1. 首页
  2. 推送

React颜色选择组件——React Color

React Color

A Collection of Color Pickers from Sketch, Photoshop, Chrome & more

react color

安装 & 使用

npm install react-color --save

引入Component

var React = require('react');
var ColorPicker = require('react-color');

class Component extends React.Component {

  render() {
    return <ColorPicker type="sketch" />;
  }
}

显示它

Display the color picker popup on click, or don’t define display and it will always be visible.

var React = require('react');
var ColorPicker = require('react-color');

class Component extends React.Component {

  constructor() {
    super();
    this.state = {
      displayColorPicker: false,
    };
    this.handleClick = this.handleClick.bind(this);
  }

  handleClick() {
    this.setState({ displayColorPicker: !this.state.displayColorPicker });
  }

  render() {
    return (
      <div>
        <button onClick={ this.handleClick }>Pick Color</button>
        <ColorPicker display={ this.state.displayColorPicker } type="sketch" />
      </div>
    );
  }
}

github:https://github.com/casesandberg/react-color

收藏

暂无评论

登录后可以进行评论。没有账号?马上注册