diff --git a/packages/ui/color-picker/src/color-picker.tsx b/packages/ui/color-picker/src/color-picker.tsx index aabd738d3..518fbccf8 100644 --- a/packages/ui/color-picker/src/color-picker.tsx +++ b/packages/ui/color-picker/src/color-picker.tsx @@ -24,6 +24,7 @@ const ColorPicker: React.FC = ({ id, type = "hex", color = "", + defaultColor, onApply, placeholder = "Select color", isError = false, @@ -49,10 +50,16 @@ const ColorPicker: React.FC = ({ // Update tempColor when color prop value changes useEffect(() => { setTempColor(color) - // eslint-disable-next-line react-hooks/exhaustive-deps }, [color]) + useEffect(() => { + // Hide reset button if default and current color matched + if (defaultColor && color === defaultColor) { + setShowResetBtn(false) + } + }, [defaultColor, color]) + // Handle reset const handleReset = useCallback( (e) => { diff --git a/packages/ui/color-picker/src/color-picker.types.ts b/packages/ui/color-picker/src/color-picker.types.ts index 54866de06..739678ea5 100644 --- a/packages/ui/color-picker/src/color-picker.types.ts +++ b/packages/ui/color-picker/src/color-picker.types.ts @@ -11,6 +11,10 @@ interface ColorPickerProps * Unique identifier for the color-picker */ id?: string + /** + * Default color (initial color) + */ + defaultColor?: string /** * Color code */ diff --git a/packages/ui/color-picker/stories/tabs/TabCode.mdx b/packages/ui/color-picker/stories/tabs/TabCode.mdx index 97b60c976..309a37851 100644 --- a/packages/ui/color-picker/stories/tabs/TabCode.mdx +++ b/packages/ui/color-picker/stories/tabs/TabCode.mdx @@ -13,10 +13,16 @@ import { buttonCode } from "@wpmudev/sui-tooltip/stories/tabs/Examples/Types.mdx

- +

The initial color value

+
+ + +

+ Current color value +