diff --git a/packages/color-chrome/README.md b/packages/color-chrome/README.md index e9642b384..d2de4e9c7 100644 --- a/packages/color-chrome/README.md +++ b/packages/color-chrome/README.md @@ -77,6 +77,48 @@ function Demo() { export default Demo; ``` +Disable the opacity setting by setting `showAlpha` to `false`. + +```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 [hsva, setHsva] = useState({ h:0, s:25.71, v:82.35, a:0.32}); + const hex = hsvaToHex(hsva) + return ( + <> + { + setHsva(color.hsva); + }} + /> +
+ {hex} +
+ + ); +} +export default Demo; +``` + + ## Props ```ts diff --git a/packages/color-chrome/src/index.tsx b/packages/color-chrome/src/index.tsx index 24444189c..c4c086038 100644 --- a/packages/color-chrome/src/index.tsx +++ b/packages/color-chrome/src/index.tsx @@ -1,6 +1,6 @@ -import React, { CSSProperties, Fragment } from 'react'; +import React, { type CSSProperties, Fragment } from 'react'; import { - HsvaColor, + type HsvaColor, hsvaToRgbaString, color as handleColor, validHex, @@ -8,7 +8,7 @@ import { hsvaToHex, hsvaToHexa, } from '@uiw/color-convert'; -import Github, { GithubProps, GithubPlacement } from '@uiw/react-color-github'; +import Github, { type GithubProps, GithubPlacement } from '@uiw/react-color-github'; import Saturation from '@uiw/react-color-saturation'; import Hue from '@uiw/react-color-hue'; import Alpha from '@uiw/react-color-alpha'; @@ -132,7 +132,7 @@ const Chrome = React.forwardRef((props, ref) => { {showHue == true && ( ((props, ref) => { {showAlpha == true && ( ((props, ref) => { rProps={{ labelStyle, inputStyle }} gProps={{ labelStyle, inputStyle }} bProps={{ labelStyle, inputStyle }} - aProps={{ labelStyle, inputStyle }} + aProps={showAlpha == false ? false : { labelStyle, inputStyle }} onChange={(reColor) => handleChange(reColor.hsva)} /> )} @@ -189,7 +189,7 @@ const Chrome = React.forwardRef((props, ref) => { hProps={{ labelStyle, inputStyle }} sProps={{ labelStyle, inputStyle }} lProps={{ labelStyle, inputStyle }} - aProps={{ labelStyle, inputStyle }} + aProps={showAlpha == false ? false : { labelStyle, inputStyle }} onChange={(reColor) => handleChange(reColor.hsva)} /> )} diff --git a/packages/color-editable-input-hsla/README.md b/packages/color-editable-input-hsla/README.md index 994bd345d..e64e329da 100644 --- a/packages/color-editable-input-hsla/README.md +++ b/packages/color-editable-input-hsla/README.md @@ -47,7 +47,7 @@ export interface EditableInputHSLAProps extends Omit>; export default EditableInputHSLA; diff --git a/packages/color-editable-input-hsla/src/index.tsx b/packages/color-editable-input-hsla/src/index.tsx index eb88ea419..f5727e661 100644 --- a/packages/color-editable-input-hsla/src/index.tsx +++ b/packages/color-editable-input-hsla/src/index.tsx @@ -1,12 +1,13 @@ import React from 'react'; -import EditableInputRGBA, { EditableInputRGBAProps } from '@uiw/react-color-editable-input-rgba'; -import { HslaColor, color as handleColor, hsvaToHsla, hslaToHsva } from '@uiw/color-convert'; +import { type EditableInputProps } from '@uiw/react-color-editable-input'; +import EditableInputRGBA, { type EditableInputRGBAProps } from '@uiw/react-color-editable-input-rgba'; +import { type HslaColor, color as handleColor, hsvaToHsla, hslaToHsva } from '@uiw/color-convert'; export interface EditableInputHSLAProps extends Omit { hProps?: EditableInputRGBAProps['gProps']; sProps?: EditableInputRGBAProps['gProps']; lProps?: EditableInputRGBAProps['gProps']; - aProps?: EditableInputRGBAProps['aProps']; + aProps?: false | EditableInputRGBAProps['aProps']; } const EditableInputHSLA = React.forwardRef((props, ref) => { @@ -46,6 +47,15 @@ const EditableInputHSLA = React.forwardRef handleChange(val, 'a', evn), + }; return ( handleChange(val, 'l', evn), }} - aProps={{ - label: 'A', - value: Math.round(hsla.a * 100) / 100, - ...aProps, - onChange: (evn, val) => handleChange(val, 'a', evn), - }} + aProps={aPropsObj} className={[prefixCls, className || ''].filter(Boolean).join(' ')} {...other} />