@wordpress/components 19.6.1-next.a55ed9455a.0 → 19.7.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 +31 -1
- package/build/base-control/index.js +19 -14
- package/build/base-control/index.js.map +1 -1
- package/build/base-control/styles/base-control-styles.js +33 -12
- package/build/base-control/styles/base-control-styles.js.map +1 -1
- package/build/box-control/all-input-control.js +3 -7
- package/build/box-control/all-input-control.js.map +1 -1
- package/build/box-control/axial-input-controls.js +20 -15
- package/build/box-control/axial-input-controls.js.map +1 -1
- package/build/box-control/input-controls.js +21 -16
- package/build/box-control/input-controls.js.map +1 -1
- package/build/box-control/utils.js +25 -11
- package/build/box-control/utils.js.map +1 -1
- package/build/checkbox-control/index.js +21 -1
- package/build/checkbox-control/index.js.map +1 -1
- package/build/color-palette/index.js +53 -4
- package/build/color-palette/index.js.map +1 -1
- package/build/custom-select-control/index.js +8 -3
- package/build/custom-select-control/index.js.map +1 -1
- package/build/divider/styles.js +28 -16
- package/build/divider/styles.js.map +1 -1
- package/build/focal-point-picker/controls.js +2 -3
- package/build/focal-point-picker/controls.js.map +1 -1
- package/build/form-file-upload/index.js +4 -1
- package/build/form-file-upload/index.js.map +1 -1
- package/build/input-control/input-field.js +21 -14
- package/build/input-control/input-field.js.map +1 -1
- package/build/input-control/reducer/actions.js +1 -3
- package/build/input-control/reducer/actions.js.map +1 -1
- package/build/input-control/reducer/reducer.js +1 -43
- package/build/input-control/reducer/reducer.js.map +1 -1
- package/build/number-control/index.js +15 -10
- package/build/number-control/index.js.map +1 -1
- package/build/resizable-box/resize-tooltip/styles/resize-tooltip.styles.js +4 -4
- package/build/resizable-box/resize-tooltip/styles/resize-tooltip.styles.js.map +1 -1
- package/build/toggle-group-control/toggle-group-control-option/component.js +1 -4
- package/build/toggle-group-control/toggle-group-control-option/component.js.map +1 -1
- package/build/toggle-group-control/toggle-group-control-option/styles.js +12 -19
- package/build/toggle-group-control/toggle-group-control-option/styles.js.map +1 -1
- package/build/tree-grid/index.js +4 -1
- package/build/tree-grid/index.js.map +1 -1
- package/build/unit-control/index.js +49 -27
- package/build/unit-control/index.js.map +1 -1
- package/build/unit-control/unit-select-control.js +2 -4
- package/build/unit-control/unit-select-control.js.map +1 -1
- package/build-module/base-control/index.js +19 -14
- package/build-module/base-control/index.js.map +1 -1
- package/build-module/base-control/styles/base-control-styles.js +34 -6
- package/build-module/base-control/styles/base-control-styles.js.map +1 -1
- package/build-module/box-control/all-input-control.js +4 -8
- package/build-module/box-control/all-input-control.js.map +1 -1
- package/build-module/box-control/axial-input-controls.js +18 -14
- package/build-module/box-control/axial-input-controls.js.map +1 -1
- package/build-module/box-control/input-controls.js +18 -14
- package/build-module/box-control/input-controls.js.map +1 -1
- package/build-module/box-control/utils.js +25 -11
- package/build-module/box-control/utils.js.map +1 -1
- package/build-module/checkbox-control/index.js +24 -3
- package/build-module/checkbox-control/index.js.map +1 -1
- package/build-module/color-palette/index.js +52 -4
- package/build-module/color-palette/index.js.map +1 -1
- package/build-module/custom-select-control/index.js +8 -3
- package/build-module/custom-select-control/index.js.map +1 -1
- package/build-module/divider/styles.js +29 -10
- package/build-module/divider/styles.js.map +1 -1
- package/build-module/focal-point-picker/controls.js +2 -3
- package/build-module/focal-point-picker/controls.js.map +1 -1
- package/build-module/form-file-upload/index.js +4 -1
- package/build-module/form-file-upload/index.js.map +1 -1
- package/build-module/input-control/input-field.js +21 -13
- package/build-module/input-control/input-field.js.map +1 -1
- package/build-module/input-control/reducer/actions.js +0 -1
- package/build-module/input-control/reducer/actions.js.map +1 -1
- package/build-module/input-control/reducer/reducer.js +2 -39
- package/build-module/input-control/reducer/reducer.js.map +1 -1
- package/build-module/number-control/index.js +15 -9
- package/build-module/number-control/index.js.map +1 -1
- package/build-module/resizable-box/resize-tooltip/styles/resize-tooltip.styles.js +4 -4
- package/build-module/resizable-box/resize-tooltip/styles/resize-tooltip.styles.js.map +1 -1
- package/build-module/toggle-group-control/toggle-group-control-option/component.js +1 -4
- package/build-module/toggle-group-control/toggle-group-control-option/component.js.map +1 -1
- package/build-module/toggle-group-control/toggle-group-control-option/styles.js +11 -17
- package/build-module/toggle-group-control/toggle-group-control-option/styles.js.map +1 -1
- package/build-module/tree-grid/index.js +4 -1
- package/build-module/tree-grid/index.js.map +1 -1
- package/build-module/unit-control/index.js +47 -25
- package/build-module/unit-control/index.js.map +1 -1
- package/build-module/unit-control/unit-select-control.js +2 -3
- package/build-module/unit-control/unit-select-control.js.map +1 -1
- package/build-style/style-rtl.css +29 -181
- package/build-style/style.css +29 -181
- package/build-types/base-control/index.d.ts +23 -18
- package/build-types/base-control/index.d.ts.map +1 -1
- package/build-types/base-control/styles/base-control-styles.d.ts +4 -0
- package/build-types/base-control/styles/base-control-styles.d.ts.map +1 -1
- package/build-types/card/card-divider/hook.d.ts +1 -1
- package/build-types/color-palette/index.d.ts.map +1 -1
- package/build-types/color-picker/styles.d.ts +1 -1
- package/build-types/divider/stories/index.d.ts +1 -0
- package/build-types/divider/stories/index.d.ts.map +1 -1
- package/build-types/divider/styles.d.ts.map +1 -1
- package/build-types/divider/types.d.ts +8 -1
- package/build-types/divider/types.d.ts.map +1 -1
- package/build-types/input-control/input-field.d.ts.map +1 -1
- package/build-types/input-control/reducer/actions.d.ts +1 -3
- package/build-types/input-control/reducer/actions.d.ts.map +1 -1
- package/build-types/input-control/reducer/reducer.d.ts +3 -9
- package/build-types/input-control/reducer/reducer.d.ts.map +1 -1
- package/build-types/input-control/types.d.ts +2 -2
- package/build-types/input-control/types.d.ts.map +1 -1
- package/build-types/number-control/index.d.ts +3 -3
- package/build-types/number-control/index.d.ts.map +1 -1
- package/build-types/range-control/styles/range-control-styles.d.ts +1 -1
- package/build-types/resizable-box/resize-tooltip/styles/resize-tooltip.styles.d.ts.map +1 -1
- package/build-types/toggle-group-control/toggle-group-control-option/component.d.ts.map +1 -1
- package/build-types/toggle-group-control/toggle-group-control-option/styles.d.ts +0 -4
- package/build-types/toggle-group-control/toggle-group-control-option/styles.d.ts.map +1 -1
- package/build-types/unit-control/index.d.ts +7 -4
- package/build-types/unit-control/index.d.ts.map +1 -1
- package/build-types/unit-control/stories/index.d.ts +33 -0
- package/build-types/unit-control/stories/index.d.ts.map +1 -0
- package/build-types/unit-control/styles/unit-control-styles.d.ts +1 -1
- package/build-types/unit-control/types.d.ts +23 -6
- package/build-types/unit-control/types.d.ts.map +1 -1
- package/build-types/unit-control/unit-select-control.d.ts.map +1 -1
- package/package.json +17 -17
- package/src/base-control/README.md +9 -1
- package/src/base-control/index.js +20 -13
- package/src/base-control/stories/index.js +2 -2
- package/src/base-control/styles/base-control-styles.js +23 -1
- package/src/box-control/all-input-control.js +2 -10
- package/src/box-control/axial-input-controls.js +32 -21
- package/src/box-control/input-controls.js +30 -19
- package/src/box-control/utils.js +29 -12
- package/src/checkbox-control/index.js +34 -3
- package/src/checkbox-control/stories/index.js +44 -0
- package/src/checkbox-control/style.scss +4 -2
- package/src/color-palette/index.js +73 -8
- package/src/color-palette/stories/index.js +62 -26
- package/src/color-palette/style.scss +11 -3
- package/src/color-palette/test/__snapshots__/index.js.snap +662 -12
- package/src/color-palette/test/index.js +1 -1
- package/src/custom-select-control/index.js +8 -2
- package/src/custom-select-control/stories/index.js +77 -74
- package/src/custom-select-control/style.scss +18 -3
- package/src/divider/stories/index.tsx +26 -23
- package/src/divider/styles.ts +9 -0
- package/src/divider/types.ts +11 -1
- package/src/focal-point-picker/controls.js +2 -3
- package/src/font-size-picker/test/index.js +0 -2
- package/src/form-file-upload/README.md +18 -0
- package/src/form-file-upload/index.js +3 -0
- package/src/form-file-upload/test/index.js +73 -11
- package/src/input-control/input-field.tsx +23 -12
- package/src/input-control/reducer/actions.ts +1 -7
- package/src/input-control/reducer/reducer.ts +0 -29
- package/src/input-control/types.ts +2 -1
- package/src/mobile/image/style.native.scss +1 -0
- package/src/number-control/README.md +14 -0
- package/src/number-control/index.js +13 -12
- package/src/number-control/stories/index.js +14 -7
- package/src/number-control/test/index.js +79 -1
- package/src/range-control/stories/index.js +91 -119
- package/src/resizable-box/resize-tooltip/styles/resize-tooltip.styles.js +1 -0
- package/src/toggle-group-control/test/__snapshots__/index.js.snap +0 -27
- package/src/toggle-group-control/toggle-group-control-option/component.tsx +1 -4
- package/src/toggle-group-control/toggle-group-control-option/styles.ts +0 -12
- package/src/toolbar-group/style.scss +0 -73
- package/src/tree-grid/README.md +1 -1
- package/src/tree-grid/index.js +4 -0
- package/src/tree-grid/test/index.js +61 -17
- package/src/unit-control/README.md +1 -3
- package/src/unit-control/index.tsx +59 -30
- package/src/unit-control/stories/index.tsx +170 -0
- package/src/unit-control/test/index.js +143 -100
- package/src/unit-control/types.ts +60 -41
- package/src/unit-control/unit-select-control.tsx +2 -3
- package/tsconfig.tsbuildinfo +1 -1
- package/src/unit-control/stories/index.js +0 -127
package/src/box-control/utils.js
CHANGED
|
@@ -61,24 +61,32 @@ function mode( arr ) {
|
|
|
61
61
|
* Gets the 'all' input value and unit from values data.
|
|
62
62
|
*
|
|
63
63
|
* @param {Object} values Box values.
|
|
64
|
+
* @param {Object} selectedUnits Box units.
|
|
64
65
|
* @param {Array} availableSides Available box sides to evaluate.
|
|
65
66
|
*
|
|
66
67
|
* @return {string} A value + unit for the 'all' input.
|
|
67
68
|
*/
|
|
68
|
-
export function getAllValue(
|
|
69
|
+
export function getAllValue(
|
|
70
|
+
values = {},
|
|
71
|
+
selectedUnits,
|
|
72
|
+
availableSides = ALL_SIDES
|
|
73
|
+
) {
|
|
69
74
|
const sides = normalizeSides( availableSides );
|
|
70
75
|
const parsedQuantitiesAndUnits = sides.map( ( side ) =>
|
|
71
76
|
parseQuantityAndUnitFromRawValue( values[ side ] )
|
|
72
77
|
);
|
|
73
|
-
const
|
|
78
|
+
const allParsedQuantities = parsedQuantitiesAndUnits.map(
|
|
74
79
|
( value ) => value[ 0 ] ?? ''
|
|
75
80
|
);
|
|
76
|
-
const
|
|
81
|
+
const allParsedUnits = parsedQuantitiesAndUnits.map(
|
|
82
|
+
( value ) => value[ 1 ]
|
|
83
|
+
);
|
|
77
84
|
|
|
78
|
-
const
|
|
79
|
-
|
|
85
|
+
const commonQuantity = allParsedQuantities.every(
|
|
86
|
+
( v ) => v === allParsedQuantities[ 0 ]
|
|
87
|
+
)
|
|
88
|
+
? allParsedQuantities[ 0 ]
|
|
80
89
|
: '';
|
|
81
|
-
const unit = mode( allUnits );
|
|
82
90
|
|
|
83
91
|
/**
|
|
84
92
|
* The isNumber check is important. On reset actions, the incoming value
|
|
@@ -89,9 +97,17 @@ export function getAllValue( values = {}, availableSides = ALL_SIDES ) {
|
|
|
89
97
|
* isNumber() is more specific for these cases, rather than relying on a
|
|
90
98
|
* simple truthy check.
|
|
91
99
|
*/
|
|
92
|
-
|
|
100
|
+
let commonUnit;
|
|
101
|
+
if ( isNumber( commonQuantity ) ) {
|
|
102
|
+
commonUnit = mode( allParsedUnits );
|
|
103
|
+
} else {
|
|
104
|
+
// Set meaningful unit selection if no commonQuantity and user has previously
|
|
105
|
+
// selected units without assigning values while controls were unlinked.
|
|
106
|
+
commonUnit =
|
|
107
|
+
getAllUnitFallback( selectedUnits ) ?? mode( allParsedUnits );
|
|
108
|
+
}
|
|
93
109
|
|
|
94
|
-
return
|
|
110
|
+
return [ commonQuantity, commonUnit ].join( '' );
|
|
95
111
|
}
|
|
96
112
|
|
|
97
113
|
/**
|
|
@@ -113,13 +129,14 @@ export function getAllUnitFallback( selectedUnits ) {
|
|
|
113
129
|
/**
|
|
114
130
|
* Checks to determine if values are mixed.
|
|
115
131
|
*
|
|
116
|
-
* @param {Object} values
|
|
117
|
-
* @param {
|
|
132
|
+
* @param {Object} values Box values.
|
|
133
|
+
* @param {Object} selectedUnits Box units.
|
|
134
|
+
* @param {Array} sides Available box sides to evaluate.
|
|
118
135
|
*
|
|
119
136
|
* @return {boolean} Whether values are mixed.
|
|
120
137
|
*/
|
|
121
|
-
export function isValuesMixed( values = {}, sides = ALL_SIDES ) {
|
|
122
|
-
const allValue = getAllValue( values, sides );
|
|
138
|
+
export function isValuesMixed( values = {}, selectedUnits, sides = ALL_SIDES ) {
|
|
139
|
+
const allValue = getAllValue( values, selectedUnits, sides );
|
|
123
140
|
const isMixed = isNaN( parseFloat( allValue ) );
|
|
124
141
|
|
|
125
142
|
return isMixed;
|
|
@@ -6,9 +6,10 @@ import classnames from 'classnames';
|
|
|
6
6
|
/**
|
|
7
7
|
* WordPress dependencies
|
|
8
8
|
*/
|
|
9
|
-
import {
|
|
9
|
+
import { useState } from '@wordpress/element';
|
|
10
|
+
import { useInstanceId, useRefEffect } from '@wordpress/compose';
|
|
10
11
|
import deprecated from '@wordpress/deprecated';
|
|
11
|
-
import { Icon, check } from '@wordpress/icons';
|
|
12
|
+
import { Icon, check, reset } from '@wordpress/icons';
|
|
12
13
|
|
|
13
14
|
/**
|
|
14
15
|
* Internal dependencies
|
|
@@ -20,6 +21,7 @@ export default function CheckboxControl( {
|
|
|
20
21
|
className,
|
|
21
22
|
heading,
|
|
22
23
|
checked,
|
|
24
|
+
indeterminate,
|
|
23
25
|
help,
|
|
24
26
|
onChange,
|
|
25
27
|
...props
|
|
@@ -31,6 +33,27 @@ export default function CheckboxControl( {
|
|
|
31
33
|
} );
|
|
32
34
|
}
|
|
33
35
|
|
|
36
|
+
const [ showCheckedIcon, setShowCheckedIcon ] = useState( false );
|
|
37
|
+
const [ showIndeterminateIcon, setShowIndeterminateIcon ] = useState(
|
|
38
|
+
false
|
|
39
|
+
);
|
|
40
|
+
|
|
41
|
+
// Run the following callback everytime the `ref` (and the additional
|
|
42
|
+
// dependencies) change.
|
|
43
|
+
const ref = useRefEffect(
|
|
44
|
+
( node ) => {
|
|
45
|
+
if ( ! node ) {
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// It cannot be set using an HTML attribute.
|
|
50
|
+
node.indeterminate = !! indeterminate;
|
|
51
|
+
|
|
52
|
+
setShowCheckedIcon( node.matches( ':checked' ) );
|
|
53
|
+
setShowIndeterminateIcon( node.matches( ':indeterminate' ) );
|
|
54
|
+
},
|
|
55
|
+
[ checked, indeterminate ]
|
|
56
|
+
);
|
|
34
57
|
const instanceId = useInstanceId( CheckboxControl );
|
|
35
58
|
const id = `inspector-checkbox-control-${ instanceId }`;
|
|
36
59
|
const onChangeValue = ( event ) => onChange( event.target.checked );
|
|
@@ -44,6 +67,7 @@ export default function CheckboxControl( {
|
|
|
44
67
|
>
|
|
45
68
|
<span className="components-checkbox-control__input-container">
|
|
46
69
|
<input
|
|
70
|
+
ref={ ref }
|
|
47
71
|
id={ id }
|
|
48
72
|
className="components-checkbox-control__input"
|
|
49
73
|
type="checkbox"
|
|
@@ -53,7 +77,14 @@ export default function CheckboxControl( {
|
|
|
53
77
|
aria-describedby={ !! help ? id + '__help' : undefined }
|
|
54
78
|
{ ...props }
|
|
55
79
|
/>
|
|
56
|
-
{
|
|
80
|
+
{ showIndeterminateIcon ? (
|
|
81
|
+
<Icon
|
|
82
|
+
icon={ reset }
|
|
83
|
+
className="components-checkbox-control__indeterminate"
|
|
84
|
+
role="presentation"
|
|
85
|
+
/>
|
|
86
|
+
) : null }
|
|
87
|
+
{ showCheckedIcon ? (
|
|
57
88
|
<Icon
|
|
58
89
|
icon={ check }
|
|
59
90
|
className="components-checkbox-control__checked"
|
|
@@ -45,3 +45,47 @@ export const all = () => {
|
|
|
45
45
|
|
|
46
46
|
return <CheckboxControlWithState label={ label } help={ help } checked />;
|
|
47
47
|
};
|
|
48
|
+
|
|
49
|
+
export const Indeterminate = () => {
|
|
50
|
+
const [ fruits, setFruits ] = useState( { apple: false, orange: false } );
|
|
51
|
+
|
|
52
|
+
const isAllChecked = Object.values( fruits ).every( Boolean );
|
|
53
|
+
const isIndeterminate =
|
|
54
|
+
Object.values( fruits ).some( Boolean ) && ! isAllChecked;
|
|
55
|
+
|
|
56
|
+
return (
|
|
57
|
+
<>
|
|
58
|
+
<CheckboxControl
|
|
59
|
+
label="Select All"
|
|
60
|
+
checked={ isAllChecked }
|
|
61
|
+
indeterminate={ isIndeterminate }
|
|
62
|
+
onChange={ ( newValue ) =>
|
|
63
|
+
setFruits( {
|
|
64
|
+
apple: newValue,
|
|
65
|
+
orange: newValue,
|
|
66
|
+
} )
|
|
67
|
+
}
|
|
68
|
+
/>
|
|
69
|
+
<CheckboxControl
|
|
70
|
+
label="Apple"
|
|
71
|
+
checked={ fruits.apple }
|
|
72
|
+
onChange={ ( apple ) =>
|
|
73
|
+
setFruits( ( prevState ) => ( {
|
|
74
|
+
...prevState,
|
|
75
|
+
apple,
|
|
76
|
+
} ) )
|
|
77
|
+
}
|
|
78
|
+
/>
|
|
79
|
+
<CheckboxControl
|
|
80
|
+
label="Orange"
|
|
81
|
+
checked={ fruits.orange }
|
|
82
|
+
onChange={ ( orange ) =>
|
|
83
|
+
setFruits( ( prevState ) => ( {
|
|
84
|
+
...prevState,
|
|
85
|
+
orange,
|
|
86
|
+
} ) )
|
|
87
|
+
}
|
|
88
|
+
/>
|
|
89
|
+
</>
|
|
90
|
+
);
|
|
91
|
+
};
|
|
@@ -33,7 +33,8 @@ $checkbox-input-size-sm: 24px; // Width & height for small viewports.
|
|
|
33
33
|
outline: 2px solid transparent;
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
-
&:checked
|
|
36
|
+
&:checked,
|
|
37
|
+
&:indeterminate {
|
|
37
38
|
background: var(--wp-admin-theme-color);
|
|
38
39
|
border-color: var(--wp-admin-theme-color);
|
|
39
40
|
|
|
@@ -62,7 +63,8 @@ $checkbox-input-size-sm: 24px; // Width & height for small viewports.
|
|
|
62
63
|
}
|
|
63
64
|
}
|
|
64
65
|
|
|
65
|
-
svg.components-checkbox-control__checked
|
|
66
|
+
svg.components-checkbox-control__checked,
|
|
67
|
+
svg.components-checkbox-control__indeterminate {
|
|
66
68
|
fill: $white;
|
|
67
69
|
cursor: pointer;
|
|
68
70
|
position: absolute;
|
|
@@ -21,6 +21,8 @@ import Dropdown from '../dropdown';
|
|
|
21
21
|
import { ColorPicker } from '../color-picker';
|
|
22
22
|
import CircularOptionPicker from '../circular-option-picker';
|
|
23
23
|
import { VStack } from '../v-stack';
|
|
24
|
+
import { Flex, FlexItem } from '../flex';
|
|
25
|
+
import { Truncate } from '../truncate';
|
|
24
26
|
import { ColorHeading } from './styles';
|
|
25
27
|
|
|
26
28
|
extend( [ namesPlugin, a11yPlugin ] );
|
|
@@ -125,6 +127,31 @@ export function CustomColorPickerDropdown( { isRenderedInSidebar, ...props } ) {
|
|
|
125
127
|
);
|
|
126
128
|
}
|
|
127
129
|
|
|
130
|
+
const extractColorNameFromCurrentValue = (
|
|
131
|
+
currentValue,
|
|
132
|
+
colors = [],
|
|
133
|
+
showMultiplePalettes = false
|
|
134
|
+
) => {
|
|
135
|
+
if ( ! currentValue ) {
|
|
136
|
+
return '';
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
// Normalize format of `colors` to simplify the following loop
|
|
140
|
+
const colorPalettes = showMultiplePalettes ? colors : [ { colors } ];
|
|
141
|
+
for ( const { colors: paletteColors } of colorPalettes ) {
|
|
142
|
+
for ( const { name: colorName, color: colorValue } of paletteColors ) {
|
|
143
|
+
if (
|
|
144
|
+
colord( currentValue ).toHex() === colord( colorValue ).toHex()
|
|
145
|
+
) {
|
|
146
|
+
return colorName;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
// translators: shown when the user has picked a custom color (i.e not in the palette of colors).
|
|
152
|
+
return __( 'Custom' );
|
|
153
|
+
};
|
|
154
|
+
|
|
128
155
|
export default function ColorPalette( {
|
|
129
156
|
clearable = true,
|
|
130
157
|
className,
|
|
@@ -137,10 +164,9 @@ export default function ColorPalette( {
|
|
|
137
164
|
__experimentalIsRenderedInSidebar = false,
|
|
138
165
|
} ) {
|
|
139
166
|
const clearColor = useCallback( () => onChange( undefined ), [ onChange ] );
|
|
140
|
-
const
|
|
141
|
-
__experimentalHasMultipleOrigins && colors?.length
|
|
142
|
-
|
|
143
|
-
: SinglePalette;
|
|
167
|
+
const showMultiplePalettes =
|
|
168
|
+
__experimentalHasMultipleOrigins && colors?.length;
|
|
169
|
+
const Component = showMultiplePalettes ? MultiplePalettes : SinglePalette;
|
|
144
170
|
|
|
145
171
|
const renderCustomColorPicker = () => (
|
|
146
172
|
<ColorPicker
|
|
@@ -157,6 +183,30 @@ export default function ColorPalette( {
|
|
|
157
183
|
|
|
158
184
|
const colordColor = colord( value );
|
|
159
185
|
|
|
186
|
+
const valueWithoutLeadingHash = value?.startsWith( '#' )
|
|
187
|
+
? value.substring( 1 )
|
|
188
|
+
: value ?? '';
|
|
189
|
+
const buttonLabelName = useMemo(
|
|
190
|
+
() =>
|
|
191
|
+
extractColorNameFromCurrentValue(
|
|
192
|
+
value,
|
|
193
|
+
colors,
|
|
194
|
+
showMultiplePalettes
|
|
195
|
+
),
|
|
196
|
+
[ value, colors, showMultiplePalettes ]
|
|
197
|
+
);
|
|
198
|
+
|
|
199
|
+
const customColorAccessibleLabel = !! valueWithoutLeadingHash
|
|
200
|
+
? sprintf(
|
|
201
|
+
// translators: %1$s: The name of the color e.g: "vivid red". %2$s: The color's hex code e.g: "#f00".
|
|
202
|
+
__(
|
|
203
|
+
'Custom color picker. The currently selected color is called "%1$s" and has a value of "%2$s".'
|
|
204
|
+
),
|
|
205
|
+
buttonLabelName,
|
|
206
|
+
valueWithoutLeadingHash
|
|
207
|
+
)
|
|
208
|
+
: __( 'Custom color picker.' );
|
|
209
|
+
|
|
160
210
|
return (
|
|
161
211
|
<VStack spacing={ 3 } className={ className }>
|
|
162
212
|
{ ! disableCustomColors && (
|
|
@@ -165,12 +215,15 @@ export default function ColorPalette( {
|
|
|
165
215
|
isRenderedInSidebar={ __experimentalIsRenderedInSidebar }
|
|
166
216
|
renderContent={ renderCustomColorPicker }
|
|
167
217
|
renderToggle={ ( { isOpen, onToggle } ) => (
|
|
168
|
-
<
|
|
218
|
+
<Flex
|
|
219
|
+
as={ 'button' }
|
|
220
|
+
justify="space-between"
|
|
221
|
+
align="flex-start"
|
|
169
222
|
className="components-color-palette__custom-color"
|
|
170
223
|
aria-expanded={ isOpen }
|
|
171
224
|
aria-haspopup="true"
|
|
172
225
|
onClick={ onToggle }
|
|
173
|
-
aria-label={
|
|
226
|
+
aria-label={ customColorAccessibleLabel }
|
|
174
227
|
style={ {
|
|
175
228
|
background: value,
|
|
176
229
|
color:
|
|
@@ -180,8 +233,20 @@ export default function ColorPalette( {
|
|
|
180
233
|
: '#000',
|
|
181
234
|
} }
|
|
182
235
|
>
|
|
183
|
-
|
|
184
|
-
|
|
236
|
+
<FlexItem
|
|
237
|
+
isBlock
|
|
238
|
+
as={ Truncate }
|
|
239
|
+
className="components-color-palette__custom-color-name"
|
|
240
|
+
>
|
|
241
|
+
{ buttonLabelName }
|
|
242
|
+
</FlexItem>
|
|
243
|
+
<FlexItem
|
|
244
|
+
as="span"
|
|
245
|
+
className="components-color-palette__custom-color-value"
|
|
246
|
+
>
|
|
247
|
+
{ valueWithoutLeadingHash }
|
|
248
|
+
</FlexItem>
|
|
249
|
+
</Flex>
|
|
185
250
|
) }
|
|
186
251
|
/>
|
|
187
252
|
) }
|
|
@@ -1,8 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* External dependencies
|
|
3
|
-
*/
|
|
4
|
-
import { object } from '@storybook/addon-knobs';
|
|
5
|
-
|
|
6
1
|
/**
|
|
7
2
|
* WordPress dependencies
|
|
8
3
|
*/
|
|
@@ -13,35 +8,76 @@ import { useState } from '@wordpress/element';
|
|
|
13
8
|
*/
|
|
14
9
|
import ColorPalette from '../';
|
|
15
10
|
|
|
16
|
-
|
|
11
|
+
const meta = {
|
|
17
12
|
title: 'Components/ColorPalette',
|
|
18
13
|
component: ColorPalette,
|
|
14
|
+
argTypes: {
|
|
15
|
+
__experimentalHasMultipleOrigins: {
|
|
16
|
+
control: {
|
|
17
|
+
type: null,
|
|
18
|
+
},
|
|
19
|
+
},
|
|
20
|
+
__experimentalIsRenderedInSidebar: {
|
|
21
|
+
control: {
|
|
22
|
+
type: 'boolean',
|
|
23
|
+
},
|
|
24
|
+
},
|
|
25
|
+
clearable: {
|
|
26
|
+
control: {
|
|
27
|
+
type: 'boolean',
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
disableCustomColors: {
|
|
31
|
+
control: {
|
|
32
|
+
type: 'boolean',
|
|
33
|
+
},
|
|
34
|
+
},
|
|
35
|
+
},
|
|
19
36
|
parameters: {
|
|
20
|
-
|
|
37
|
+
controls: { expanded: true },
|
|
38
|
+
docs: { source: { state: 'open' } },
|
|
21
39
|
},
|
|
22
40
|
};
|
|
41
|
+
export default meta;
|
|
23
42
|
|
|
24
|
-
const
|
|
25
|
-
const [ color, setColor ] = useState( '#
|
|
26
|
-
return <ColorPalette { ...
|
|
43
|
+
const Template = ( args ) => {
|
|
44
|
+
const [ color, setColor ] = useState( '#f00' );
|
|
45
|
+
return <ColorPalette { ...args } value={ color } onChange={ setColor } />;
|
|
27
46
|
};
|
|
28
47
|
|
|
29
|
-
export const
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
{ name: '
|
|
33
|
-
{ name: '
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
return <ColorPaletteWithState colors={ colors } />;
|
|
48
|
+
export const Default = Template.bind( {} );
|
|
49
|
+
Default.args = {
|
|
50
|
+
colors: [
|
|
51
|
+
{ name: 'Red', color: '#f00' },
|
|
52
|
+
{ name: 'White', color: '#fff' },
|
|
53
|
+
{ name: 'Blue', color: '#00f' },
|
|
54
|
+
],
|
|
37
55
|
};
|
|
38
56
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
57
|
+
/**
|
|
58
|
+
* When setting the `__experimentalHasMultipleOrigins` prop to `true`,
|
|
59
|
+
* the `colors` prop is expected to be an array of color palettes, rather
|
|
60
|
+
* than an array of color objects.
|
|
61
|
+
*/
|
|
62
|
+
export const MultipleOrigins = Template.bind( {} );
|
|
63
|
+
MultipleOrigins.args = {
|
|
64
|
+
__experimentalHasMultipleOrigins: true,
|
|
65
|
+
colors: [
|
|
66
|
+
{
|
|
67
|
+
name: 'Primary colors',
|
|
68
|
+
colors: [
|
|
69
|
+
{ name: 'Red', color: '#f00' },
|
|
70
|
+
{ name: 'Yellow', color: '#ff0' },
|
|
71
|
+
{ name: 'Blue', color: '#00f' },
|
|
72
|
+
],
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
name: 'Primary colors',
|
|
76
|
+
colors: [
|
|
77
|
+
{ name: 'Orange', color: '#f60' },
|
|
78
|
+
{ name: 'Green', color: '#0f0' },
|
|
79
|
+
{ name: 'Purple', color: '#60f' },
|
|
80
|
+
],
|
|
81
|
+
},
|
|
82
|
+
],
|
|
47
83
|
};
|
|
@@ -2,11 +2,10 @@
|
|
|
2
2
|
position: relative;
|
|
3
3
|
border: none;
|
|
4
4
|
background: none;
|
|
5
|
-
display: block;
|
|
6
5
|
border-radius: $radius-block-ui;
|
|
7
|
-
height: $grid-unit-
|
|
6
|
+
height: $grid-unit-80;
|
|
7
|
+
padding: $grid-unit-15;
|
|
8
8
|
font-family: inherit;
|
|
9
|
-
text-align: right;
|
|
10
9
|
width: 100%;
|
|
11
10
|
background-image:
|
|
12
11
|
repeating-linear-gradient(45deg, $gray-200 25%, transparent 25%, transparent 75%, $gray-200 75%, $gray-200),
|
|
@@ -55,3 +54,12 @@
|
|
|
55
54
|
}
|
|
56
55
|
}
|
|
57
56
|
}
|
|
57
|
+
|
|
58
|
+
.components-color-palette__custom-color-name {
|
|
59
|
+
text-align: left;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
.components-color-palette__custom-color-value {
|
|
63
|
+
margin-left: $grid-unit-20;
|
|
64
|
+
text-transform: uppercase;
|
|
65
|
+
}
|