@wordpress/components 25.15.1-next.79a6196f.0 → 25.16.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 +27 -2
- package/build/border-box-control/border-box-control/component.js.map +1 -1
- package/build/border-box-control/border-box-control/hook.js +3 -1
- package/build/border-box-control/border-box-control/hook.js.map +1 -1
- package/build/border-box-control/types.js.map +1 -1
- package/build/border-control/border-control/component.js +5 -1
- package/build/border-control/border-control/component.js.map +1 -1
- package/build/border-control/border-control/hook.js +18 -15
- package/build/border-control/border-control/hook.js.map +1 -1
- package/build/border-control/border-control-dropdown/component.js +2 -1
- package/build/border-control/border-control-dropdown/component.js.map +1 -1
- package/build/border-control/border-control-style-picker/component.js +21 -49
- package/build/border-control/border-control-style-picker/component.js.map +1 -1
- package/build/border-control/styles.js +15 -27
- package/build/border-control/styles.js.map +1 -1
- package/build/border-control/types.js.map +1 -1
- package/build/box-control/all-input-control.js +35 -29
- package/build/box-control/all-input-control.js.map +1 -1
- package/build/box-control/axial-input-controls.js +40 -54
- package/build/box-control/axial-input-controls.js.map +1 -1
- package/build/box-control/index.js +21 -24
- package/build/box-control/index.js.map +1 -1
- package/build/box-control/input-controls.js +45 -37
- package/build/box-control/input-controls.js.map +1 -1
- package/build/box-control/styles/box-control-styles.js +50 -112
- package/build/box-control/styles/box-control-styles.js.map +1 -1
- package/build/box-control/types.js.map +1 -1
- package/build/box-control/utils.js +123 -8
- package/build/box-control/utils.js.map +1 -1
- package/build/button/index.js +14 -16
- package/build/button/index.js.map +1 -1
- package/build/button/types.js.map +1 -1
- package/build/color-picker/hsl-input.js +55 -33
- package/build/color-picker/hsl-input.js.map +1 -1
- package/build/custom-select-control-v2/index.js +3 -2
- package/build/custom-select-control-v2/index.js.map +1 -1
- package/build/slot-fill/bubbles-virtually/use-slot-fills.js +1 -1
- package/build/slot-fill/bubbles-virtually/use-slot-fills.js.map +1 -1
- package/build/theme/styles.js +11 -6
- package/build/theme/styles.js.map +1 -1
- package/build/toggle-group-control/toggle-group-control/utils.js +7 -1
- package/build/toggle-group-control/toggle-group-control/utils.js.map +1 -1
- package/build/tooltip/index.js +15 -12
- package/build/tooltip/index.js.map +1 -1
- package/build/tooltip/types.js.map +1 -1
- package/build-module/border-box-control/border-box-control/component.js.map +1 -1
- package/build-module/border-box-control/border-box-control/hook.js +3 -1
- package/build-module/border-box-control/border-box-control/hook.js.map +1 -1
- package/build-module/border-box-control/types.js.map +1 -1
- package/build-module/border-control/border-control/component.js +5 -1
- package/build-module/border-control/border-control/component.js.map +1 -1
- package/build-module/border-control/border-control/hook.js +18 -15
- package/build-module/border-control/border-control/hook.js.map +1 -1
- package/build-module/border-control/border-control-dropdown/component.js +2 -1
- package/build-module/border-control/border-control-dropdown/component.js.map +1 -1
- package/build-module/border-control/border-control-style-picker/component.js +21 -48
- package/build-module/border-control/border-control-style-picker/component.js.map +1 -1
- package/build-module/border-control/styles.js +14 -24
- package/build-module/border-control/styles.js.map +1 -1
- package/build-module/border-control/types.js.map +1 -1
- package/build-module/box-control/all-input-control.js +38 -28
- package/build-module/box-control/all-input-control.js.map +1 -1
- package/build-module/box-control/axial-input-controls.js +42 -57
- package/build-module/box-control/axial-input-controls.js.map +1 -1
- package/build-module/box-control/index.js +22 -25
- package/build-module/box-control/index.js.map +1 -1
- package/build-module/box-control/input-controls.js +47 -40
- package/build-module/box-control/input-controls.js.map +1 -1
- package/build-module/box-control/styles/box-control-styles.js +45 -105
- package/build-module/box-control/styles/box-control-styles.js.map +1 -1
- package/build-module/box-control/types.js.map +1 -1
- package/build-module/box-control/utils.js +121 -7
- package/build-module/box-control/utils.js.map +1 -1
- package/build-module/button/index.js +14 -16
- package/build-module/button/index.js.map +1 -1
- package/build-module/button/types.js.map +1 -1
- package/build-module/color-picker/hsl-input.js +55 -33
- package/build-module/color-picker/hsl-input.js.map +1 -1
- package/build-module/custom-select-control-v2/index.js +3 -2
- package/build-module/custom-select-control-v2/index.js.map +1 -1
- package/build-module/slot-fill/bubbles-virtually/use-slot-fills.js +1 -1
- package/build-module/slot-fill/bubbles-virtually/use-slot-fills.js.map +1 -1
- package/build-module/theme/styles.js +11 -2
- package/build-module/theme/styles.js.map +1 -1
- package/build-module/toggle-group-control/toggle-group-control/utils.js +7 -1
- package/build-module/toggle-group-control/toggle-group-control/utils.js.map +1 -1
- package/build-module/tooltip/index.js +16 -13
- package/build-module/tooltip/index.js.map +1 -1
- package/build-module/tooltip/types.js.map +1 -1
- package/build-style/style-rtl.css +6 -4
- package/build-style/style.css +6 -4
- package/build-types/border-box-control/border-box-control/component.d.ts +1 -0
- package/build-types/border-box-control/border-box-control/component.d.ts.map +1 -1
- package/build-types/border-box-control/border-box-control/hook.d.ts +4 -4
- package/build-types/border-box-control/border-box-control/hook.d.ts.map +1 -1
- package/build-types/border-box-control/border-box-control-linked-button/hook.d.ts +5 -5
- package/build-types/border-box-control/border-box-control-split-controls/hook.d.ts +4 -4
- package/build-types/border-box-control/border-box-control-visualizer/hook.d.ts +4 -4
- package/build-types/border-box-control/stories/index.story.d.ts +2 -1
- package/build-types/border-box-control/stories/index.story.d.ts.map +1 -1
- package/build-types/border-box-control/types.d.ts +6 -0
- package/build-types/border-box-control/types.d.ts.map +1 -1
- package/build-types/border-control/border-control/component.d.ts +1 -0
- package/build-types/border-control/border-control/component.d.ts.map +1 -1
- package/build-types/border-control/border-control/hook.d.ts +6 -4
- package/build-types/border-control/border-control/hook.d.ts.map +1 -1
- package/build-types/border-control/border-control-dropdown/component.d.ts +1 -0
- package/build-types/border-control/border-control-dropdown/component.d.ts.map +1 -1
- package/build-types/border-control/border-control-dropdown/hook.d.ts +5 -4
- package/build-types/border-control/border-control-dropdown/hook.d.ts.map +1 -1
- package/build-types/border-control/border-control-style-picker/component.d.ts +3 -4
- package/build-types/border-control/border-control-style-picker/component.d.ts.map +1 -1
- package/build-types/border-control/stories/index.story.d.ts +12 -6
- package/build-types/border-control/stories/index.story.d.ts.map +1 -1
- package/build-types/border-control/styles.d.ts +0 -2
- package/build-types/border-control/styles.d.ts.map +1 -1
- package/build-types/border-control/types.d.ts +12 -1
- package/build-types/border-control/types.d.ts.map +1 -1
- package/build-types/box-control/all-input-control.d.ts +1 -1
- package/build-types/box-control/all-input-control.d.ts.map +1 -1
- package/build-types/box-control/axial-input-controls.d.ts +1 -1
- package/build-types/box-control/axial-input-controls.d.ts.map +1 -1
- package/build-types/box-control/index.d.ts +1 -1
- package/build-types/box-control/index.d.ts.map +1 -1
- package/build-types/box-control/input-controls.d.ts +1 -1
- package/build-types/box-control/input-controls.d.ts.map +1 -1
- package/build-types/box-control/stories/index.story.d.ts +42 -36
- package/build-types/box-control/stories/index.story.d.ts.map +1 -1
- package/build-types/box-control/styles/box-control-styles.d.ts +49 -23
- package/build-types/box-control/styles/box-control-styles.d.ts.map +1 -1
- package/build-types/box-control/types.d.ts +12 -12
- package/build-types/box-control/types.d.ts.map +1 -1
- package/build-types/box-control/utils.d.ts +2 -1
- package/build-types/box-control/utils.d.ts.map +1 -1
- package/build-types/button/deprecated.d.ts +3 -3
- package/build-types/button/index.d.ts.map +1 -1
- package/build-types/button/types.d.ts +7 -3
- package/build-types/button/types.d.ts.map +1 -1
- package/build-types/card/card/hook.d.ts +4 -4
- package/build-types/card/card-body/hook.d.ts +4 -4
- package/build-types/card/card-divider/hook.d.ts +4 -4
- package/build-types/card/card-footer/hook.d.ts +4 -4
- package/build-types/card/card-header/hook.d.ts +4 -4
- package/build-types/card/card-media/hook.d.ts +4 -4
- package/build-types/color-palette/styles.d.ts +2 -2
- package/build-types/color-picker/component.d.ts +1 -1
- package/build-types/color-picker/hsl-input.d.ts.map +1 -1
- package/build-types/color-picker/stories/index.story.d.ts +1 -1
- package/build-types/color-picker/styles.d.ts +3 -3
- package/build-types/custom-select-control-v2/index.d.ts.map +1 -1
- package/build-types/date-time/date/styles.d.ts +3 -3
- package/build-types/date-time/date-time/styles.d.ts +1 -1
- package/build-types/date-time/time/styles.d.ts +4 -4
- package/build-types/elevation/hook.d.ts +4 -4
- package/build-types/flex/flex/hook.d.ts +4 -4
- package/build-types/flex/flex-block/hook.d.ts +4 -4
- package/build-types/flex/flex-item/hook.d.ts +4 -4
- package/build-types/focal-point-picker/styles/focal-point-picker-style.d.ts +1 -1
- package/build-types/font-size-picker/styles.d.ts +1 -1
- package/build-types/grid/hook.d.ts +4 -4
- package/build-types/h-stack/hook.d.ts +4 -4
- package/build-types/heading/component.d.ts +1 -1
- package/build-types/heading/hook.d.ts +4 -4
- package/build-types/item-group/item/hook.d.ts +4 -4
- package/build-types/item-group/item-group/hook.d.ts +4 -4
- package/build-types/menu-item/index.d.ts +1 -1
- package/build-types/menu-item/stories/index.story.d.ts +4 -4
- package/build-types/navigation/styles/navigation-styles.d.ts +2 -2
- package/build-types/navigator/navigator-back-button/hook.d.ts +4 -4
- package/build-types/navigator/navigator-button/hook.d.ts +4 -4
- package/build-types/number-control/index.d.ts +1 -1
- package/build-types/number-control/stories/index.story.d.ts +1 -1
- package/build-types/palette-edit/styles.d.ts +3 -3
- package/build-types/range-control/index.d.ts +1 -1
- package/build-types/range-control/styles/range-control-styles.d.ts +1 -1
- package/build-types/resizable-box/index.d.ts +1 -1
- package/build-types/resizable-box/resize-tooltip/index.d.ts +1 -1
- package/build-types/resizable-box/stories/index.story.d.ts +2 -2
- package/build-types/scrollable/hook.d.ts +4 -4
- package/build-types/spacer/hook.d.ts +4 -4
- package/build-types/surface/hook.d.ts +4 -4
- package/build-types/text/hook.d.ts +4 -4
- package/build-types/theme/styles.d.ts.map +1 -1
- package/build-types/toggle-control/stories/index.story.d.ts +2 -2
- package/build-types/toggle-group-control/toggle-group-control/utils.d.ts.map +1 -1
- package/build-types/toggle-group-control/toggle-group-control-option-icon/component.d.ts +1 -1
- package/build-types/toolbar/toolbar-button/index.d.ts +3 -3
- package/build-types/tools-panel/tools-panel/hook.d.ts +4 -4
- package/build-types/tools-panel/tools-panel-header/hook.d.ts +4 -4
- package/build-types/tools-panel/tools-panel-item/hook.d.ts +4 -4
- package/build-types/tooltip/index.d.ts +1 -1
- package/build-types/tooltip/index.d.ts.map +1 -1
- package/build-types/tooltip/stories/index.story.d.ts +1 -1
- package/build-types/tooltip/stories/index.story.d.ts.map +1 -1
- package/build-types/tooltip/types.d.ts +1 -1
- package/build-types/tooltip/types.d.ts.map +1 -1
- package/build-types/truncate/hook.d.ts +4 -4
- package/build-types/unit-control/index.d.ts +1 -1
- package/build-types/unit-control/styles/unit-control-styles.d.ts +1 -1
- package/build-types/v-stack/hook.d.ts +4 -4
- package/build-types/v-stack/stories/index.story.d.ts +1 -1
- package/package.json +19 -19
- package/src/border-box-control/border-box-control/component.tsx +0 -1
- package/src/border-box-control/border-box-control/hook.ts +5 -1
- package/src/border-box-control/types.ts +6 -0
- package/src/border-control/border-control/component.tsx +4 -0
- package/src/border-control/border-control/hook.ts +22 -16
- package/src/border-control/border-control-dropdown/component.tsx +2 -1
- package/src/border-control/border-control-style-picker/component.tsx +31 -66
- package/src/border-control/styles.ts +0 -15
- package/src/border-control/types.ts +15 -1
- package/src/box-control/all-input-control.tsx +57 -34
- package/src/box-control/axial-input-controls.tsx +79 -69
- package/src/box-control/index.tsx +47 -54
- package/src/box-control/input-controls.tsx +114 -83
- package/src/box-control/styles/box-control-styles.ts +21 -61
- package/src/box-control/test/index.tsx +126 -18
- package/src/box-control/types.ts +10 -21
- package/src/box-control/utils.ts +43 -8
- package/src/button/README.md +1 -1
- package/src/button/index.tsx +21 -33
- package/src/button/test/index.tsx +122 -0
- package/src/button/types.ts +7 -3
- package/src/circular-option-picker/test/index.tsx +10 -16
- package/src/color-picker/hsl-input.tsx +56 -30
- package/src/color-picker/test/index.tsx +190 -16
- package/src/custom-select-control-v2/index.tsx +5 -2
- package/src/palette-edit/test/index.tsx +326 -10
- package/src/slot-fill/bubbles-virtually/use-slot-fills.ts +1 -1
- package/src/tabs/test/index.tsx +3 -1
- package/src/theme/styles.ts +3 -1
- package/src/toggle-group-control/test/__snapshots__/index.tsx.snap +6 -6
- package/src/toggle-group-control/test/index.tsx +73 -36
- package/src/toggle-group-control/toggle-group-control/utils.ts +8 -3
- package/src/tooltip/index.tsx +29 -29
- package/src/tooltip/test/index.tsx +32 -13
- package/src/tooltip/types.ts +1 -1
- package/tsconfig.tsbuildinfo +1 -1
- package/build/border-control/border-control-style-picker/hook.js +0 -41
- package/build/border-control/border-control-style-picker/hook.js.map +0 -1
- package/build/box-control/styles/box-control-visualizer-styles.js +0 -93
- package/build/box-control/styles/box-control-visualizer-styles.js.map +0 -1
- package/build/box-control/unit-control.js +0 -76
- package/build/box-control/unit-control.js.map +0 -1
- package/build-module/border-control/border-control-style-picker/hook.js +0 -32
- package/build-module/border-control/border-control-style-picker/hook.js.map +0 -1
- package/build-module/box-control/styles/box-control-visualizer-styles.js +0 -86
- package/build-module/box-control/styles/box-control-visualizer-styles.js.map +0 -1
- package/build-module/box-control/unit-control.js +0 -68
- package/build-module/box-control/unit-control.js.map +0 -1
- package/build-types/border-control/border-control-style-picker/hook.d.ts +0 -267
- package/build-types/border-control/border-control-style-picker/hook.d.ts.map +0 -1
- package/build-types/box-control/styles/box-control-visualizer-styles.d.ts +0 -46
- package/build-types/box-control/styles/box-control-visualizer-styles.d.ts.map +0 -1
- package/build-types/box-control/unit-control.d.ts +0 -4
- package/build-types/box-control/unit-control.d.ts.map +0 -1
- package/src/border-control/border-control-style-picker/hook.ts +0 -35
- package/src/box-control/styles/box-control-visualizer-styles.ts +0 -75
- package/src/box-control/unit-control.tsx +0 -74
|
@@ -1,26 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { useInstanceId } from '@wordpress/compose';
|
|
1
5
|
/**
|
|
2
6
|
* Internal dependencies
|
|
3
7
|
*/
|
|
4
8
|
import { parseQuantityAndUnitFromRawValue } from '../unit-control/utils';
|
|
5
|
-
import
|
|
6
|
-
import { LABELS } from './utils';
|
|
7
|
-
import {
|
|
9
|
+
import Tooltip from '../tooltip';
|
|
10
|
+
import { CUSTOM_VALUE_SETTINGS, LABELS } from './utils';
|
|
11
|
+
import {
|
|
12
|
+
FlexedBoxControlIcon,
|
|
13
|
+
FlexedRangeControl,
|
|
14
|
+
InputWrapper,
|
|
15
|
+
StyledUnitControl,
|
|
16
|
+
} from './styles/box-control-styles';
|
|
8
17
|
import type { BoxControlInputControlProps } from './types';
|
|
9
18
|
|
|
10
19
|
const groupedSides = [ 'vertical', 'horizontal' ] as const;
|
|
11
20
|
type GroupedSide = ( typeof groupedSides )[ number ];
|
|
12
21
|
|
|
13
22
|
export default function AxialInputControls( {
|
|
23
|
+
__next40pxDefaultSize,
|
|
14
24
|
onChange,
|
|
15
25
|
onFocus,
|
|
16
|
-
onHoverOn,
|
|
17
|
-
onHoverOff,
|
|
18
26
|
values,
|
|
19
27
|
selectedUnits,
|
|
20
28
|
setSelectedUnits,
|
|
21
29
|
sides,
|
|
22
30
|
...props
|
|
23
31
|
}: BoxControlInputControlProps ) {
|
|
32
|
+
const generatedId = useInstanceId(
|
|
33
|
+
AxialInputControls,
|
|
34
|
+
`box-control-input`
|
|
35
|
+
);
|
|
36
|
+
|
|
24
37
|
const createHandleOnFocus =
|
|
25
38
|
( side: GroupedSide ) =>
|
|
26
39
|
( event: React.FocusEvent< HTMLInputElement > ) => {
|
|
@@ -30,43 +43,7 @@ export default function AxialInputControls( {
|
|
|
30
43
|
onFocus( event, { side } );
|
|
31
44
|
};
|
|
32
45
|
|
|
33
|
-
const
|
|
34
|
-
if ( ! onHoverOn ) {
|
|
35
|
-
return;
|
|
36
|
-
}
|
|
37
|
-
if ( side === 'vertical' ) {
|
|
38
|
-
onHoverOn( {
|
|
39
|
-
top: true,
|
|
40
|
-
bottom: true,
|
|
41
|
-
} );
|
|
42
|
-
}
|
|
43
|
-
if ( side === 'horizontal' ) {
|
|
44
|
-
onHoverOn( {
|
|
45
|
-
left: true,
|
|
46
|
-
right: true,
|
|
47
|
-
} );
|
|
48
|
-
}
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
const createHandleOnHoverOff = ( side: GroupedSide ) => () => {
|
|
52
|
-
if ( ! onHoverOff ) {
|
|
53
|
-
return;
|
|
54
|
-
}
|
|
55
|
-
if ( side === 'vertical' ) {
|
|
56
|
-
onHoverOff( {
|
|
57
|
-
top: false,
|
|
58
|
-
bottom: false,
|
|
59
|
-
} );
|
|
60
|
-
}
|
|
61
|
-
if ( side === 'horizontal' ) {
|
|
62
|
-
onHoverOff( {
|
|
63
|
-
left: false,
|
|
64
|
-
right: false,
|
|
65
|
-
} );
|
|
66
|
-
}
|
|
67
|
-
};
|
|
68
|
-
|
|
69
|
-
const createHandleOnChange = ( side: GroupedSide ) => ( next?: string ) => {
|
|
46
|
+
const handleOnValueChange = ( side: GroupedSide, next?: string ) => {
|
|
70
47
|
if ( ! onChange ) {
|
|
71
48
|
return;
|
|
72
49
|
}
|
|
@@ -109,16 +86,8 @@ export default function AxialInputControls( {
|
|
|
109
86
|
? groupedSides.filter( ( side ) => sides.includes( side ) )
|
|
110
87
|
: groupedSides;
|
|
111
88
|
|
|
112
|
-
const first = filteredSides[ 0 ];
|
|
113
|
-
const last = filteredSides[ filteredSides.length - 1 ];
|
|
114
|
-
const only = first === last && first;
|
|
115
|
-
|
|
116
89
|
return (
|
|
117
|
-
|
|
118
|
-
gap={ 0 }
|
|
119
|
-
align="top"
|
|
120
|
-
className="component-box-control__vertical-horizontal-input-controls"
|
|
121
|
-
>
|
|
90
|
+
<>
|
|
122
91
|
{ filteredSides.map( ( side ) => {
|
|
123
92
|
const [ parsedQuantity, parsedUnit ] =
|
|
124
93
|
parseQuantityAndUnitFromRawValue(
|
|
@@ -128,26 +97,67 @@ export default function AxialInputControls( {
|
|
|
128
97
|
side === 'vertical'
|
|
129
98
|
? selectedUnits.top
|
|
130
99
|
: selectedUnits.left;
|
|
100
|
+
|
|
101
|
+
const inputId = [ generatedId, side ].join( '-' );
|
|
102
|
+
|
|
131
103
|
return (
|
|
132
|
-
<
|
|
133
|
-
{
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
104
|
+
<InputWrapper key={ side }>
|
|
105
|
+
<FlexedBoxControlIcon side={ side } sides={ sides } />
|
|
106
|
+
<Tooltip placement="top-end" text={ LABELS[ side ] }>
|
|
107
|
+
<StyledUnitControl
|
|
108
|
+
{ ...props }
|
|
109
|
+
__next40pxDefaultSize={ __next40pxDefaultSize }
|
|
110
|
+
className="component-box-control__unit-control"
|
|
111
|
+
id={ inputId }
|
|
112
|
+
isPressEnterToChange
|
|
113
|
+
value={ [
|
|
114
|
+
parsedQuantity,
|
|
115
|
+
selectedUnit ?? parsedUnit,
|
|
116
|
+
].join( '' ) }
|
|
117
|
+
onChange={ ( newValue ) =>
|
|
118
|
+
handleOnValueChange( side, newValue )
|
|
119
|
+
}
|
|
120
|
+
onUnitChange={ createHandleOnUnitChange(
|
|
121
|
+
side
|
|
122
|
+
) }
|
|
123
|
+
onFocus={ createHandleOnFocus( side ) }
|
|
124
|
+
label={ LABELS[ side ] }
|
|
125
|
+
hideLabelFromVision
|
|
126
|
+
key={ side }
|
|
127
|
+
/>
|
|
128
|
+
</Tooltip>
|
|
129
|
+
<FlexedRangeControl
|
|
130
|
+
__nextHasNoMarginBottom
|
|
131
|
+
__next40pxDefaultSize={ __next40pxDefaultSize }
|
|
132
|
+
aria-controls={ inputId }
|
|
133
|
+
label={ LABELS[ side ] }
|
|
134
|
+
hideLabelFromVision
|
|
135
|
+
onChange={ ( newValue ) =>
|
|
136
|
+
handleOnValueChange(
|
|
137
|
+
side,
|
|
138
|
+
newValue !== undefined
|
|
139
|
+
? [
|
|
140
|
+
newValue,
|
|
141
|
+
selectedUnit ?? parsedUnit,
|
|
142
|
+
].join( '' )
|
|
143
|
+
: undefined
|
|
144
|
+
)
|
|
145
|
+
}
|
|
146
|
+
min={ 0 }
|
|
147
|
+
max={
|
|
148
|
+
CUSTOM_VALUE_SETTINGS[ selectedUnit ?? 'px' ]
|
|
149
|
+
?.max ?? 10
|
|
150
|
+
}
|
|
151
|
+
step={
|
|
152
|
+
CUSTOM_VALUE_SETTINGS[ selectedUnit ?? 'px' ]
|
|
153
|
+
?.step ?? 0.1
|
|
154
|
+
}
|
|
155
|
+
value={ parsedQuantity ?? 0 }
|
|
156
|
+
withInputField={ false }
|
|
157
|
+
/>
|
|
158
|
+
</InputWrapper>
|
|
149
159
|
);
|
|
150
160
|
} ) }
|
|
151
|
-
|
|
161
|
+
</>
|
|
152
162
|
);
|
|
153
163
|
}
|
|
@@ -9,17 +9,16 @@ import { __ } from '@wordpress/i18n';
|
|
|
9
9
|
* Internal dependencies
|
|
10
10
|
*/
|
|
11
11
|
import { BaseControl } from '../base-control';
|
|
12
|
-
import Button from '../button';
|
|
13
|
-
import { FlexItem, FlexBlock } from '../flex';
|
|
14
12
|
import AllInputControl from './all-input-control';
|
|
15
13
|
import InputControls from './input-controls';
|
|
16
14
|
import AxialInputControls from './axial-input-controls';
|
|
17
|
-
import BoxControlIcon from './icon';
|
|
18
15
|
import LinkedButton from './linked-button';
|
|
16
|
+
import { Grid } from '../grid';
|
|
19
17
|
import {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
18
|
+
FlexedBoxControlIcon,
|
|
19
|
+
InputWrapper,
|
|
20
|
+
ResetButton,
|
|
21
|
+
LinkedButtonWrapper,
|
|
23
22
|
} from './styles/box-control-styles';
|
|
24
23
|
import { parseQuantityAndUnitFromRawValue } from '../unit-control/utils';
|
|
25
24
|
import {
|
|
@@ -73,6 +72,7 @@ function useUniqueId( idProp?: string ) {
|
|
|
73
72
|
* ```
|
|
74
73
|
*/
|
|
75
74
|
function BoxControl( {
|
|
75
|
+
__next40pxDefaultSize = false,
|
|
76
76
|
id: idProp,
|
|
77
77
|
inputProps = defaultInputProps,
|
|
78
78
|
onChange = noop,
|
|
@@ -152,60 +152,53 @@ function BoxControl( {
|
|
|
152
152
|
values: inputValues,
|
|
153
153
|
onMouseOver,
|
|
154
154
|
onMouseOut,
|
|
155
|
+
__next40pxDefaultSize,
|
|
155
156
|
};
|
|
156
157
|
|
|
157
158
|
return (
|
|
158
|
-
<
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
aria-label={ label }
|
|
187
|
-
{ ...inputControlProps }
|
|
188
|
-
/>
|
|
189
|
-
</FlexBlock>
|
|
190
|
-
) }
|
|
191
|
-
{ ! isLinked && splitOnAxis && (
|
|
192
|
-
<FlexBlock>
|
|
193
|
-
<AxialInputControls { ...inputControlProps } />
|
|
194
|
-
</FlexBlock>
|
|
195
|
-
) }
|
|
196
|
-
{ ! hasOneSide && (
|
|
197
|
-
<FlexItem>
|
|
198
|
-
<LinkedButton
|
|
199
|
-
onClick={ toggleLinked }
|
|
200
|
-
isLinked={ isLinked }
|
|
201
|
-
/>
|
|
202
|
-
</FlexItem>
|
|
203
|
-
) }
|
|
204
|
-
</HeaderControlWrapper>
|
|
159
|
+
<Grid
|
|
160
|
+
id={ id }
|
|
161
|
+
columns={ 3 }
|
|
162
|
+
templateColumns="1fr min-content min-content"
|
|
163
|
+
role="group"
|
|
164
|
+
aria-labelledby={ headingId }
|
|
165
|
+
>
|
|
166
|
+
<BaseControl.VisualLabel id={ headingId }>
|
|
167
|
+
{ label }
|
|
168
|
+
</BaseControl.VisualLabel>
|
|
169
|
+
{ isLinked && (
|
|
170
|
+
<InputWrapper>
|
|
171
|
+
<FlexedBoxControlIcon side={ side } sides={ sides } />
|
|
172
|
+
<AllInputControl { ...inputControlProps } />
|
|
173
|
+
</InputWrapper>
|
|
174
|
+
) }
|
|
175
|
+
{ ! hasOneSide && (
|
|
176
|
+
<LinkedButtonWrapper>
|
|
177
|
+
<LinkedButton
|
|
178
|
+
onClick={ toggleLinked }
|
|
179
|
+
isLinked={ isLinked }
|
|
180
|
+
/>
|
|
181
|
+
</LinkedButtonWrapper>
|
|
182
|
+
) }
|
|
183
|
+
|
|
184
|
+
{ ! isLinked && splitOnAxis && (
|
|
185
|
+
<AxialInputControls { ...inputControlProps } />
|
|
186
|
+
) }
|
|
205
187
|
{ ! isLinked && ! splitOnAxis && (
|
|
206
188
|
<InputControls { ...inputControlProps } />
|
|
207
189
|
) }
|
|
208
|
-
|
|
190
|
+
{ allowReset && (
|
|
191
|
+
<ResetButton
|
|
192
|
+
className="component-box-control__reset-button"
|
|
193
|
+
variant="secondary"
|
|
194
|
+
size="small"
|
|
195
|
+
onClick={ handleOnReset }
|
|
196
|
+
disabled={ ! isDirty }
|
|
197
|
+
>
|
|
198
|
+
{ __( 'Reset' ) }
|
|
199
|
+
</ResetButton>
|
|
200
|
+
) }
|
|
201
|
+
</Grid>
|
|
209
202
|
);
|
|
210
203
|
}
|
|
211
204
|
|
|
@@ -1,82 +1,82 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { useInstanceId } from '@wordpress/compose';
|
|
1
5
|
/**
|
|
2
6
|
* Internal dependencies
|
|
3
7
|
*/
|
|
4
|
-
import
|
|
8
|
+
import Tooltip from '../tooltip';
|
|
5
9
|
import { parseQuantityAndUnitFromRawValue } from '../unit-control/utils';
|
|
6
|
-
import { ALL_SIDES, LABELS } from './utils';
|
|
7
|
-
import {
|
|
10
|
+
import { ALL_SIDES, CUSTOM_VALUE_SETTINGS, LABELS } from './utils';
|
|
11
|
+
import {
|
|
12
|
+
FlexedBoxControlIcon,
|
|
13
|
+
FlexedRangeControl,
|
|
14
|
+
InputWrapper,
|
|
15
|
+
StyledUnitControl,
|
|
16
|
+
} from './styles/box-control-styles';
|
|
8
17
|
import type { BoxControlInputControlProps, BoxControlValue } from './types';
|
|
9
|
-
import type { UnitControlProps } from '../unit-control/types';
|
|
10
18
|
|
|
11
19
|
const noop = () => {};
|
|
12
20
|
|
|
13
21
|
export default function BoxInputControls( {
|
|
22
|
+
__next40pxDefaultSize,
|
|
14
23
|
onChange = noop,
|
|
15
24
|
onFocus = noop,
|
|
16
|
-
onHoverOn = noop,
|
|
17
|
-
onHoverOff = noop,
|
|
18
25
|
values,
|
|
19
26
|
selectedUnits,
|
|
20
27
|
setSelectedUnits,
|
|
21
28
|
sides,
|
|
22
29
|
...props
|
|
23
30
|
}: BoxControlInputControlProps ) {
|
|
31
|
+
const generatedId = useInstanceId( BoxInputControls, 'box-control-input' );
|
|
32
|
+
|
|
24
33
|
const createHandleOnFocus =
|
|
25
34
|
( side: keyof BoxControlValue ) =>
|
|
26
35
|
( event: React.FocusEvent< HTMLInputElement > ) => {
|
|
27
36
|
onFocus( event, { side } );
|
|
28
37
|
};
|
|
29
38
|
|
|
30
|
-
const createHandleOnHoverOn = ( side: keyof BoxControlValue ) => () => {
|
|
31
|
-
onHoverOn( { [ side ]: true } );
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
const createHandleOnHoverOff = ( side: keyof BoxControlValue ) => () => {
|
|
35
|
-
onHoverOff( { [ side ]: false } );
|
|
36
|
-
};
|
|
37
|
-
|
|
38
39
|
const handleOnChange = ( nextValues: BoxControlValue ) => {
|
|
39
40
|
onChange( nextValues );
|
|
40
41
|
};
|
|
41
42
|
|
|
42
|
-
const
|
|
43
|
-
side: keyof BoxControlValue
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
const nextValue = isNumeric ? next : undefined;
|
|
43
|
+
const handleOnValueChange = (
|
|
44
|
+
side: keyof BoxControlValue,
|
|
45
|
+
next?: string,
|
|
46
|
+
extra?: { event: React.SyntheticEvent< Element, Event > }
|
|
47
|
+
) => {
|
|
48
|
+
const nextValues = { ...values };
|
|
49
|
+
const isNumeric = next !== undefined && ! isNaN( parseFloat( next ) );
|
|
50
|
+
const nextValue = isNumeric ? next : undefined;
|
|
51
51
|
|
|
52
|
-
|
|
52
|
+
nextValues[ side ] = nextValue;
|
|
53
53
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
}
|
|
54
|
+
/**
|
|
55
|
+
* Supports changing pair sides. For example, holding the ALT key
|
|
56
|
+
* when changing the TOP will also update BOTTOM.
|
|
57
|
+
*/
|
|
58
|
+
// @ts-expect-error - TODO: event.altKey is only present when the change event was
|
|
59
|
+
// triggered by a keyboard event. Should this feature be implemented differently so
|
|
60
|
+
// it also works with drag events?
|
|
61
|
+
if ( extra?.event.altKey ) {
|
|
62
|
+
switch ( side ) {
|
|
63
|
+
case 'top':
|
|
64
|
+
nextValues.bottom = nextValue;
|
|
65
|
+
break;
|
|
66
|
+
case 'bottom':
|
|
67
|
+
nextValues.top = nextValue;
|
|
68
|
+
break;
|
|
69
|
+
case 'left':
|
|
70
|
+
nextValues.right = nextValue;
|
|
71
|
+
break;
|
|
72
|
+
case 'right':
|
|
73
|
+
nextValues.left = nextValue;
|
|
74
|
+
break;
|
|
76
75
|
}
|
|
76
|
+
}
|
|
77
77
|
|
|
78
|
-
|
|
79
|
-
|
|
78
|
+
handleOnChange( nextValues );
|
|
79
|
+
};
|
|
80
80
|
|
|
81
81
|
const createHandleOnUnitChange =
|
|
82
82
|
( side: keyof BoxControlValue ) => ( next?: string ) => {
|
|
@@ -90,45 +90,76 @@ export default function BoxInputControls( {
|
|
|
90
90
|
? ALL_SIDES.filter( ( side ) => sides.includes( side ) )
|
|
91
91
|
: ALL_SIDES;
|
|
92
92
|
|
|
93
|
-
const first = filteredSides[ 0 ];
|
|
94
|
-
const last = filteredSides[ filteredSides.length - 1 ];
|
|
95
|
-
const only = first === last && first;
|
|
96
|
-
|
|
97
93
|
return (
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
94
|
+
<>
|
|
95
|
+
{ filteredSides.map( ( side ) => {
|
|
96
|
+
const [ parsedQuantity, parsedUnit ] =
|
|
97
|
+
parseQuantityAndUnitFromRawValue( values[ side ] );
|
|
98
|
+
|
|
99
|
+
const computedUnit = values[ side ]
|
|
100
|
+
? parsedUnit
|
|
101
|
+
: selectedUnits[ side ];
|
|
102
|
+
|
|
103
|
+
const inputId = [ generatedId, side ].join( '-' );
|
|
107
104
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
105
|
+
return (
|
|
106
|
+
<InputWrapper key={ `box-control-${ side }` } expanded>
|
|
107
|
+
<FlexedBoxControlIcon side={ side } sides={ sides } />
|
|
108
|
+
<Tooltip placement="top-end" text={ LABELS[ side ] }>
|
|
109
|
+
<StyledUnitControl
|
|
110
|
+
{ ...props }
|
|
111
|
+
__next40pxDefaultSize={ __next40pxDefaultSize }
|
|
112
|
+
className="component-box-control__unit-control"
|
|
113
|
+
id={ inputId }
|
|
114
|
+
isPressEnterToChange
|
|
115
|
+
value={ [ parsedQuantity, computedUnit ].join(
|
|
116
|
+
''
|
|
117
|
+
) }
|
|
118
|
+
onChange={ ( nextValue, extra ) =>
|
|
119
|
+
handleOnValueChange(
|
|
120
|
+
side,
|
|
121
|
+
nextValue,
|
|
122
|
+
extra
|
|
123
|
+
)
|
|
124
|
+
}
|
|
125
|
+
onUnitChange={ createHandleOnUnitChange(
|
|
126
|
+
side
|
|
127
|
+
) }
|
|
128
|
+
onFocus={ createHandleOnFocus( side ) }
|
|
129
|
+
label={ LABELS[ side ] }
|
|
130
|
+
hideLabelFromVision
|
|
131
|
+
/>
|
|
132
|
+
</Tooltip>
|
|
111
133
|
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
{
|
|
115
|
-
|
|
116
|
-
isLast={ last === side }
|
|
117
|
-
isOnly={ only === side }
|
|
118
|
-
value={ [ parsedQuantity, computedUnit ].join(
|
|
119
|
-
''
|
|
120
|
-
) }
|
|
121
|
-
onChange={ createHandleOnChange( side ) }
|
|
122
|
-
onUnitChange={ createHandleOnUnitChange( side ) }
|
|
123
|
-
onFocus={ createHandleOnFocus( side ) }
|
|
124
|
-
onHoverOn={ createHandleOnHoverOn( side ) }
|
|
125
|
-
onHoverOff={ createHandleOnHoverOff( side ) }
|
|
134
|
+
<FlexedRangeControl
|
|
135
|
+
__nextHasNoMarginBottom
|
|
136
|
+
__next40pxDefaultSize={ __next40pxDefaultSize }
|
|
137
|
+
aria-controls={ inputId }
|
|
126
138
|
label={ LABELS[ side ] }
|
|
127
|
-
|
|
139
|
+
hideLabelFromVision
|
|
140
|
+
onChange={ ( newValue ) => {
|
|
141
|
+
handleOnValueChange(
|
|
142
|
+
side,
|
|
143
|
+
newValue !== undefined
|
|
144
|
+
? [ newValue, computedUnit ].join( '' )
|
|
145
|
+
: undefined
|
|
146
|
+
);
|
|
147
|
+
} }
|
|
148
|
+
min={ 0 }
|
|
149
|
+
max={
|
|
150
|
+
CUSTOM_VALUE_SETTINGS[ computedUnit ?? 'px' ]
|
|
151
|
+
?.max ?? 10
|
|
152
|
+
}
|
|
153
|
+
step={
|
|
154
|
+
CUSTOM_VALUE_SETTINGS[ computedUnit ?? 'px' ]
|
|
155
|
+
?.step ?? 0.1
|
|
156
|
+
}
|
|
157
|
+
value={ parsedQuantity ?? 0 }
|
|
158
|
+
withInputField={ false }
|
|
128
159
|
/>
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
160
|
+
</InputWrapper>
|
|
161
|
+
);
|
|
162
|
+
} ) }
|
|
163
|
+
</>
|
|
133
164
|
);
|
|
134
165
|
}
|
|
@@ -1,80 +1,40 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* External dependencies
|
|
3
3
|
*/
|
|
4
|
-
import { css } from '@emotion/react';
|
|
5
4
|
import styled from '@emotion/styled';
|
|
6
5
|
/**
|
|
7
6
|
* Internal dependencies
|
|
8
7
|
*/
|
|
9
|
-
import
|
|
10
|
-
import
|
|
11
|
-
import {
|
|
12
|
-
import
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
width: 100%;
|
|
8
|
+
import BoxControlIcon from '../icon';
|
|
9
|
+
import Button from '../../button';
|
|
10
|
+
import { HStack } from '../../h-stack';
|
|
11
|
+
import RangeControl from '../../range-control';
|
|
12
|
+
import UnitControl from '../../unit-control';
|
|
13
|
+
import { space } from '../../utils/space';
|
|
14
|
+
|
|
15
|
+
export const StyledUnitControl = styled( UnitControl )`
|
|
16
|
+
max-width: 90px;
|
|
19
17
|
`;
|
|
20
18
|
|
|
21
|
-
export const
|
|
22
|
-
|
|
19
|
+
export const InputWrapper = styled( HStack )`
|
|
20
|
+
grid-column: 1 / span 3;
|
|
23
21
|
`;
|
|
24
22
|
|
|
25
|
-
export const
|
|
26
|
-
|
|
27
|
-
|
|
23
|
+
export const ResetButton = styled( Button )`
|
|
24
|
+
grid-area: 1 / 2;
|
|
25
|
+
justify-self: end;
|
|
28
26
|
`;
|
|
29
27
|
|
|
30
|
-
export const
|
|
31
|
-
|
|
32
|
-
|
|
28
|
+
export const LinkedButtonWrapper = styled.div`
|
|
29
|
+
grid-area: 1 / 3;
|
|
30
|
+
justify-self: end;
|
|
33
31
|
`;
|
|
34
32
|
|
|
35
|
-
export const
|
|
36
|
-
|
|
37
|
-
padding-top: 8px;
|
|
33
|
+
export const FlexedBoxControlIcon = styled( BoxControlIcon )`
|
|
34
|
+
flex: 0 0 auto;
|
|
38
35
|
`;
|
|
39
36
|
|
|
40
|
-
export const
|
|
41
|
-
position: relative;
|
|
42
|
-
height: 100%;
|
|
37
|
+
export const FlexedRangeControl = styled( RangeControl )`
|
|
43
38
|
width: 100%;
|
|
44
|
-
|
|
45
|
-
`;
|
|
46
|
-
|
|
47
|
-
const unitControlBorderRadiusStyles = ( {
|
|
48
|
-
isFirst,
|
|
49
|
-
isLast,
|
|
50
|
-
isOnly,
|
|
51
|
-
}: Pick< BoxUnitControlProps, 'isFirst' | 'isLast' | 'isOnly' > ) => {
|
|
52
|
-
if ( isFirst ) {
|
|
53
|
-
return rtl( { borderTopRightRadius: 0, borderBottomRightRadius: 0 } )();
|
|
54
|
-
}
|
|
55
|
-
if ( isLast ) {
|
|
56
|
-
return rtl( { borderTopLeftRadius: 0, borderBottomLeftRadius: 0 } )();
|
|
57
|
-
}
|
|
58
|
-
if ( isOnly ) {
|
|
59
|
-
return css( { borderRadius: 2 } );
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
return css( {
|
|
63
|
-
borderRadius: 0,
|
|
64
|
-
} );
|
|
65
|
-
};
|
|
66
|
-
|
|
67
|
-
const unitControlMarginStyles = ( {
|
|
68
|
-
isFirst,
|
|
69
|
-
isOnly,
|
|
70
|
-
}: Pick< BoxUnitControlProps, 'isFirst' | 'isOnly' > ) => {
|
|
71
|
-
const marginLeft = isFirst || isOnly ? 0 : -1;
|
|
72
|
-
|
|
73
|
-
return rtl( { marginLeft } )();
|
|
74
|
-
};
|
|
75
|
-
|
|
76
|
-
export const UnitControl = styled( BaseUnitControl )`
|
|
77
|
-
max-width: 60px;
|
|
78
|
-
${ unitControlBorderRadiusStyles };
|
|
79
|
-
${ unitControlMarginStyles };
|
|
39
|
+
margin-inline-end: ${ space( 2 ) };
|
|
80
40
|
`;
|