@wordpress/components 25.15.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.
Files changed (236) hide show
  1. package/CHANGELOG.md +26 -0
  2. package/build/border-box-control/border-box-control/component.js.map +1 -1
  3. package/build/border-box-control/border-box-control/hook.js +3 -1
  4. package/build/border-box-control/border-box-control/hook.js.map +1 -1
  5. package/build/border-box-control/types.js.map +1 -1
  6. package/build/border-control/border-control/component.js +5 -1
  7. package/build/border-control/border-control/component.js.map +1 -1
  8. package/build/border-control/border-control/hook.js +18 -15
  9. package/build/border-control/border-control/hook.js.map +1 -1
  10. package/build/border-control/border-control-dropdown/component.js +2 -1
  11. package/build/border-control/border-control-dropdown/component.js.map +1 -1
  12. package/build/border-control/border-control-style-picker/component.js +21 -49
  13. package/build/border-control/border-control-style-picker/component.js.map +1 -1
  14. package/build/border-control/styles.js +15 -27
  15. package/build/border-control/styles.js.map +1 -1
  16. package/build/border-control/types.js.map +1 -1
  17. package/build/box-control/all-input-control.js +35 -29
  18. package/build/box-control/all-input-control.js.map +1 -1
  19. package/build/box-control/axial-input-controls.js +40 -54
  20. package/build/box-control/axial-input-controls.js.map +1 -1
  21. package/build/box-control/index.js +21 -24
  22. package/build/box-control/index.js.map +1 -1
  23. package/build/box-control/input-controls.js +45 -37
  24. package/build/box-control/input-controls.js.map +1 -1
  25. package/build/box-control/styles/box-control-styles.js +50 -112
  26. package/build/box-control/styles/box-control-styles.js.map +1 -1
  27. package/build/box-control/types.js.map +1 -1
  28. package/build/box-control/utils.js +123 -8
  29. package/build/box-control/utils.js.map +1 -1
  30. package/build/button/index.js +14 -16
  31. package/build/button/index.js.map +1 -1
  32. package/build/button/types.js.map +1 -1
  33. package/build/color-palette/index.native.js +11 -7
  34. package/build/color-palette/index.native.js.map +1 -1
  35. package/build/color-picker/hsl-input.js +55 -33
  36. package/build/color-picker/hsl-input.js.map +1 -1
  37. package/build/custom-select-control-v2/index.js +3 -2
  38. package/build/custom-select-control-v2/index.js.map +1 -1
  39. package/build/mobile/color-settings/palette.screen.native.js +8 -4
  40. package/build/mobile/color-settings/palette.screen.native.js.map +1 -1
  41. package/build/slot-fill/bubbles-virtually/use-slot-fills.js +1 -1
  42. package/build/slot-fill/bubbles-virtually/use-slot-fills.js.map +1 -1
  43. package/build/theme/styles.js +11 -6
  44. package/build/theme/styles.js.map +1 -1
  45. package/build/toggle-group-control/toggle-group-control/utils.js +7 -1
  46. package/build/toggle-group-control/toggle-group-control/utils.js.map +1 -1
  47. package/build/tooltip/index.js +35 -8
  48. package/build/tooltip/index.js.map +1 -1
  49. package/build/tooltip/types.js.map +1 -1
  50. package/build-module/border-box-control/border-box-control/component.js.map +1 -1
  51. package/build-module/border-box-control/border-box-control/hook.js +3 -1
  52. package/build-module/border-box-control/border-box-control/hook.js.map +1 -1
  53. package/build-module/border-box-control/types.js.map +1 -1
  54. package/build-module/border-control/border-control/component.js +5 -1
  55. package/build-module/border-control/border-control/component.js.map +1 -1
  56. package/build-module/border-control/border-control/hook.js +18 -15
  57. package/build-module/border-control/border-control/hook.js.map +1 -1
  58. package/build-module/border-control/border-control-dropdown/component.js +2 -1
  59. package/build-module/border-control/border-control-dropdown/component.js.map +1 -1
  60. package/build-module/border-control/border-control-style-picker/component.js +21 -48
  61. package/build-module/border-control/border-control-style-picker/component.js.map +1 -1
  62. package/build-module/border-control/styles.js +14 -24
  63. package/build-module/border-control/styles.js.map +1 -1
  64. package/build-module/border-control/types.js.map +1 -1
  65. package/build-module/box-control/all-input-control.js +38 -28
  66. package/build-module/box-control/all-input-control.js.map +1 -1
  67. package/build-module/box-control/axial-input-controls.js +42 -57
  68. package/build-module/box-control/axial-input-controls.js.map +1 -1
  69. package/build-module/box-control/index.js +22 -25
  70. package/build-module/box-control/index.js.map +1 -1
  71. package/build-module/box-control/input-controls.js +47 -40
  72. package/build-module/box-control/input-controls.js.map +1 -1
  73. package/build-module/box-control/styles/box-control-styles.js +45 -105
  74. package/build-module/box-control/styles/box-control-styles.js.map +1 -1
  75. package/build-module/box-control/types.js.map +1 -1
  76. package/build-module/box-control/utils.js +121 -7
  77. package/build-module/box-control/utils.js.map +1 -1
  78. package/build-module/button/index.js +14 -16
  79. package/build-module/button/index.js.map +1 -1
  80. package/build-module/button/types.js.map +1 -1
  81. package/build-module/color-palette/index.native.js +11 -7
  82. package/build-module/color-palette/index.native.js.map +1 -1
  83. package/build-module/color-picker/hsl-input.js +55 -33
  84. package/build-module/color-picker/hsl-input.js.map +1 -1
  85. package/build-module/custom-select-control-v2/index.js +3 -2
  86. package/build-module/custom-select-control-v2/index.js.map +1 -1
  87. package/build-module/mobile/color-settings/palette.screen.native.js +8 -4
  88. package/build-module/mobile/color-settings/palette.screen.native.js.map +1 -1
  89. package/build-module/slot-fill/bubbles-virtually/use-slot-fills.js +1 -1
  90. package/build-module/slot-fill/bubbles-virtually/use-slot-fills.js.map +1 -1
  91. package/build-module/theme/styles.js +11 -2
  92. package/build-module/theme/styles.js.map +1 -1
  93. package/build-module/toggle-group-control/toggle-group-control/utils.js +7 -1
  94. package/build-module/toggle-group-control/toggle-group-control/utils.js.map +1 -1
  95. package/build-module/tooltip/index.js +34 -9
  96. package/build-module/tooltip/index.js.map +1 -1
  97. package/build-module/tooltip/types.js.map +1 -1
  98. package/build-style/style-rtl.css +6 -4
  99. package/build-style/style.css +6 -4
  100. package/build-types/border-box-control/border-box-control/component.d.ts +1 -0
  101. package/build-types/border-box-control/border-box-control/component.d.ts.map +1 -1
  102. package/build-types/border-box-control/border-box-control/hook.d.ts.map +1 -1
  103. package/build-types/border-box-control/border-box-control-linked-button/hook.d.ts +3 -3
  104. package/build-types/border-box-control/stories/index.story.d.ts +2 -1
  105. package/build-types/border-box-control/stories/index.story.d.ts.map +1 -1
  106. package/build-types/border-box-control/types.d.ts +6 -0
  107. package/build-types/border-box-control/types.d.ts.map +1 -1
  108. package/build-types/border-control/border-control/component.d.ts +1 -0
  109. package/build-types/border-control/border-control/component.d.ts.map +1 -1
  110. package/build-types/border-control/border-control/hook.d.ts +2 -0
  111. package/build-types/border-control/border-control/hook.d.ts.map +1 -1
  112. package/build-types/border-control/border-control-dropdown/component.d.ts +1 -0
  113. package/build-types/border-control/border-control-dropdown/component.d.ts.map +1 -1
  114. package/build-types/border-control/border-control-dropdown/hook.d.ts +1 -0
  115. package/build-types/border-control/border-control-dropdown/hook.d.ts.map +1 -1
  116. package/build-types/border-control/border-control-style-picker/component.d.ts +3 -4
  117. package/build-types/border-control/border-control-style-picker/component.d.ts.map +1 -1
  118. package/build-types/border-control/stories/index.story.d.ts +12 -6
  119. package/build-types/border-control/stories/index.story.d.ts.map +1 -1
  120. package/build-types/border-control/styles.d.ts +0 -2
  121. package/build-types/border-control/styles.d.ts.map +1 -1
  122. package/build-types/border-control/types.d.ts +12 -1
  123. package/build-types/border-control/types.d.ts.map +1 -1
  124. package/build-types/box-control/all-input-control.d.ts +1 -1
  125. package/build-types/box-control/all-input-control.d.ts.map +1 -1
  126. package/build-types/box-control/axial-input-controls.d.ts +1 -1
  127. package/build-types/box-control/axial-input-controls.d.ts.map +1 -1
  128. package/build-types/box-control/index.d.ts +1 -1
  129. package/build-types/box-control/index.d.ts.map +1 -1
  130. package/build-types/box-control/input-controls.d.ts +1 -1
  131. package/build-types/box-control/input-controls.d.ts.map +1 -1
  132. package/build-types/box-control/stories/index.story.d.ts +24 -18
  133. package/build-types/box-control/stories/index.story.d.ts.map +1 -1
  134. package/build-types/box-control/styles/box-control-styles.d.ts +49 -23
  135. package/build-types/box-control/styles/box-control-styles.d.ts.map +1 -1
  136. package/build-types/box-control/types.d.ts +12 -12
  137. package/build-types/box-control/types.d.ts.map +1 -1
  138. package/build-types/box-control/utils.d.ts +2 -1
  139. package/build-types/box-control/utils.d.ts.map +1 -1
  140. package/build-types/button/deprecated.d.ts +1 -1
  141. package/build-types/button/index.d.ts.map +1 -1
  142. package/build-types/button/types.d.ts +7 -3
  143. package/build-types/button/types.d.ts.map +1 -1
  144. package/build-types/color-picker/hsl-input.d.ts.map +1 -1
  145. package/build-types/color-picker/styles.d.ts +1 -1
  146. package/build-types/custom-select-control-v2/index.d.ts.map +1 -1
  147. package/build-types/date-time/time/styles.d.ts +4 -4
  148. package/build-types/focal-point-picker/stories/index.story.d.ts +4 -4
  149. package/build-types/focal-point-picker/styles/focal-point-picker-style.d.ts +1 -1
  150. package/build-types/navigation/styles/navigation-styles.d.ts +1 -1
  151. package/build-types/navigator/navigator-back-button/hook.d.ts +2 -2
  152. package/build-types/navigator/navigator-button/hook.d.ts +2 -2
  153. package/build-types/number-control/index.d.ts +1 -1
  154. package/build-types/number-control/stories/index.story.d.ts +1 -1
  155. package/build-types/range-control/styles/range-control-styles.d.ts +1 -1
  156. package/build-types/search-control/index.d.ts +1 -1
  157. package/build-types/search-control/stories/index.story.d.ts +2 -2
  158. package/build-types/text-control/index.d.ts +1 -1
  159. package/build-types/textarea-control/index.d.ts +1 -1
  160. package/build-types/theme/styles.d.ts.map +1 -1
  161. package/build-types/toggle-group-control/toggle-group-control/as-button-group.d.ts +1 -1
  162. package/build-types/toggle-group-control/toggle-group-control/as-radio-group.d.ts +1 -1
  163. package/build-types/toggle-group-control/toggle-group-control/utils.d.ts.map +1 -1
  164. package/build-types/toggle-group-control/toggle-group-control-option/component.d.ts +1 -1
  165. package/build-types/toggle-group-control/toggle-group-control-option-icon/component.d.ts +1 -1
  166. package/build-types/toolbar/toolbar-button/index.d.ts +1 -1
  167. package/build-types/tooltip/index.d.ts +1 -1
  168. package/build-types/tooltip/index.d.ts.map +1 -1
  169. package/build-types/tooltip/stories/index.story.d.ts +10 -1
  170. package/build-types/tooltip/stories/index.story.d.ts.map +1 -1
  171. package/build-types/tooltip/types.d.ts +3 -0
  172. package/build-types/tooltip/types.d.ts.map +1 -1
  173. package/build-types/unit-control/index.d.ts +1 -1
  174. package/build-types/unit-control/styles/unit-control-styles.d.ts +1 -1
  175. package/package.json +19 -19
  176. package/src/border-box-control/border-box-control/component.tsx +0 -1
  177. package/src/border-box-control/border-box-control/hook.ts +5 -1
  178. package/src/border-box-control/types.ts +6 -0
  179. package/src/border-control/border-control/component.tsx +4 -0
  180. package/src/border-control/border-control/hook.ts +22 -16
  181. package/src/border-control/border-control-dropdown/component.tsx +2 -1
  182. package/src/border-control/border-control-style-picker/component.tsx +31 -66
  183. package/src/border-control/styles.ts +0 -15
  184. package/src/border-control/types.ts +15 -1
  185. package/src/box-control/all-input-control.tsx +57 -34
  186. package/src/box-control/axial-input-controls.tsx +79 -69
  187. package/src/box-control/index.tsx +47 -54
  188. package/src/box-control/input-controls.tsx +114 -83
  189. package/src/box-control/styles/box-control-styles.ts +21 -61
  190. package/src/box-control/test/index.tsx +126 -18
  191. package/src/box-control/types.ts +10 -21
  192. package/src/box-control/utils.ts +43 -8
  193. package/src/button/README.md +1 -1
  194. package/src/button/index.tsx +21 -33
  195. package/src/button/test/index.tsx +122 -0
  196. package/src/button/types.ts +7 -3
  197. package/src/circular-option-picker/test/index.tsx +10 -16
  198. package/src/color-palette/index.native.js +18 -7
  199. package/src/color-picker/hsl-input.tsx +56 -30
  200. package/src/color-picker/test/index.tsx +190 -16
  201. package/src/custom-select-control-v2/index.tsx +5 -2
  202. package/src/mobile/color-settings/palette.screen.native.js +7 -5
  203. package/src/palette-edit/test/index.tsx +326 -10
  204. package/src/slot-fill/bubbles-virtually/use-slot-fills.ts +1 -1
  205. package/src/tabs/test/index.tsx +3 -1
  206. package/src/theme/styles.ts +3 -1
  207. package/src/toggle-group-control/test/__snapshots__/index.tsx.snap +6 -6
  208. package/src/toggle-group-control/test/index.tsx +73 -36
  209. package/src/toggle-group-control/toggle-group-control/utils.ts +8 -3
  210. package/src/tooltip/README.md +4 -0
  211. package/src/tooltip/index.tsx +46 -8
  212. package/src/tooltip/stories/index.story.tsx +18 -1
  213. package/src/tooltip/test/index.tsx +77 -12
  214. package/src/tooltip/types.ts +4 -0
  215. package/tsconfig.tsbuildinfo +1 -1
  216. package/build/border-control/border-control-style-picker/hook.js +0 -41
  217. package/build/border-control/border-control-style-picker/hook.js.map +0 -1
  218. package/build/box-control/styles/box-control-visualizer-styles.js +0 -93
  219. package/build/box-control/styles/box-control-visualizer-styles.js.map +0 -1
  220. package/build/box-control/unit-control.js +0 -76
  221. package/build/box-control/unit-control.js.map +0 -1
  222. package/build-module/border-control/border-control-style-picker/hook.js +0 -32
  223. package/build-module/border-control/border-control-style-picker/hook.js.map +0 -1
  224. package/build-module/box-control/styles/box-control-visualizer-styles.js +0 -86
  225. package/build-module/box-control/styles/box-control-visualizer-styles.js.map +0 -1
  226. package/build-module/box-control/unit-control.js +0 -68
  227. package/build-module/box-control/unit-control.js.map +0 -1
  228. package/build-types/border-control/border-control-style-picker/hook.d.ts +0 -267
  229. package/build-types/border-control/border-control-style-picker/hook.d.ts.map +0 -1
  230. package/build-types/box-control/styles/box-control-visualizer-styles.d.ts +0 -46
  231. package/build-types/box-control/styles/box-control-visualizer-styles.d.ts.map +0 -1
  232. package/build-types/box-control/unit-control.d.ts +0 -4
  233. package/build-types/box-control/unit-control.d.ts.map +0 -1
  234. package/src/border-control/border-control-style-picker/hook.ts +0 -35
  235. package/src/box-control/styles/box-control-visualizer-styles.ts +0 -75
  236. package/src/box-control/unit-control.tsx +0 -74
