Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(color-picker): add new defaultColor prop #319

Merged
merged 1 commit into from
Aug 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion packages/ui/color-picker/src/color-picker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const ColorPicker: React.FC<ColorPickerProps> = ({
id,
type = "hex",
color = "",
defaultColor,
onApply,
placeholder = "Select color",
isError = false,
Expand All @@ -49,10 +50,16 @@ const ColorPicker: React.FC<ColorPickerProps> = ({
// 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) => {
Expand Down
4 changes: 4 additions & 0 deletions packages/ui/color-picker/src/color-picker.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ interface ColorPickerProps
* Unique identifier for the color-picker
*/
id?: string
/**
* Default color (initial color)
*/
defaultColor?: string
/**
* Color code
*/
Expand Down
8 changes: 7 additions & 1 deletion packages/ui/color-picker/stories/tabs/TabCode.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,16 @@ import { buttonCode } from "@wpmudev/sui-tooltip/stories/tabs/Examples/Types.mdx
</p>
</PropSection>

<PropSection title="color" type="string">
<PropSection title="defaultColor" type="string">
<p>
The initial color value
</p>
</PropSection>

<PropSection title="color" type="string">
<p>
Current color value
</p>
</PropSection>

<PropSection title="onColorChange" type="function">
Expand Down
Loading