diff --git a/packages/color-chrome/README.md b/packages/color-chrome/README.md index 18f19863e..e9642b384 100644 --- a/packages/color-chrome/README.md +++ b/packages/color-chrome/README.md @@ -23,26 +23,49 @@ npm i @uiw/react-color-chrome ```jsx mdx:preview import React, { useState } from 'react'; + +import { + HsvaColor, + hsvaToRgbaString, + color as handleColor, + validHex, + hexToHsva, + hsvaToHex, + hsvaToHexa, +} from '@uiw/color-convert'; + import Chrome from '@uiw/react-color-chrome'; import { GithubPlacement } from '@uiw/react-color-github'; function Demo() { - const [hex, setHex] = useState("#d29c9c53"); + const [hsva, setHsva] = useState({ h:0, s:25.71, v:82.35, a:0.32}); + const hex = hsvaToHex(hsva) return ( <> { - setHex(color.hexa); + setHsva(color.hsva); + }} + /> + { + setHsva(color.hsva); }} /> { - setHex(color.hexa); + setHsva(color.hsva); }} />
@@ -60,12 +83,17 @@ export default Demo; import React from 'react'; import { GithubProps } from '@uiw/react-color-github'; export declare enum ChromeInputType { - HEXA = "hexa", - RGBA = "rgba", - HSLA = "hsla" + HEXA = "hexa", + RGBA = "rgba", + HSLA = "hsla" } export interface ChromeProps extends Omit { - inputType?: ChromeInputType; + inputType?: ChromeInputType; + showEditableInput?: boolean; + showEyeDropper?: boolean; + showColorPreview?: boolean; + showHue?: boolean; + showAlpha?: boolean; } declare const Chrome: React.ForwardRefExoticComponent>; export default Chrome; diff --git a/packages/color-chrome/src/index.tsx b/packages/color-chrome/src/index.tsx index 7642d2c2c..24444189c 100644 --- a/packages/color-chrome/src/index.tsx +++ b/packages/color-chrome/src/index.tsx @@ -27,6 +27,11 @@ export enum ChromeInputType { export interface ChromeProps extends Omit { inputType?: ChromeInputType; + showEditableInput?: boolean; + showEyeDropper?: boolean; + showColorPreview?: boolean; + showHue?: boolean; + showAlpha?: boolean; } const Chrome = React.forwardRef((props, ref) => { @@ -35,6 +40,11 @@ const Chrome = React.forwardRef((props, ref) => { className, style, color, + showEditableInput = true, + showEyeDropper = true, + showColorPreview = true, + showHue = true, + showAlpha = true, inputType = ChromeInputType.RGBA, rectProps = {}, onChange, @@ -78,6 +88,10 @@ const Chrome = React.forwardRef((props, ref) => { handleChange({ ...result }); }; const styleSize = { height: 14, width: 14 }; + const pointerProps = { + style: { ...styleSize }, + fillProps: { style: styleSize }, + }; return ( ((props, ref) => { }} />
- {isSupportEyeDropper && } - } - /> -
- { - handleChange({ ...hsva, ...newHue }); - }} - /> + {isSupportEyeDropper && showEyeDropper && } + {showColorPreview && ( { - handleChange({ ...hsva, ...newAlpha }); + bgProps={{ style: { background: 'transparent' } }} + innerProps={{ + style: alphaStyle, }} + pointer={() => } /> -
-
-
+ )}
- {type == ChromeInputType.RGBA && ( - handleChange(reColor.hsva)} - /> - )} - {type === ChromeInputType.HEXA && ( - 0 && hsva.a < 1 ? hsvaToHexa(hsva).toLocaleUpperCase() : hsvaToHex(hsva).toLocaleUpperCase()} - onChange={(_, value) => { - if (typeof value === 'string') { - handleChange(hexToHsva(/^#/.test(value) ? value : `#${value}`)); - } + {showHue == true && ( + { + handleChange({ ...hsva, ...newHue }); }} /> )} - {type === ChromeInputType.HSLA && ( - handleChange(reColor.hsva)} + style={{ marginTop: 6, height: 12 }} + pointerProps={pointerProps} + bgProps={{ + style: { borderRadius: 2 }, + }} + onChange={(newAlpha) => { + handleChange({ ...hsva, ...newAlpha }); + }} /> )}
-
+ {showEditableInput && ( +
+
+ {type == ChromeInputType.RGBA && ( + handleChange(reColor.hsva)} + /> + )} + {type === ChromeInputType.HEXA && ( + 0 && hsva.a < 1 ? hsvaToHexa(hsva).toLocaleUpperCase() : hsvaToHex(hsva).toLocaleUpperCase()} + onChange={(_, value) => { + if (typeof value === 'string') { + handleChange(hexToHsva(/^#/.test(value) ? value : `#${value}`)); + } + }} + /> + )} + {type === ChromeInputType.HSLA && ( + handleChange(reColor.hsva)} + /> + )} +
+ +
+ )} } rectRender={() => }