@wordpress/components 32.2.2-next.v.202602200903.0 → 32.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +19 -1
- package/build/alignment-matrix-control/cell.cjs +2 -2
- package/build/alignment-matrix-control/cell.cjs.map +2 -2
- package/build/alignment-matrix-control/index.cjs +2 -2
- package/build/alignment-matrix-control/index.cjs.map +2 -2
- package/build/angle-picker-control/angle-circle.cjs +2 -2
- package/build/angle-picker-control/angle-circle.cjs.map +2 -2
- package/build/color-picker/color-input.cjs +11 -8
- package/build/color-picker/color-input.cjs.map +2 -2
- package/build/color-picker/component.cjs +47 -3
- package/build/color-picker/component.cjs.map +2 -2
- package/build/color-picker/hsl-input.cjs +7 -28
- package/build/color-picker/hsl-input.cjs.map +2 -2
- package/build/color-picker/picker.cjs +29 -20
- package/build/color-picker/picker.cjs.map +2 -2
- package/build/date-time/date/styles.cjs +9 -9
- package/build/date-time/date/styles.cjs.map +2 -2
- package/build/number-control/index.cjs +2 -5
- package/build/number-control/index.cjs.map +2 -2
- package/build/select-control/styles/select-control-styles.cjs +8 -8
- package/build/select-control/styles/select-control-styles.cjs.map +2 -2
- package/build/toggle-group-control/toggle-group-control-option-base/styles.cjs +8 -8
- package/build/toggle-group-control/toggle-group-control-option-base/styles.cjs.map +2 -2
- package/build-module/alignment-matrix-control/cell.mjs +2 -2
- package/build-module/alignment-matrix-control/cell.mjs.map +2 -2
- package/build-module/alignment-matrix-control/index.mjs +2 -2
- package/build-module/alignment-matrix-control/index.mjs.map +2 -2
- package/build-module/angle-picker-control/angle-circle.mjs +2 -2
- package/build-module/angle-picker-control/angle-circle.mjs.map +2 -2
- package/build-module/color-picker/color-input.mjs +11 -8
- package/build-module/color-picker/color-input.mjs.map +2 -2
- package/build-module/color-picker/component.mjs +48 -4
- package/build-module/color-picker/component.mjs.map +2 -2
- package/build-module/color-picker/hsl-input.mjs +7 -28
- package/build-module/color-picker/hsl-input.mjs.map +2 -2
- package/build-module/color-picker/picker.mjs +30 -21
- package/build-module/color-picker/picker.mjs.map +2 -2
- package/build-module/date-time/date/styles.mjs +9 -9
- package/build-module/date-time/date/styles.mjs.map +2 -2
- package/build-module/number-control/index.mjs +2 -5
- package/build-module/number-control/index.mjs.map +2 -2
- package/build-module/select-control/styles/select-control-styles.mjs +8 -8
- package/build-module/select-control/styles/select-control-styles.mjs.map +2 -2
- package/build-module/toggle-group-control/toggle-group-control-option-base/styles.mjs +8 -8
- package/build-module/toggle-group-control/toggle-group-control-option-base/styles.mjs.map +2 -2
- package/build-style/style-rtl.css +2 -0
- package/build-style/style.css +2 -0
- package/build-types/color-picker/color-input.d.ts +1 -1
- package/build-types/color-picker/color-input.d.ts.map +1 -1
- package/build-types/color-picker/component.d.ts.map +1 -1
- package/build-types/color-picker/hsl-input.d.ts +1 -1
- package/build-types/color-picker/hsl-input.d.ts.map +1 -1
- package/build-types/color-picker/picker.d.ts +1 -1
- package/build-types/color-picker/picker.d.ts.map +1 -1
- package/build-types/color-picker/types.d.ts +6 -4
- package/build-types/color-picker/types.d.ts.map +1 -1
- package/build-types/date-time/date/styles.d.ts.map +1 -1
- package/build-types/dropdown/types.d.ts +9 -13
- package/build-types/dropdown/types.d.ts.map +1 -1
- package/build-types/modal/types.d.ts +9 -3
- package/build-types/modal/types.d.ts.map +1 -1
- package/build-types/number-control/index.d.ts.map +1 -1
- package/build-types/popover/types.d.ts +10 -10
- package/build-types/popover/types.d.ts.map +1 -1
- package/build-types/select-control/styles/select-control-styles.d.ts.map +1 -1
- package/build-types/toggle-group-control/toggle-group-control-option-base/styles.d.ts.map +1 -1
- package/build-types/tools-panel/tools-panel/hook.d.ts +1 -1
- package/build-types/tools-panel/types.d.ts +1 -1
- package/build-types/tools-panel/types.d.ts.map +1 -1
- package/package.json +21 -21
- package/src/button/style.scss +1 -0
- package/src/color-picker/color-input.tsx +23 -4
- package/src/color-picker/component.tsx +88 -4
- package/src/color-picker/hsl-input.tsx +9 -51
- package/src/color-picker/picker.tsx +28 -24
- package/src/color-picker/test/index.tsx +139 -6
- package/src/color-picker/types.ts +6 -4
- package/src/date-time/date/styles.ts +1 -0
- package/src/dropdown/types.ts +9 -14
- package/src/form-token-field/style.scss +1 -0
- package/src/modal/types.ts +9 -5
- package/src/number-control/index.tsx +73 -77
- package/src/popover/types.ts +10 -10
- package/src/select-control/styles/select-control-styles.ts +1 -0
- package/src/toggle-group-control/test/__snapshots__/index.tsx.snap +18 -16
- package/src/toggle-group-control/toggle-group-control-option-base/styles.ts +4 -6
- package/src/tools-panel/types.ts +4 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"select-control-styles.d.ts","sourceRoot":"","sources":["../../../src/select-control/styles/select-control-styles.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AAKnD,UAAU,WACT,SAAQ,IAAI,CACX,kBAAkB,EAClB,uBAAuB,GAAG,UAAU,GAAG,UAAU,GAAG,SAAS,CAC7D;IAGD,UAAU,CAAC,EAAE,kBAAkB,CAAE,MAAM,CAAE,CAAC;CAC1C;AAuBD,eAAO,MAAM,eAAe;;;;wBAM3B,CAAC;AAiDF,eAAO,MAAM,eAAe,KAAK,CAAC;AAmDlC,eAAO,MAAM,MAAM;;;
|
|
1
|
+
{"version":3,"file":"select-control-styles.d.ts","sourceRoot":"","sources":["../../../src/select-control/styles/select-control-styles.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AAKnD,UAAU,WACT,SAAQ,IAAI,CACX,kBAAkB,EAClB,uBAAuB,GAAG,UAAU,GAAG,UAAU,GAAG,SAAS,CAC7D;IAGD,UAAU,CAAC,EAAE,kBAAkB,CAAE,MAAM,CAAE,CAAC;CAC1C;AAuBD,eAAO,MAAM,eAAe;;;;wBAM3B,CAAC;AAiDF,eAAO,MAAM,eAAe,KAAK,CAAC;AAmDlC,eAAO,MAAM,MAAM;;;mIAwBlB,CAAC;AAEF,eAAO,MAAM,gBAAgB;;;yGAO5B,CAAC;AAEF,eAAO,MAAM,yCAAyC;;;;UAOrD,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"styles.d.ts","sourceRoot":"","sources":["../../../src/toggle-group-control/toggle-group-control-option-base/styles.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EACX,uBAAuB,EACvB,iCAAiC,EACjC,MAAM,UAAU,CAAC;AAElB,eAAO,MAAM,SAAS;;;yGAKrB,CAAC;AAEF,eAAO,MAAM,UAAU,2CAEtB,CAAC;AAEF,eAAO,MAAM,UAAU,GAAK,8CAKzB,IAAI,CAAE,uBAAuB,EAAE,gBAAgB,GAAG,MAAM,CAAE,GAC5D,IAAI,CAAE,iCAAiC,EAAE,QAAQ,CAAE,GAAG;IACrD,SAAS,CAAC,EAAE,OAAO,CAAC;CACpB,
|
|
1
|
+
{"version":3,"file":"styles.d.ts","sourceRoot":"","sources":["../../../src/toggle-group-control/toggle-group-control-option-base/styles.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EACX,uBAAuB,EACvB,iCAAiC,EACjC,MAAM,UAAU,CAAC;AAElB,eAAO,MAAM,SAAS;;;yGAKrB,CAAC;AAEF,eAAO,MAAM,UAAU,2CAEtB,CAAC;AAEF,eAAO,MAAM,UAAU,GAAK,8CAKzB,IAAI,CAAE,uBAAuB,EAAE,gBAAgB,GAAG,MAAM,CAAE,GAC5D,IAAI,CAAE,iCAAiC,EAAE,QAAQ,CAAE,GAAG;IACrD,SAAS,CAAC,EAAE,OAAO,CAAC;CACpB,8CA4CD,CAAC;AAoBF,eAAO,MAAM,iBAAiB;;;yGAI7B,CAAC"}
|
|
@@ -23,7 +23,7 @@ export declare function useToolsPanel(props: WordPressComponentProps<ToolsPanelP
|
|
|
23
23
|
toggleItem: (label: string) => void;
|
|
24
24
|
className: string;
|
|
25
25
|
children: import("react").ReactNode;
|
|
26
|
-
dropdownMenuProps?: React.ComponentProps<typeof import("../..").DropdownMenu>;
|
|
26
|
+
dropdownMenuProps?: Omit<React.ComponentProps<typeof import("../..").DropdownMenu>, "label">;
|
|
27
27
|
label: string;
|
|
28
28
|
defaultValue?: string | number | readonly string[] | undefined;
|
|
29
29
|
onChange?: import("react").FormEventHandler<HTMLDivElement> | undefined;
|
|
@@ -17,7 +17,7 @@ export type ToolsPanelProps = {
|
|
|
17
17
|
/**
|
|
18
18
|
* The dropdown menu props to configure the panel's `DropdownMenu`.
|
|
19
19
|
*/
|
|
20
|
-
dropdownMenuProps?: React.ComponentProps<typeof DropdownMenu>;
|
|
20
|
+
dropdownMenuProps?: Omit<React.ComponentProps<typeof DropdownMenu>, 'label'>;
|
|
21
21
|
/**
|
|
22
22
|
* Flags that the items in this ToolsPanel will be contained within an inner
|
|
23
23
|
* wrapper element allowing the panel to lay them out accordingly.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/tools-panel/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAEvC;;GAEG;AACH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAErD,MAAM,MAAM,cAAc,GAAG,CAAE,UAAU,CAAC,EAAE,GAAG,KAAM,GAAG,CAAC;AACzD,KAAK,QAAQ,GAAG,CAAE,OAAO,CAAC,EAAE,cAAc,EAAE,KAAM,IAAI,CAAC;AAEvD,MAAM,MAAM,eAAe,GAAG;IAC7B;;OAEG;IACH,QAAQ,EAAE,SAAS,CAAC;IACpB;;OAEG;IACH,iBAAiB,CAAC,EAAE,KAAK,CAAC,cAAc,CAAE,OAAO,YAAY,CAAE,CAAC;
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/tools-panel/types.ts"],"names":[],"mappings":"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"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wordpress/components",
|
|
3
|
-
"version": "32.
|
|
3
|
+
"version": "32.3.0",
|
|
4
4
|
"description": "UI components for WordPress.",
|
|
5
5
|
"author": "The WordPress Contributors",
|
|
6
6
|
"license": "GPL-2.0-or-later",
|
|
@@ -64,24 +64,24 @@
|
|
|
64
64
|
"@types/highlight-words-core": "1.2.1",
|
|
65
65
|
"@types/react": "^18.3.27",
|
|
66
66
|
"@use-gesture/react": "^10.3.1",
|
|
67
|
-
"@wordpress/a11y": "^4.
|
|
68
|
-
"@wordpress/base-styles": "^6.
|
|
69
|
-
"@wordpress/compose": "^7.
|
|
70
|
-
"@wordpress/date": "^5.
|
|
71
|
-
"@wordpress/deprecated": "^4.
|
|
72
|
-
"@wordpress/dom": "^4.
|
|
73
|
-
"@wordpress/element": "^6.
|
|
74
|
-
"@wordpress/escape-html": "^3.
|
|
75
|
-
"@wordpress/hooks": "^4.
|
|
76
|
-
"@wordpress/html-entities": "^4.
|
|
77
|
-
"@wordpress/i18n": "^6.
|
|
78
|
-
"@wordpress/icons": "^11.
|
|
79
|
-
"@wordpress/is-shallow-equal": "^5.
|
|
80
|
-
"@wordpress/keycodes": "^4.
|
|
81
|
-
"@wordpress/primitives": "^4.
|
|
82
|
-
"@wordpress/private-apis": "^1.
|
|
83
|
-
"@wordpress/rich-text": "^7.
|
|
84
|
-
"@wordpress/warning": "^3.
|
|
67
|
+
"@wordpress/a11y": "^4.41.0",
|
|
68
|
+
"@wordpress/base-styles": "^6.17.0",
|
|
69
|
+
"@wordpress/compose": "^7.41.0",
|
|
70
|
+
"@wordpress/date": "^5.41.0",
|
|
71
|
+
"@wordpress/deprecated": "^4.41.0",
|
|
72
|
+
"@wordpress/dom": "^4.41.0",
|
|
73
|
+
"@wordpress/element": "^6.41.0",
|
|
74
|
+
"@wordpress/escape-html": "^3.41.0",
|
|
75
|
+
"@wordpress/hooks": "^4.41.0",
|
|
76
|
+
"@wordpress/html-entities": "^4.41.0",
|
|
77
|
+
"@wordpress/i18n": "^6.14.0",
|
|
78
|
+
"@wordpress/icons": "^11.8.0",
|
|
79
|
+
"@wordpress/is-shallow-equal": "^5.41.0",
|
|
80
|
+
"@wordpress/keycodes": "^4.41.0",
|
|
81
|
+
"@wordpress/primitives": "^4.41.0",
|
|
82
|
+
"@wordpress/private-apis": "^1.41.0",
|
|
83
|
+
"@wordpress/rich-text": "^7.41.0",
|
|
84
|
+
"@wordpress/warning": "^3.41.0",
|
|
85
85
|
"change-case": "^4.1.2",
|
|
86
86
|
"clsx": "^2.1.1",
|
|
87
87
|
"colord": "^2.7.0",
|
|
@@ -107,7 +107,7 @@
|
|
|
107
107
|
"@storybook/react-vite": "^10.1.11",
|
|
108
108
|
"@testing-library/jest-dom": "^6.9.1",
|
|
109
109
|
"@types/jest": "^29.5.14",
|
|
110
|
-
"@wordpress/jest-console": "^8.
|
|
110
|
+
"@wordpress/jest-console": "^8.41.0",
|
|
111
111
|
"snapshot-diff": "^0.10.0",
|
|
112
112
|
"storybook": "^10.1.11",
|
|
113
113
|
"timezone-mock": "^1.3.6"
|
|
@@ -119,5 +119,5 @@
|
|
|
119
119
|
"publishConfig": {
|
|
120
120
|
"access": "public"
|
|
121
121
|
},
|
|
122
|
-
"gitHead": "
|
|
122
|
+
"gitHead": "8bfc179b9aed74c0a6dd6e8edf7a49e40e4f87cc"
|
|
123
123
|
}
|
package/src/button/style.scss
CHANGED
|
@@ -9,17 +9,36 @@ import type { ColorInputProps } from './types';
|
|
|
9
9
|
export const ColorInput = ( {
|
|
10
10
|
colorType,
|
|
11
11
|
color,
|
|
12
|
+
hsla,
|
|
12
13
|
onChange,
|
|
14
|
+
onHSLChange,
|
|
13
15
|
enableAlpha,
|
|
14
16
|
}: ColorInputProps ) => {
|
|
15
|
-
const props = { color, onChange, enableAlpha };
|
|
16
17
|
switch ( colorType ) {
|
|
17
18
|
case 'hsl':
|
|
18
|
-
return
|
|
19
|
+
return (
|
|
20
|
+
<HslInput
|
|
21
|
+
hsla={ hsla }
|
|
22
|
+
onChange={ onHSLChange }
|
|
23
|
+
enableAlpha={ enableAlpha }
|
|
24
|
+
/>
|
|
25
|
+
);
|
|
19
26
|
case 'rgb':
|
|
20
|
-
return
|
|
27
|
+
return (
|
|
28
|
+
<RgbInput
|
|
29
|
+
color={ color }
|
|
30
|
+
onChange={ onChange }
|
|
31
|
+
enableAlpha={ enableAlpha }
|
|
32
|
+
/>
|
|
33
|
+
);
|
|
21
34
|
default:
|
|
22
35
|
case 'hex':
|
|
23
|
-
return
|
|
36
|
+
return (
|
|
37
|
+
<HexInput
|
|
38
|
+
color={ color }
|
|
39
|
+
onChange={ onChange }
|
|
40
|
+
enableAlpha={ enableAlpha }
|
|
41
|
+
/>
|
|
42
|
+
);
|
|
24
43
|
}
|
|
25
44
|
};
|
|
@@ -4,12 +4,19 @@
|
|
|
4
4
|
import type { ClipboardEvent, ForwardedRef } from 'react';
|
|
5
5
|
import type { Colord } from 'colord';
|
|
6
6
|
import { colord, extend, getFormat } from 'colord';
|
|
7
|
+
import type { HslaColor } from 'react-colorful';
|
|
7
8
|
import namesPlugin from 'colord/plugins/names';
|
|
8
9
|
|
|
9
10
|
/**
|
|
10
11
|
* WordPress dependencies
|
|
11
12
|
*/
|
|
12
|
-
import {
|
|
13
|
+
import {
|
|
14
|
+
useCallback,
|
|
15
|
+
useEffect,
|
|
16
|
+
useRef,
|
|
17
|
+
useState,
|
|
18
|
+
useMemo,
|
|
19
|
+
} from '@wordpress/element';
|
|
13
20
|
import { useDebounce } from '@wordpress/compose';
|
|
14
21
|
import { __ } from '@wordpress/i18n';
|
|
15
22
|
|
|
@@ -33,6 +40,21 @@ import type { ColorPickerProps, ColorType } from './types';
|
|
|
33
40
|
|
|
34
41
|
extend( [ namesPlugin ] );
|
|
35
42
|
|
|
43
|
+
/**
|
|
44
|
+
* Merges incoming HSLA with previous state, preserving hue for achromatic
|
|
45
|
+
* colors and saturation only at lightness extremes (black/white) where
|
|
46
|
+
* it has no visual effect.
|
|
47
|
+
*/
|
|
48
|
+
function mergeHSLA( nextHSLA: HslaColor, prevHSLA: HslaColor ): HslaColor {
|
|
49
|
+
if ( nextHSLA.s === 0 ) {
|
|
50
|
+
if ( nextHSLA.l === 0 || nextHSLA.l === 100 ) {
|
|
51
|
+
return { ...nextHSLA, h: prevHSLA.h, s: prevHSLA.s };
|
|
52
|
+
}
|
|
53
|
+
return { ...nextHSLA, h: prevHSLA.h };
|
|
54
|
+
}
|
|
55
|
+
return nextHSLA;
|
|
56
|
+
}
|
|
57
|
+
|
|
36
58
|
const options = [
|
|
37
59
|
{ label: 'RGB', value: 'rgb' as const },
|
|
38
60
|
{ label: 'HSL', value: 'hsl' as const },
|
|
@@ -65,9 +87,69 @@ const UnconnectedColorPicker = (
|
|
|
65
87
|
|
|
66
88
|
const debouncedSetColor = useDebounce( setColor );
|
|
67
89
|
|
|
90
|
+
// Internal HSLA state preserves hue and saturation values that
|
|
91
|
+
// would otherwise be lost when converting to/from hex at achromatic
|
|
92
|
+
// colors (e.g. pure black or white where any H/S maps to the same hex).
|
|
93
|
+
const [ internalHSLA, setInternalHSLA ] = useState< HslaColor >( () => ( {
|
|
94
|
+
...safeColordColor.toHsl(),
|
|
95
|
+
} ) );
|
|
96
|
+
|
|
97
|
+
// Track the last hex we produced so the sync effect can
|
|
98
|
+
// distinguish our own updates from external prop changes.
|
|
99
|
+
const lastProducedHexRef = useRef( safeColordColor.toHex() );
|
|
100
|
+
|
|
101
|
+
// Sync internalHSLA when the color prop changes externally (e.g.
|
|
102
|
+
// parent passes a new color that wasn't produced by our onChange).
|
|
103
|
+
useEffect( () => {
|
|
104
|
+
const incomingHex = safeColordColor.toHex();
|
|
105
|
+
|
|
106
|
+
// If this hex matches what we last produced, it's our own
|
|
107
|
+
// update arriving back — skip the sync to avoid overwriting
|
|
108
|
+
// internalHSLA with lossy round-tripped values.
|
|
109
|
+
if ( incomingHex === lastProducedHexRef.current ) {
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
// Genuinely external change — sync internalHSLA.
|
|
114
|
+
lastProducedHexRef.current = incomingHex;
|
|
115
|
+
const externalHSLA = safeColordColor.toHsl();
|
|
116
|
+
setInternalHSLA( ( prev ) => mergeHSLA( externalHSLA, prev ) );
|
|
117
|
+
}, [ safeColordColor ] );
|
|
118
|
+
|
|
119
|
+
// Handler for HSL-aware components (Picker, HSL inputs) that
|
|
120
|
+
// provide raw HSLA values without information loss.
|
|
121
|
+
// Uses direct setColor (not debounced) to prevent race conditions
|
|
122
|
+
// where a stale debounced hex would overwrite newer internalHSLA.
|
|
123
|
+
// This is safe performance-wise because react-colorful internally
|
|
124
|
+
// throttles its onChange callbacks using requestAnimationFrame.
|
|
125
|
+
|
|
126
|
+
const handleHSLAChange = useCallback(
|
|
127
|
+
( nextHSLA: HslaColor ) => {
|
|
128
|
+
// No mergeHSLA here — this handler receives the user's explicit
|
|
129
|
+
// choice from the picker or HSL inputs, with no lossy conversion.
|
|
130
|
+
setInternalHSLA( nextHSLA );
|
|
131
|
+
const previousHex = lastProducedHexRef.current;
|
|
132
|
+
const nextHex = colord( nextHSLA ).toHex();
|
|
133
|
+
// Only notify parent when the hex actually changes. This
|
|
134
|
+
// avoids firing onChange for H/S changes on achromatic
|
|
135
|
+
// colors (e.g. adjusting hue on pure white).
|
|
136
|
+
if ( nextHex !== previousHex ) {
|
|
137
|
+
lastProducedHexRef.current = nextHex;
|
|
138
|
+
setColor( nextHex );
|
|
139
|
+
}
|
|
140
|
+
},
|
|
141
|
+
[ setColor ]
|
|
142
|
+
);
|
|
143
|
+
|
|
144
|
+
// Handler for components that provide Colord values (RGB, Hex inputs).
|
|
145
|
+
// Uses debouncedSetColor since the hex input fires per keystroke.
|
|
68
146
|
const handleChange = useCallback(
|
|
69
147
|
( nextValue: Colord ) => {
|
|
70
|
-
|
|
148
|
+
const nextHSLA = nextValue.toHsl();
|
|
149
|
+
setInternalHSLA( ( prev ) => mergeHSLA( nextHSLA, prev ) );
|
|
150
|
+
const nextHex = nextValue.toHex();
|
|
151
|
+
lastProducedHexRef.current = nextHex;
|
|
152
|
+
debouncedSetColor( nextHex );
|
|
71
153
|
},
|
|
72
154
|
[ debouncedSetColor ]
|
|
73
155
|
);
|
|
@@ -128,8 +210,8 @@ const UnconnectedColorPicker = (
|
|
|
128
210
|
onPasteCapture={ maybeHandlePaste }
|
|
129
211
|
>
|
|
130
212
|
<Picker
|
|
131
|
-
onChange={
|
|
132
|
-
|
|
213
|
+
onChange={ handleHSLAChange }
|
|
214
|
+
hsla={ internalHSLA }
|
|
133
215
|
enableAlpha={ enableAlpha }
|
|
134
216
|
/>
|
|
135
217
|
<AuxiliaryColorArtefactWrapper>
|
|
@@ -154,7 +236,9 @@ const UnconnectedColorPicker = (
|
|
|
154
236
|
<ColorInput
|
|
155
237
|
colorType={ colorType }
|
|
156
238
|
color={ safeColordColor }
|
|
239
|
+
hsla={ internalHSLA }
|
|
157
240
|
onChange={ handleChange }
|
|
241
|
+
onHSLChange={ handleHSLAChange }
|
|
158
242
|
enableAlpha={ enableAlpha }
|
|
159
243
|
/>
|
|
160
244
|
</ColorInputWrapper>
|
|
@@ -1,12 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* External dependencies
|
|
3
3
|
*/
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* WordPress dependencies
|
|
8
|
-
*/
|
|
9
|
-
import { useState, useEffect, useMemo } from '@wordpress/element';
|
|
4
|
+
import type { HslaColor } from 'react-colorful';
|
|
10
5
|
|
|
11
6
|
/**
|
|
12
7
|
* Internal dependencies
|
|
@@ -14,49 +9,12 @@ import { useState, useEffect, useMemo } from '@wordpress/element';
|
|
|
14
9
|
import { InputWithSlider } from './input-with-slider';
|
|
15
10
|
import type { HslInputProps } from './types';
|
|
16
11
|
|
|
17
|
-
export const HslInput = ( {
|
|
18
|
-
const
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
const isInternalColorSameAsReceivedColor = color.isEqual(
|
|
23
|
-
colord( internalHSLA )
|
|
24
|
-
);
|
|
25
|
-
|
|
26
|
-
useEffect( () => {
|
|
27
|
-
if ( ! isInternalColorSameAsReceivedColor ) {
|
|
28
|
-
// Keep internal HSLA color up to date with the received color prop
|
|
29
|
-
setInternalHSLA( colorPropHSLA );
|
|
30
|
-
}
|
|
31
|
-
}, [ colorPropHSLA, isInternalColorSameAsReceivedColor ] );
|
|
32
|
-
|
|
33
|
-
// If the internal color is equal to the received color prop, we can use the
|
|
34
|
-
// HSLA values from the local state which, compared to the received color prop,
|
|
35
|
-
// retain more details about the actual H and S values that the user selected,
|
|
36
|
-
// and thus allow for better UX when interacting with the H and S sliders.
|
|
37
|
-
const colorValue = isInternalColorSameAsReceivedColor
|
|
38
|
-
? internalHSLA
|
|
39
|
-
: colorPropHSLA;
|
|
40
|
-
|
|
41
|
-
const updateHSLAValue = (
|
|
42
|
-
partialNewValue: Partial< typeof colorPropHSLA >
|
|
43
|
-
) => {
|
|
44
|
-
const nextOnChangeValue = colord( {
|
|
45
|
-
...colorValue,
|
|
12
|
+
export const HslInput = ( { hsla, onChange, enableAlpha }: HslInputProps ) => {
|
|
13
|
+
const updateHSLAValue = ( partialNewValue: Partial< HslaColor > ) => {
|
|
14
|
+
onChange( {
|
|
15
|
+
...hsla,
|
|
46
16
|
...partialNewValue,
|
|
47
17
|
} );
|
|
48
|
-
|
|
49
|
-
// Fire `onChange` only if the resulting color is different from the
|
|
50
|
-
// current one.
|
|
51
|
-
// Otherwise, update the internal HSLA color to cause a re-render.
|
|
52
|
-
if ( ! color.isEqual( nextOnChangeValue ) ) {
|
|
53
|
-
onChange( nextOnChangeValue );
|
|
54
|
-
} else {
|
|
55
|
-
setInternalHSLA( ( prevHSLA ) => ( {
|
|
56
|
-
...prevHSLA,
|
|
57
|
-
...partialNewValue,
|
|
58
|
-
} ) );
|
|
59
|
-
}
|
|
60
18
|
};
|
|
61
19
|
|
|
62
20
|
return (
|
|
@@ -66,7 +24,7 @@ export const HslInput = ( { color, onChange, enableAlpha }: HslInputProps ) => {
|
|
|
66
24
|
max={ 359 }
|
|
67
25
|
label="Hue"
|
|
68
26
|
abbreviation="H"
|
|
69
|
-
value={
|
|
27
|
+
value={ hsla.h }
|
|
70
28
|
onChange={ ( nextH: number ) => {
|
|
71
29
|
updateHSLAValue( { h: nextH } );
|
|
72
30
|
} }
|
|
@@ -76,7 +34,7 @@ export const HslInput = ( { color, onChange, enableAlpha }: HslInputProps ) => {
|
|
|
76
34
|
max={ 100 }
|
|
77
35
|
label="Saturation"
|
|
78
36
|
abbreviation="S"
|
|
79
|
-
value={
|
|
37
|
+
value={ hsla.s }
|
|
80
38
|
onChange={ ( nextS: number ) => {
|
|
81
39
|
updateHSLAValue( { s: nextS } );
|
|
82
40
|
} }
|
|
@@ -86,7 +44,7 @@ export const HslInput = ( { color, onChange, enableAlpha }: HslInputProps ) => {
|
|
|
86
44
|
max={ 100 }
|
|
87
45
|
label="Lightness"
|
|
88
46
|
abbreviation="L"
|
|
89
|
-
value={
|
|
47
|
+
value={ hsla.l }
|
|
90
48
|
onChange={ ( nextL: number ) => {
|
|
91
49
|
updateHSLAValue( { l: nextL } );
|
|
92
50
|
} }
|
|
@@ -97,7 +55,7 @@ export const HslInput = ( { color, onChange, enableAlpha }: HslInputProps ) => {
|
|
|
97
55
|
max={ 100 }
|
|
98
56
|
label="Alpha"
|
|
99
57
|
abbreviation="A"
|
|
100
|
-
value={ Math.trunc( 100 *
|
|
58
|
+
value={ Math.trunc( 100 * hsla.a ) }
|
|
101
59
|
onChange={ ( nextA: number ) => {
|
|
102
60
|
updateHSLAValue( { a: nextA / 100 } );
|
|
103
61
|
} }
|
|
@@ -1,40 +1,44 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* External dependencies
|
|
3
3
|
*/
|
|
4
|
-
import {
|
|
5
|
-
import { colord } from 'colord';
|
|
4
|
+
import { HslColorPicker, HslaColorPicker } from 'react-colorful';
|
|
6
5
|
|
|
7
|
-
/**
|
|
8
|
-
* WordPress dependencies
|
|
9
|
-
*/
|
|
10
|
-
import { useMemo } from '@wordpress/element';
|
|
11
6
|
/**
|
|
12
7
|
* Internal dependencies
|
|
13
8
|
*/
|
|
14
9
|
import type { PickerProps } from './types';
|
|
15
10
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
11
|
+
// Pointer capture fortifies drag gestures so that they continue to work
|
|
12
|
+
// while dragging outside the component over objects like iframes. If a
|
|
13
|
+
// newer version of react-colorful begins to employ pointer capture this
|
|
14
|
+
// will be redundant and should be removed.
|
|
15
|
+
const pointerCaptureProps = {
|
|
16
|
+
onPointerDown( { currentTarget, pointerId }: React.PointerEvent ) {
|
|
17
|
+
currentTarget.setPointerCapture( pointerId );
|
|
18
|
+
},
|
|
19
|
+
onPointerUp( { currentTarget, pointerId }: React.PointerEvent ) {
|
|
20
|
+
currentTarget.releasePointerCapture( pointerId );
|
|
21
|
+
},
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export const Picker = ( { hsla, enableAlpha, onChange }: PickerProps ) => {
|
|
25
|
+
if ( enableAlpha ) {
|
|
26
|
+
return (
|
|
27
|
+
<HslaColorPicker
|
|
28
|
+
color={ hsla }
|
|
29
|
+
onChange={ onChange }
|
|
30
|
+
{ ...pointerCaptureProps }
|
|
31
|
+
/>
|
|
32
|
+
);
|
|
33
|
+
}
|
|
21
34
|
|
|
22
35
|
return (
|
|
23
|
-
<
|
|
24
|
-
color={
|
|
36
|
+
<HslColorPicker
|
|
37
|
+
color={ hsla }
|
|
25
38
|
onChange={ ( nextColor ) => {
|
|
26
|
-
onChange(
|
|
27
|
-
} }
|
|
28
|
-
// Pointer capture fortifies drag gestures so that they continue to
|
|
29
|
-
// work while dragging outside the component over objects like
|
|
30
|
-
// iframes. If a newer version of react-colorful begins to employ
|
|
31
|
-
// pointer capture this will be redundant and should be removed.
|
|
32
|
-
onPointerDown={ ( { currentTarget, pointerId } ) => {
|
|
33
|
-
currentTarget.setPointerCapture( pointerId );
|
|
34
|
-
} }
|
|
35
|
-
onPointerUp={ ( { currentTarget, pointerId } ) => {
|
|
36
|
-
currentTarget.releasePointerCapture( pointerId );
|
|
39
|
+
onChange( { ...nextColor, a: hsla.a } );
|
|
37
40
|
} }
|
|
41
|
+
{ ...pointerCaptureProps }
|
|
38
42
|
/>
|
|
39
43
|
);
|
|
40
44
|
};
|
|
@@ -248,18 +248,19 @@ describe( 'ColorPicker', () => {
|
|
|
248
248
|
expect( onChange ).toHaveBeenLastCalledWith( '#597326' );
|
|
249
249
|
|
|
250
250
|
// Interact with the Lightness slider, setting to 100 (ie. white).
|
|
251
|
-
// It should also cause the `onChange` callback to fire
|
|
252
|
-
//
|
|
251
|
+
// It should also cause the `onChange` callback to fire. The hue and
|
|
252
|
+
// saturation should be preserved (not reset to 0) since the user
|
|
253
|
+
// explicitly set them earlier.
|
|
253
254
|
fireEvent.change( lightnessSlider, { target: { value: 100 } } );
|
|
254
255
|
|
|
255
256
|
await waitFor( () =>
|
|
256
257
|
expect( lightnessSlider ).toHaveValue( '100' )
|
|
257
258
|
);
|
|
258
259
|
expect( lightnessNumberInput ).toHaveValue( 100 );
|
|
259
|
-
expect( hueSlider ).toHaveValue( '
|
|
260
|
-
expect( saturationSlider ).toHaveValue( '
|
|
261
|
-
expect( hueNumberInput ).toHaveValue(
|
|
262
|
-
expect( saturationNumberInput ).toHaveValue(
|
|
260
|
+
expect( hueSlider ).toHaveValue( '80' );
|
|
261
|
+
expect( saturationSlider ).toHaveValue( '50' );
|
|
262
|
+
expect( hueNumberInput ).toHaveValue( 80 );
|
|
263
|
+
expect( saturationNumberInput ).toHaveValue( 50 );
|
|
263
264
|
expect( onChange ).toHaveBeenCalledTimes( 2 );
|
|
264
265
|
expect( onChange ).toHaveBeenLastCalledWith( '#ffffff' );
|
|
265
266
|
|
|
@@ -309,6 +310,138 @@ describe( 'ColorPicker', () => {
|
|
|
309
310
|
expect( lightnessNumberInput ).toHaveValue( 52 );
|
|
310
311
|
} );
|
|
311
312
|
|
|
313
|
+
it( 'should preserve hue and saturation when lightness is set to 0 (black)', async () => {
|
|
314
|
+
const onChange = jest.fn();
|
|
315
|
+
|
|
316
|
+
render(
|
|
317
|
+
<ControlledColorPicker
|
|
318
|
+
onChange={ onChange }
|
|
319
|
+
enableAlpha={ false }
|
|
320
|
+
initialColor="#2ad5d5" // hsl(180, 67%, 50%)
|
|
321
|
+
/>
|
|
322
|
+
);
|
|
323
|
+
|
|
324
|
+
const formatSelector = screen.getByRole( 'combobox' );
|
|
325
|
+
await userEvent.setup().selectOptions( formatSelector, 'hsl' );
|
|
326
|
+
|
|
327
|
+
const hueSliders = screen.getAllByRole( 'slider', { name: 'Hue' } );
|
|
328
|
+
const hueSlider = hueSliders.at( -1 )!;
|
|
329
|
+
const saturationSlider = screen.getByRole( 'slider', {
|
|
330
|
+
name: 'Saturation',
|
|
331
|
+
} );
|
|
332
|
+
const lightnessSlider = screen.getByRole( 'slider', {
|
|
333
|
+
name: 'Lightness',
|
|
334
|
+
} );
|
|
335
|
+
const hueNumberInput = screen.getByRole( 'spinbutton', {
|
|
336
|
+
name: 'Hue',
|
|
337
|
+
} );
|
|
338
|
+
const saturationNumberInput = screen.getByRole( 'spinbutton', {
|
|
339
|
+
name: 'Saturation',
|
|
340
|
+
} );
|
|
341
|
+
|
|
342
|
+
// Verify initial values
|
|
343
|
+
expect( hueSlider ).toHaveValue( '180' );
|
|
344
|
+
expect( saturationSlider ).toHaveValue( '67' );
|
|
345
|
+
|
|
346
|
+
// Set lightness to 0 (black)
|
|
347
|
+
fireEvent.change( lightnessSlider, { target: { value: 0 } } );
|
|
348
|
+
|
|
349
|
+
await waitFor( () => expect( lightnessSlider ).toHaveValue( '0' ) );
|
|
350
|
+
|
|
351
|
+
// Hue and saturation should be preserved
|
|
352
|
+
expect( hueSlider ).toHaveValue( '180' );
|
|
353
|
+
expect( saturationSlider ).toHaveValue( '67' );
|
|
354
|
+
expect( hueNumberInput ).toHaveValue( 180 );
|
|
355
|
+
expect( saturationNumberInput ).toHaveValue( 67 );
|
|
356
|
+
expect( onChange ).toHaveBeenLastCalledWith( '#000000' );
|
|
357
|
+
} );
|
|
358
|
+
|
|
359
|
+
it( 'should reset saturation to 0 when a mid-gray is entered via hex input', async () => {
|
|
360
|
+
const user = userEvent.setup();
|
|
361
|
+
|
|
362
|
+
render(
|
|
363
|
+
<ControlledColorPicker
|
|
364
|
+
enableAlpha={ false }
|
|
365
|
+
initialColor="#2ad5d5" // hsl(180, 67%, 50%)
|
|
366
|
+
/>
|
|
367
|
+
);
|
|
368
|
+
|
|
369
|
+
const formatSelector = screen.getByRole( 'combobox' );
|
|
370
|
+
|
|
371
|
+
// Start in hex mode and enter a mid-gray.
|
|
372
|
+
await user.selectOptions( formatSelector, 'hex' );
|
|
373
|
+
const hexInput = screen.getByRole( 'textbox' );
|
|
374
|
+
await user.clear( hexInput );
|
|
375
|
+
await user.type( hexInput, '808080' );
|
|
376
|
+
|
|
377
|
+
// Switch to HSL to inspect the values.
|
|
378
|
+
await user.selectOptions( formatSelector, 'hsl' );
|
|
379
|
+
|
|
380
|
+
const saturationSlider = screen.getByRole( 'slider', {
|
|
381
|
+
name: 'Saturation',
|
|
382
|
+
} );
|
|
383
|
+
const saturationNumberInput = screen.getByRole( 'spinbutton', {
|
|
384
|
+
name: 'Saturation',
|
|
385
|
+
} );
|
|
386
|
+
|
|
387
|
+
// #808080 is hsl(0, 0%, 50%) — a pure mid-gray.
|
|
388
|
+
// Saturation must be 0, not the stale value from the
|
|
389
|
+
// previous chromatic color.
|
|
390
|
+
await waitFor( () =>
|
|
391
|
+
expect( saturationSlider ).toHaveValue( '0' )
|
|
392
|
+
);
|
|
393
|
+
expect( saturationNumberInput ).toHaveValue( 0 );
|
|
394
|
+
} );
|
|
395
|
+
|
|
396
|
+
it( 'should preserve hue when saturation is set to 0', async () => {
|
|
397
|
+
const onChange = jest.fn();
|
|
398
|
+
|
|
399
|
+
render(
|
|
400
|
+
<ControlledColorPicker
|
|
401
|
+
onChange={ onChange }
|
|
402
|
+
enableAlpha={ false }
|
|
403
|
+
initialColor="#ff0000" // hsl(0, 100%, 50%) - pure red
|
|
404
|
+
/>
|
|
405
|
+
);
|
|
406
|
+
|
|
407
|
+
const formatSelector = screen.getByRole( 'combobox' );
|
|
408
|
+
await userEvent.setup().selectOptions( formatSelector, 'hsl' );
|
|
409
|
+
|
|
410
|
+
const hueSliders = screen.getAllByRole( 'slider', { name: 'Hue' } );
|
|
411
|
+
const hueSlider = hueSliders.at( -1 )!;
|
|
412
|
+
const saturationSlider = screen.getByRole( 'slider', {
|
|
413
|
+
name: 'Saturation',
|
|
414
|
+
} );
|
|
415
|
+
const hueNumberInput = screen.getByRole( 'spinbutton', {
|
|
416
|
+
name: 'Hue',
|
|
417
|
+
} );
|
|
418
|
+
|
|
419
|
+
// Set a specific hue first
|
|
420
|
+
fireEvent.change( hueSlider, { target: { value: 200 } } );
|
|
421
|
+
|
|
422
|
+
await waitFor( () => expect( hueSlider ).toHaveValue( '200' ) );
|
|
423
|
+
|
|
424
|
+
// Set saturation to 0 (grayscale)
|
|
425
|
+
fireEvent.change( saturationSlider, { target: { value: 0 } } );
|
|
426
|
+
|
|
427
|
+
await waitFor( () =>
|
|
428
|
+
expect( saturationSlider ).toHaveValue( '0' )
|
|
429
|
+
);
|
|
430
|
+
|
|
431
|
+
// Hue should be preserved even though color is now gray
|
|
432
|
+
expect( hueSlider ).toHaveValue( '200' );
|
|
433
|
+
expect( hueNumberInput ).toHaveValue( 200 );
|
|
434
|
+
|
|
435
|
+
// Increase saturation again - hue should still be 200
|
|
436
|
+
fireEvent.change( saturationSlider, { target: { value: 50 } } );
|
|
437
|
+
|
|
438
|
+
await waitFor( () =>
|
|
439
|
+
expect( saturationSlider ).toHaveValue( '50' )
|
|
440
|
+
);
|
|
441
|
+
|
|
442
|
+
expect( hueSlider ).toHaveValue( '200' );
|
|
443
|
+
expect( hueNumberInput ).toHaveValue( 200 );
|
|
444
|
+
} );
|
|
312
445
|
describe.each( [
|
|
313
446
|
[ 'hue', 'Hue', '#aad52a' ],
|
|
314
447
|
[ 'saturation', 'Saturation', '#20dfdf' ],
|
|
@@ -56,15 +56,17 @@ export type ColorPickerProps = WordPressComponentProps<
|
|
|
56
56
|
>;
|
|
57
57
|
|
|
58
58
|
export interface PickerProps {
|
|
59
|
-
|
|
59
|
+
hsla: HslaColor;
|
|
60
60
|
enableAlpha: boolean;
|
|
61
|
-
onChange: (
|
|
61
|
+
onChange: ( nextHsla: HslaColor ) => void;
|
|
62
62
|
}
|
|
63
63
|
|
|
64
64
|
export interface ColorInputProps {
|
|
65
65
|
colorType: 'hsl' | 'hex' | 'rgb';
|
|
66
66
|
color: Colord;
|
|
67
|
+
hsla: HslaColor;
|
|
67
68
|
onChange: ( nextColor: Colord ) => void;
|
|
69
|
+
onHSLChange: ( nextHsla: HslaColor ) => void;
|
|
68
70
|
enableAlpha: boolean;
|
|
69
71
|
}
|
|
70
72
|
|
|
@@ -84,8 +86,8 @@ export interface HexInputProps {
|
|
|
84
86
|
}
|
|
85
87
|
|
|
86
88
|
export interface HslInputProps {
|
|
87
|
-
|
|
88
|
-
onChange: (
|
|
89
|
+
hsla: HslaColor;
|
|
90
|
+
onChange: ( nextHsla: HslaColor ) => void;
|
|
89
91
|
enableAlpha: boolean;
|
|
90
92
|
}
|
|
91
93
|
|