$ npm install react-colorful
npm install react-colorful --save
import ColorPicker from "react-colorful";
import "react-colorful/dist/index.css";
const YourComponent = () => {
const [color, setColor] = useState("#aabbcc");
return <ColorPicker hex={color} onChange={setColor} />;
};
The easiest way to tweak react-colorful is to create another stylesheet to override the default styles.
.react-colorful {
height: 250px;
}
.react-colorful__saturation {
bottom: 30px;
border-radius: 3px 3px 0 0;
}
.react-colorful__hue {
height: 30px;
border-radius: 0 0 3px 3px;
}
.react-colorful__saturation-pointer {
border-radius: 5px;
}
.react-colorful__hue-pointer {
border-radius: 2px;
width: 15px;
height: inherit;
}
Today each dependency drags more dependencies and increases your project’s bundle size uncontrollably. But size is very important for everything that intends to work in a browser.
react-colorful is a simple color picker for those who care about their bundle size and client-side performance. It's fast and lightweight because:
To show you the problem that react-colorful is trying to solve, we have performed a simple benchmark (using size-limit) against popular React color picker libraries:
Name | Size (minified) | Size (gzipped) | Dependencies |
---|---|---|---|
react-colorful v1.2.1 | 4 KB | 1,5 KB | 0 |
react-color v2.18.1 | 165 KB | 40,6 KB | 6 |
react-input-color v3.0.1 | 59 KB | 19,1 KB | 7 |
rc-color-picker v1.2.6 | 117 KB | 32,4 KB | 5 |
© 2010 - cnpmjs.org x YWFE | Home | YWFE