npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

daifee-react-component

v2.0.3

Published

封装常用的 react 组件,参考(copy) weui 的 UI 风格

Downloads

5

Readme

Daifee-React-Component

用 React 封装一套常用组件

所有组件都是 stateless 组件,但为方便,某些组件提供 API 调用方式的静态方法。


[TOC]

使用前须知

源码已构建成 UMD 模块发布到 NPM.

npm install -s daifee-react-component

依赖:

用法

建议用 webpack 构建

文档:http://daifee.github.io/react-component/doc/

Demos

将所有依赖(包括 Daifee-React-Component)与项目源码打包为一个文件。

访问地址

  • 源码:/example
  • 配置:/website/webpack.config.demos.js

Demos-externals

将所有依赖(包括 Daifee-React-Component)用 <script /> 加载。

访问地址

  • 源码:/example
  • 配置:/website/webpack.config.demos-externals.js

项目目录结构


/react-component
  |-- dist  构建后的代码
  |-- doc  文档
  |-- example  开发过程中的例子(也是在线 Demos 的源码)
  |-- src  项目源码
  |-- test  测试(还没写)
  |-- website  网站(Demos 构建配置)
  |-- ...配置

开发

命令脚本:

  • npm install 安装依赖
  • npm start 启动本地开发服务器 localhost:8082
  • npm test 测试
  • npm run lint 检测代码
  • npm run lint:watch 监听文件变化,持续检测代码
  • npm run build 构建编译源码
  • npm run build:website 构建 website 项目

风格

  • 文件名(包含目录)和标识符(变量、函数名、属性)都用使用“驼峰式”。
  • 以模块为单位创建文件,如果模块为“类”则第一个字母大写。
  • 每个组件定义一个目录,以组件名命名。
  • 尽量使用 stateless component
  • 某些组件为了方便使用,提供静态方法作为直接调用的接口。
  • 定义组件时用到的 props 必须在 propTypes 声明,可以向组件传递任意 props(React 支持就行)。

踩到的坑

addComponentAsRefTo Invariant Violation

竟然是 react-with-addonsreact-dom 加载顺序的问题 http://stackoverflow.com/questions/28519287/what-does-only-a-reactowner-can-have-refs-mean

构建 UMD 模块

Daifee-React-Component 依赖 react-addons-css-transition-group 将其配置为 externals

// webpack.config.js

'react-addons-css-transition-group': {
  // UMD 依赖模块: root['React']['addons']['CSSTransitionGroup']
  // 项目依赖模块:module.exports = React.addons.CSSTransitionGroup;
  // 作为项目依赖模块时,root 的值不能是数组,只能是 {root: 'React.addons.CSSTransitionGroup'}
  root: ['React','addons','CSSTransitionGroup'],
  commonjs2: 'react-addons-css-transition-group',
  commonjs: 'react-addons-css-transition-group',
  amd: 'react-addons-css-transition-group'
}

如果项目依赖 Daifee-React-Component,并希望也将 react-addons-css-transition-group 配置为 externals,其配置却与上面不一样。

// webpack.config.demos-externals.js
externals: {
  'react': 'React',
  'react-dom': 'ReactDOM',
  // 看我傻逼不?
  'react-addons-css-transition-group': 'React.addons.CSSTransitionGroup',
  'daifee-react-component': 'DaifeeReactComponent',
  'xiscroll': 'IScroll'
}