Skip to content

Commit

Permalink
Add changelog, update readme, simplify safeColordColor return value
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewserong committed Nov 30, 2021
1 parent 9e0d22d commit c4c051a
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 13 deletions.
2 changes: 2 additions & 0 deletions packages/components/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

### Bug Fix

- Fixed error thrown in `ColorPicker` when used in controlled state in color gradients ([#36941](https://github.com/WordPress/gutenberg/pull/36941)).
- Updated readme to include default value introduced in fix for unexpected movements in the `ColorPicker` ([#35670](https://github.com/WordPress/gutenberg/pull/35670)).
- Replaced hardcoded blue in `ColorPicker` with UI theme color ([#36153](https://github.com/WordPress/gutenberg/pull/36153)).

### Experimental
Expand Down
24 changes: 13 additions & 11 deletions packages/components/src/color-picker/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,32 +22,34 @@ function Example() {

## Props

### `color`

**Type**: `string`
### `color`: `string`

The current color value to display in the picker. Must be a hex or hex8 string.

### `onChange`
- Required: No

**Type**: `(hex8Color: string) => void`
### `onChange`: `(hex8Color: string) => void`

Fired when the color changes. Always passes a hex8 color string.

### `enableAlpha`
- Required: No

**Type**: `boolean`
### `enableAlpha`: `boolean`

Defaults to `false`. When `true` the color picker will display the alpha channel both in the bottom inputs as well as in the color picker itself.

### `defaultValue`
- Required: No
- Default: `false`

**Type**: `string | undefined`
### `defaultValue`: `string | undefined`

An optional default value to use for the color picker.

### `copyFormat`
- Required: No
- Default: `'#fff'`

**Type**: `'hex' | 'hsl' | 'rgb' | undefined`
### `copyFormat`: `'hex' | 'hsl' | 'rgb' | undefined`

The format to copy when clicking the displayed color format.

- Required: No
4 changes: 2 additions & 2 deletions packages/components/src/color-picker/component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,15 @@ const ColorPicker = (
...divProps
} = useContextSystem( props, 'ColorPicker' );

// Use a safe default value for the color and remove the possibility of `undefined`.
const [ color, setColor ] = useControlledValue( {
onChange,
value: colorProp,
defaultValue,
} );

// Use a safe default value for the color and remove the possibility of `undefined`.
const safeColordColor = useMemo( () => {
return color ? colord( color ) : colord( defaultValue );
return colord( color );
}, [ color, defaultValue ] );

const debouncedSetColor = useDebounce( setColor );
Expand Down

0 comments on commit c4c051a

Please sign in to comment.