Color picker component provides a simple and beautiful panel, easy to select commonly used colors, with recommended colors, recently used colors, color picker, custom colors and other functions.
Introduce a,
- Recommended color: Red, Orange, yellow, green, blue, purple by default. You can customize the color
- Recently usedUse:
localstorage
Record the most recently used colors - Color picker: The color straw tool draws color values from other elements on the page
- More colors: You can edit the transparency of the color, select the color from the color palette, enter the color value, and so on (use the react-color implementation)
legend
- Color picker main panel
- Color picker (color straw tool)
Second, the use of
The installation
npm install -s color-picker-react-component
Copy the code
use
import React, { useState } from 'react';
import ColorPicker from 'color-picker-react-component';
export default() = > {const [color, setColor] = useState('#fff');
const [visible, setVisible] = useState(false);
return (
<>
<div
color={color}
style={{
width: 20.height: 20.border: '1px solid #ccc',
backgroundColor: color,
}}
/>
<ColorPicker
color={color}
visible={visible}
onChange={(color: string) = > setColor(color)}
onVisibleChange={(v: boolean) => setVisible(v)}
/>
</>
);
};
Copy the code
3. Parameter Description
Parameter names | meaning | The default value | note |
---|---|---|---|
color | Color value | ‘# 000’ | – |
visible | Whether or not visible | true | – |
recommendedColors | Custom recommended colors | – | – |
localStorageKey | The custom key | ‘color_picker_recent_color’ | Localstorage-unique key value used for the most recent color |
showPipetteColor | Whether to display color picker | true | – |
showMoreColor | Whether to show more colors | true | – |
className | The name of the class | ‘ ‘ | – |
style | Style object | {} | – |
onChange | Listen for color changes | – | ({ color: string; }) => void |
onVisibleChange | Monitor display changes | – | (visible: boolean) => void |
More and more
NPM package
Version 1.0 has been released to NPM. Welcome to use it
- Link: www.npmjs.com/package/col…