@@ -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 UnitControl from './unit-control';
8
+ import Tooltip from '../tooltip';
5
9
  import { parseQuantityAndUnitFromRawValue } from '../unit-control/utils';
6
- import { ALL_SIDES, LABELS } from './utils';
7
- import { LayoutContainer, Layout } from './styles/box-control-styles';
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 createHandleOnChange: (
43
- side: keyof BoxControlValue
44
- ) => UnitControlProps[ 'onChange' ] =
45
- ( side ) =>
46
- ( next, { event } ) => {
47
- const nextValues = { ...values };
48
- const isNumeric =
49
- next !== undefined && ! isNaN( parseFloat( next ) );
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
- nextValues[ side ] = nextValue;
52
+ nextValues[ side ] = nextValue;
53
53
 
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 ( 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;
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
- handleOnChange( nextValues );
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
- <LayoutContainer className="component-box-control__input-controls-wrapper">
99
- <Layout
100
- gap={ 0 }
101
- align="top"
102
- className="component-box-control__input-controls"
103
- >
104
- { filteredSides.map( ( side ) => {
105
- const [ parsedQuantity, parsedUnit ] =
106
- parseQuantityAndUnitFromRawValue( values[ side ] );
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
- const computedUnit = values[ side ]
109
- ? parsedUnit
110
- : selectedUnits[ side ];
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
- return (
113
- <UnitControl
114
- { ...props }
115
- isFirst={ first === side }
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
- key={ `box-control-${ side }` }
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
- </Layout>
132
- </LayoutContainer>
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 { Flex } from '../../flex';
10
- import BaseUnitControl from '../../unit-control';
11
- import { rtl } from '../../utils';
12
- import type { BoxUnitControlProps } from '../types';
13
-
14
- export const Root = styled.div`
15
- box-sizing: border-box;
16
- max-width: 235px;
17
- padding-bottom: 12px;
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 Header = styled( Flex )`
22
- margin-bottom: 8px;
19
+ export const InputWrapper = styled( HStack )`
20
+ grid-column: 1 / span 3;
23
21
  `;
24
22
 
25
- export const HeaderControlWrapper = styled( Flex )`
26
- min-height: 30px;
27
- gap: 0;
23
+ export const ResetButton = styled( Button )`
24
+ grid-area: 1 / 2;
25
+ justify-self: end;
28
26
  `;
29
27
 
30
- export const UnitControlWrapper = styled.div`
31
- box-sizing: border-box;
32
- max-width: 80px;
28
+ export const LinkedButtonWrapper = styled.div`
29
+ grid-area: 1 / 3;
30
+ justify-self: end;
33
31
  `;
34
32
 
35
- export const LayoutContainer = styled( Flex )`
36
- justify-content: center;
37
- padding-top: 8px;
33
+ export const FlexedBoxControlIcon = styled( BoxControlIcon )`
34
+ flex: 0 0 auto;
38
35
  `;
39
36
 
40
- export const Layout = styled( Flex )`
41
- position: relative;
42
- height: 100%;
37
+ export const FlexedRangeControl = styled( RangeControl )`
43
38
  width: 100%;
44
- justify-content: flex-start;
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
  `;
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * External dependencies
3
3
  */
4
- import { render, screen } from '@testing-library/react';
4
+ import { fireEvent, render, screen } from '@testing-library/react';
5
5
  import userEvent from '@testing-library/user-event';
6
6
 
7
7
  /**
@@ -33,7 +33,10 @@ describe( 'BoxControl', () => {
33
33
  render( <BoxControl onChange={ () => {} } /> );
34
34
 
35
35
  expect(
36
- screen.getByRole( 'textbox', { name: 'Box Control' } )
36
+ screen.getByRole( 'group', { name: 'Box Control' } )
37
+ ).toBeVisible();
38
+ expect(
39
+ screen.getByRole( 'textbox', { name: 'All sides' } )
37
40
  ).toBeVisible();
38
41
  } );
39
42
 
@@ -42,15 +45,41 @@ describe( 'BoxControl', () => {
42
45
 
43
46
  render( <BoxControl onChange={ () => {} } /> );
44
47
 
45
- const input = screen.getByRole( 'textbox', {
46
- name: 'Box Control',
47
- } );
48
+ const input = screen.getByRole( 'textbox', { name: 'All sides' } );
48
49
 
49
50
  await user.type( input, '100' );
50
51
  await user.keyboard( '{Enter}' );
51
52
 
52
53
  expect( input ).toHaveValue( '100' );
53
54
  } );
55
+
56
+ it( 'should update input values when interacting with slider', () => {
57
+ render( <BoxControl onChange={ () => {} } /> );
58
+
59
+ const slider = screen.getByRole( 'slider' );
60
+
61
+ fireEvent.change( slider, { target: { value: 50 } } );
62
+
63
+ expect( slider ).toHaveValue( '50' );
64
+ expect(
65
+ screen.getByRole( 'textbox', { name: 'All sides' } )
66
+ ).toHaveValue( '50' );
67
+ } );
68
+
69
+ it( 'should update slider values when interacting with input', async () => {
70
+ const user = userEvent.setup();
71
+ render( <BoxControl onChange={ () => {} } /> );
72
+
73
+ const input = screen.getByRole( 'textbox', {
74
+ name: 'All sides',
75
+ } );
76
+
77
+ await user.type( input, '50' );
78
+ await user.keyboard( '{Enter}' );
79
+
80
+ expect( input ).toHaveValue( '50' );
81
+ expect( screen.getByRole( 'slider' ) ).toHaveValue( '50' );
82
+ } );
54
83
  } );
55
84
 
56
85
  describe( 'Reset', () => {
@@ -60,7 +89,7 @@ describe( 'BoxControl', () => {
60
89
  render( <BoxControl onChange={ () => {} } /> );
61
90
 
62
91
  const input = screen.getByRole( 'textbox', {
63
- name: 'Box Control',
92
+ name: 'All sides',
64
93
  } );
65
94
 
66
95
  await user.type( input, '100' );
@@ -79,7 +108,7 @@ describe( 'BoxControl', () => {
79
108
  render( <Example /> );
80
109
 
81
110
  const input = screen.getByRole( 'textbox', {
82
- name: 'Box Control',
111
+ name: 'All sides',
83
112
  } );
84
113
 
85
114
  await user.type( input, '100' );
@@ -98,7 +127,7 @@ describe( 'BoxControl', () => {
98
127
  render( <Example /> );
99
128
 
100
129
  const input = screen.getByRole( 'textbox', {
101
- name: 'Box Control',
130
+ name: 'All sides',
102
131
  } );
103
132
 
104
133
  await user.type( input, '100' );
@@ -118,7 +147,7 @@ describe( 'BoxControl', () => {
118
147
  render( <BoxControl onChange={ ( v ) => spyChange( v ) } /> );
119
148
 
120
149
  const input = screen.getByRole( 'textbox', {
121
- name: 'Box Control',
150
+ name: 'All sides',
122
151
  } );
123
152
 
124
153
  await user.type( input, '100' );
@@ -152,21 +181,49 @@ describe( 'BoxControl', () => {
152
181
  );
153
182
 
154
183
  await user.type(
155
- screen.getByRole( 'textbox', { name: 'Top' } ),
184
+ screen.getByRole( 'textbox', { name: 'Top side' } ),
156
185
  '100'
157
186
  );
158
187
 
159
188
  expect(
160
- screen.getByRole( 'textbox', { name: 'Top' } )
189
+ screen.getByRole( 'textbox', { name: 'Top side' } )
161
190
  ).toHaveValue( '100' );
162
191
  expect(
163
- screen.getByRole( 'textbox', { name: 'Right' } )
192
+ screen.getByRole( 'textbox', { name: 'Right side' } )
164
193
  ).not.toHaveValue();
165
194
  expect(
166
- screen.getByRole( 'textbox', { name: 'Bottom' } )
195
+ screen.getByRole( 'textbox', { name: 'Bottom side' } )
167
196
  ).not.toHaveValue();
168
197
  expect(
169
- screen.getByRole( 'textbox', { name: 'Left' } )
198
+ screen.getByRole( 'textbox', { name: 'Left side' } )
199
+ ).not.toHaveValue();
200
+ } );
201
+
202
+ it( 'should update a single side value when using slider unlinked', async () => {
203
+ const user = userEvent.setup();
204
+
205
+ render( <Example /> );
206
+
207
+ await user.click(
208
+ screen.getByRole( 'button', { name: 'Unlink sides' } )
209
+ );
210
+
211
+ const slider = screen.getByRole( 'slider', { name: 'Right side' } );
212
+
213
+ fireEvent.change( slider, { target: { value: 50 } } );
214
+
215
+ expect( slider ).toHaveValue( '50' );
216
+ expect(
217
+ screen.getByRole( 'textbox', { name: 'Top side' } )
218
+ ).not.toHaveValue();
219
+ expect(
220
+ screen.getByRole( 'textbox', { name: 'Right side' } )
221
+ ).toHaveValue( '50' );
222
+ expect(
223
+ screen.getByRole( 'textbox', { name: 'Bottom side' } )
224
+ ).not.toHaveValue();
225
+ expect(
226
+ screen.getByRole( 'textbox', { name: 'Left side' } )
170
227
  ).not.toHaveValue();
171
228
  } );
172
229
 
@@ -181,17 +238,68 @@ describe( 'BoxControl', () => {
181
238
 
182
239
  await user.type(
183
240
  screen.getByRole( 'textbox', {
184
- name: 'Vertical',
241
+ name: 'Top and bottom sides',
185
242
  } ),
186
243
  '100'
187
244
  );
188
245
 
189
246
  expect(
190
- screen.getByRole( 'textbox', { name: 'Vertical' } )
247
+ screen.getByRole( 'textbox', { name: 'Top and bottom sides' } )
191
248
  ).toHaveValue( '100' );
192
249
  expect(
193
- screen.getByRole( 'textbox', { name: 'Horizontal' } )
250
+ screen.getByRole( 'textbox', { name: 'Left and right sides' } )
251
+ ).not.toHaveValue();
252
+ } );
253
+
254
+ it( 'should update a whole axis using a slider when value is changed when unlinked', async () => {
255
+ const user = userEvent.setup();
256
+
257
+ render( <Example splitOnAxis /> );
258
+
259
+ await user.click(
260
+ screen.getByRole( 'button', { name: 'Unlink sides' } )
261
+ );
262
+
263
+ const slider = screen.getByRole( 'slider', {
264
+ name: 'Left and right sides',
265
+ } );
266
+
267
+ fireEvent.change( slider, { target: { value: 50 } } );
268
+
269
+ expect( slider ).toHaveValue( '50' );
270
+ expect(
271
+ screen.getByRole( 'textbox', { name: 'Top and bottom sides' } )
194
272
  ).not.toHaveValue();
273
+ expect(
274
+ screen.getByRole( 'textbox', { name: 'Left and right sides' } )
275
+ ).toHaveValue( '50' );
276
+ } );
277
+
278
+ it( 'should show "Mixed" label when sides have different values but are linked', async () => {
279
+ const user = userEvent.setup();
280
+
281
+ render( <Example /> );
282
+
283
+ const unlinkButton = screen.getByRole( 'button', {
284
+ name: 'Unlink sides',
285
+ } );
286
+
287
+ await user.click( unlinkButton );
288
+
289
+ await user.type(
290
+ screen.getByRole( 'textbox', {
291
+ name: 'Right side',
292
+ } ),
293
+ '13'
294
+ );
295
+
296
+ expect(
297
+ screen.getByRole( 'textbox', { name: 'Right side' } )
298
+ ).toHaveValue( '13' );
299
+
300
+ await user.click( unlinkButton );
301
+
302
+ expect( screen.getByPlaceholderText( 'Mixed' ) ).toHaveValue( '' );
195
303
  } );
196
304
  } );
197
305
 
@@ -287,7 +395,7 @@ describe( 'BoxControl', () => {
287
395
  render( <BoxControl onChange={ onChangeSpy } /> );
288
396
 
289
397
  const valueInput = screen.getByRole( 'textbox', {
290
- name: 'Box Control',
398
+ name: 'All sides',
291
399
  } );
292
400
  const unitSelect = screen.getByRole( 'combobox', {
293
401
  name: 'Select unit',
@@ -1,8 +1,3 @@
1
- /**
2
- * External dependencies
3
- */
4
- import type { useHover } from '@use-gesture/react';
5
-
6
1
  /**
7
2
  * Internal dependencies
8
3
  */
@@ -16,6 +11,10 @@ export type BoxControlValue = {
16
11
  left?: string;
17
12
  };
18
13
 
14
+ export type CustomValueUnits = {
15
+ [ key: string ]: { max: number; step: number };
16
+ };
17
+
19
18
  type UnitControlPassthroughProps = Omit<
20
19
  UnitControlProps,
21
20
  'label' | 'onChange' | 'onFocus' | 'onMouseOver' | 'onMouseOut' | 'units'
@@ -72,6 +71,12 @@ export type BoxControlProps = Pick<
72
71
  * The current values of the control, expressed as an object of `top`, `right`, `bottom`, and `left` values.
73
72
  */
74
73
  values?: BoxControlValue;
74
+ /**
75
+ * Start opting into the larger default height that will become the default size in a future version.
76
+ *
77
+ * @default false
78
+ */
79
+ __next40pxDefaultSize?: boolean;
75
80
  };
76
81
 
77
82
  export type BoxControlInputControlProps = UnitControlPassthroughProps & {
@@ -92,22 +97,6 @@ export type BoxControlInputControlProps = UnitControlPassthroughProps & {
92
97
  values: BoxControlValue;
93
98
  };
94
99
 
95
- export type BoxUnitControlProps = UnitControlPassthroughProps &
96
- Pick< UnitControlProps, 'onChange' | 'onFocus' > & {
97
- isFirst?: boolean;
98
- isLast?: boolean;
99
- isOnly?: boolean;
100
- label?: string;
101
- onHoverOff?: (
102
- event: ReturnType< typeof useHover >[ 'event' ],
103
- state: Omit< ReturnType< typeof useHover >, 'event' >
104
- ) => void;
105
- onHoverOn?: (
106
- event: ReturnType< typeof useHover >[ 'event' ],
107
- state: Omit< ReturnType< typeof useHover >, 'event' >
108
- ) => void;
109
- };
110
-
111
100
  export type BoxControlIconProps = {
112
101
  /**
113
102
  * @default 24
@@ -7,17 +7,52 @@ import { __ } from '@wordpress/i18n';
7
7
  * Internal dependencies
8
8
  */
9
9
  import { parseQuantityAndUnitFromRawValue } from '../unit-control/utils';
10
- import type { BoxControlProps, BoxControlValue } from './types';
10
+ import type {
11
+ BoxControlProps,
12
+ BoxControlValue,
13
+ CustomValueUnits,
14
+ } from './types';
15
+
16
+ export const CUSTOM_VALUE_SETTINGS: CustomValueUnits = {
17
+ px: { max: 300, step: 1 },
18
+ '%': { max: 100, step: 1 },
19
+ vw: { max: 100, step: 1 },
20
+ vh: { max: 100, step: 1 },
21
+ em: { max: 10, step: 0.1 },
22
+ rm: { max: 10, step: 0.1 },
23
+ svw: { max: 100, step: 1 },
24
+ lvw: { max: 100, step: 1 },
25
+ dvw: { max: 100, step: 1 },
26
+ svh: { max: 100, step: 1 },
27
+ lvh: { max: 100, step: 1 },
28
+ dvh: { max: 100, step: 1 },
29
+ vi: { max: 100, step: 1 },
30
+ svi: { max: 100, step: 1 },
31
+ lvi: { max: 100, step: 1 },
32
+ dvi: { max: 100, step: 1 },
33
+ vb: { max: 100, step: 1 },
34
+ svb: { max: 100, step: 1 },
35
+ lvb: { max: 100, step: 1 },
36
+ dvb: { max: 100, step: 1 },
37
+ vmin: { max: 100, step: 1 },
38
+ svmin: { max: 100, step: 1 },
39
+ lvmin: { max: 100, step: 1 },
40
+ dvmin: { max: 100, step: 1 },
41
+ vmax: { max: 100, step: 1 },
42
+ svmax: { max: 100, step: 1 },
43
+ lvmax: { max: 100, step: 1 },
44
+ dvmax: { max: 100, step: 1 },
45
+ };
11
46
 
12
47
  export const LABELS = {
13
- all: __( 'All' ),
14
- top: __( 'Top' ),
15
- bottom: __( 'Bottom' ),
16
- left: __( 'Left' ),
17
- right: __( 'Right' ),
48
+ all: __( 'All sides' ),
49
+ top: __( 'Top side' ),
50
+ bottom: __( 'Bottom side' ),
51
+ left: __( 'Left side' ),
52
+ right: __( 'Right side' ),
18
53
  mixed: __( 'Mixed' ),
19
- vertical: __( 'Vertical' ),
20
- horizontal: __( 'Horizontal' ),
54
+ vertical: __( 'Top and bottom sides' ),
55
+ horizontal: __( 'Left and right sides' ),
21
56
  };
22
57
 
23
58
  export const DEFAULT_VALUES = {