@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.
Files changed (259) hide show
  1. package/CHANGELOG.md +27 -2
  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-picker/hsl-input.js +55 -33
  34. package/build/color-picker/hsl-input.js.map +1 -1
  35. package/build/custom-select-control-v2/index.js +3 -2
  36. package/build/custom-select-control-v2/index.js.map +1 -1
  37. package/build/slot-fill/bubbles-virtually/use-slot-fills.js +1 -1
  38. package/build/slot-fill/bubbles-virtually/use-slot-fills.js.map +1 -1
  39. package/build/theme/styles.js +11 -6
  40. package/build/theme/styles.js.map +1 -1
  41. package/build/toggle-group-control/toggle-group-control/utils.js +7 -1
  42. package/build/toggle-group-control/toggle-group-control/utils.js.map +1 -1
  43. package/build/tooltip/index.js +15 -12
  44. package/build/tooltip/index.js.map +1 -1
  45. package/build/tooltip/types.js.map +1 -1
  46. package/build-module/border-box-control/border-box-control/component.js.map +1 -1
  47. package/build-module/border-box-control/border-box-control/hook.js +3 -1
  48. package/build-module/border-box-control/border-box-control/hook.js.map +1 -1
  49. package/build-module/border-box-control/types.js.map +1 -1
  50. package/build-module/border-control/border-control/component.js +5 -1
  51. package/build-module/border-control/border-control/component.js.map +1 -1
  52. package/build-module/border-control/border-control/hook.js +18 -15
  53. package/build-module/border-control/border-control/hook.js.map +1 -1
  54. package/build-module/border-control/border-control-dropdown/component.js +2 -1
  55. package/build-module/border-control/border-control-dropdown/component.js.map +1 -1
  56. package/build-module/border-control/border-control-style-picker/component.js +21 -48
  57. package/build-module/border-control/border-control-style-picker/component.js.map +1 -1
  58. package/build-module/border-control/styles.js +14 -24
  59. package/build-module/border-control/styles.js.map +1 -1
  60. package/build-module/border-control/types.js.map +1 -1
  61. package/build-module/box-control/all-input-control.js +38 -28
  62. package/build-module/box-control/all-input-control.js.map +1 -1
  63. package/build-module/box-control/axial-input-controls.js +42 -57
  64. package/build-module/box-control/axial-input-controls.js.map +1 -1
  65. package/build-module/box-control/index.js +22 -25
  66. package/build-module/box-control/index.js.map +1 -1
  67. package/build-module/box-control/input-controls.js +47 -40
  68. package/build-module/box-control/input-controls.js.map +1 -1
  69. package/build-module/box-control/styles/box-control-styles.js +45 -105
  70. package/build-module/box-control/styles/box-control-styles.js.map +1 -1
  71. package/build-module/box-control/types.js.map +1 -1
  72. package/build-module/box-control/utils.js +121 -7
  73. package/build-module/box-control/utils.js.map +1 -1
  74. package/build-module/button/index.js +14 -16
  75. package/build-module/button/index.js.map +1 -1
  76. package/build-module/button/types.js.map +1 -1
  77. package/build-module/color-picker/hsl-input.js +55 -33
  78. package/build-module/color-picker/hsl-input.js.map +1 -1
  79. package/build-module/custom-select-control-v2/index.js +3 -2
  80. package/build-module/custom-select-control-v2/index.js.map +1 -1
  81. package/build-module/slot-fill/bubbles-virtually/use-slot-fills.js +1 -1
  82. package/build-module/slot-fill/bubbles-virtually/use-slot-fills.js.map +1 -1
  83. package/build-module/theme/styles.js +11 -2
  84. package/build-module/theme/styles.js.map +1 -1
  85. package/build-module/toggle-group-control/toggle-group-control/utils.js +7 -1
  86. package/build-module/toggle-group-control/toggle-group-control/utils.js.map +1 -1
  87. package/build-module/tooltip/index.js +16 -13
  88. package/build-module/tooltip/index.js.map +1 -1
  89. package/build-module/tooltip/types.js.map +1 -1
  90. package/build-style/style-rtl.css +6 -4
  91. package/build-style/style.css +6 -4
  92. package/build-types/border-box-control/border-box-control/component.d.ts +1 -0
  93. package/build-types/border-box-control/border-box-control/component.d.ts.map +1 -1
  94. package/build-types/border-box-control/border-box-control/hook.d.ts +4 -4
  95. package/build-types/border-box-control/border-box-control/hook.d.ts.map +1 -1
  96. package/build-types/border-box-control/border-box-control-linked-button/hook.d.ts +5 -5
  97. package/build-types/border-box-control/border-box-control-split-controls/hook.d.ts +4 -4
  98. package/build-types/border-box-control/border-box-control-visualizer/hook.d.ts +4 -4
  99. package/build-types/border-box-control/stories/index.story.d.ts +2 -1
  100. package/build-types/border-box-control/stories/index.story.d.ts.map +1 -1
  101. package/build-types/border-box-control/types.d.ts +6 -0
  102. package/build-types/border-box-control/types.d.ts.map +1 -1
  103. package/build-types/border-control/border-control/component.d.ts +1 -0
  104. package/build-types/border-control/border-control/component.d.ts.map +1 -1
  105. package/build-types/border-control/border-control/hook.d.ts +6 -4
  106. package/build-types/border-control/border-control/hook.d.ts.map +1 -1
  107. package/build-types/border-control/border-control-dropdown/component.d.ts +1 -0
  108. package/build-types/border-control/border-control-dropdown/component.d.ts.map +1 -1
  109. package/build-types/border-control/border-control-dropdown/hook.d.ts +5 -4
  110. package/build-types/border-control/border-control-dropdown/hook.d.ts.map +1 -1
  111. package/build-types/border-control/border-control-style-picker/component.d.ts +3 -4
  112. package/build-types/border-control/border-control-style-picker/component.d.ts.map +1 -1
  113. package/build-types/border-control/stories/index.story.d.ts +12 -6
  114. package/build-types/border-control/stories/index.story.d.ts.map +1 -1
  115. package/build-types/border-control/styles.d.ts +0 -2
  116. package/build-types/border-control/styles.d.ts.map +1 -1
  117. package/build-types/border-control/types.d.ts +12 -1
  118. package/build-types/border-control/types.d.ts.map +1 -1
  119. package/build-types/box-control/all-input-control.d.ts +1 -1
  120. package/build-types/box-control/all-input-control.d.ts.map +1 -1
  121. package/build-types/box-control/axial-input-controls.d.ts +1 -1
  122. package/build-types/box-control/axial-input-controls.d.ts.map +1 -1
  123. package/build-types/box-control/index.d.ts +1 -1
  124. package/build-types/box-control/index.d.ts.map +1 -1
  125. package/build-types/box-control/input-controls.d.ts +1 -1
  126. package/build-types/box-control/input-controls.d.ts.map +1 -1
  127. package/build-types/box-control/stories/index.story.d.ts +42 -36
  128. package/build-types/box-control/stories/index.story.d.ts.map +1 -1
  129. package/build-types/box-control/styles/box-control-styles.d.ts +49 -23
  130. package/build-types/box-control/styles/box-control-styles.d.ts.map +1 -1
  131. package/build-types/box-control/types.d.ts +12 -12
  132. package/build-types/box-control/types.d.ts.map +1 -1
  133. package/build-types/box-control/utils.d.ts +2 -1
  134. package/build-types/box-control/utils.d.ts.map +1 -1
  135. package/build-types/button/deprecated.d.ts +3 -3
  136. package/build-types/button/index.d.ts.map +1 -1
  137. package/build-types/button/types.d.ts +7 -3
  138. package/build-types/button/types.d.ts.map +1 -1
  139. package/build-types/card/card/hook.d.ts +4 -4
  140. package/build-types/card/card-body/hook.d.ts +4 -4
  141. package/build-types/card/card-divider/hook.d.ts +4 -4
  142. package/build-types/card/card-footer/hook.d.ts +4 -4
  143. package/build-types/card/card-header/hook.d.ts +4 -4
  144. package/build-types/card/card-media/hook.d.ts +4 -4
  145. package/build-types/color-palette/styles.d.ts +2 -2
  146. package/build-types/color-picker/component.d.ts +1 -1
  147. package/build-types/color-picker/hsl-input.d.ts.map +1 -1
  148. package/build-types/color-picker/stories/index.story.d.ts +1 -1
  149. package/build-types/color-picker/styles.d.ts +3 -3
  150. package/build-types/custom-select-control-v2/index.d.ts.map +1 -1
  151. package/build-types/date-time/date/styles.d.ts +3 -3
  152. package/build-types/date-time/date-time/styles.d.ts +1 -1
  153. package/build-types/date-time/time/styles.d.ts +4 -4
  154. package/build-types/elevation/hook.d.ts +4 -4
  155. package/build-types/flex/flex/hook.d.ts +4 -4
  156. package/build-types/flex/flex-block/hook.d.ts +4 -4
  157. package/build-types/flex/flex-item/hook.d.ts +4 -4
  158. package/build-types/focal-point-picker/styles/focal-point-picker-style.d.ts +1 -1
  159. package/build-types/font-size-picker/styles.d.ts +1 -1
  160. package/build-types/grid/hook.d.ts +4 -4
  161. package/build-types/h-stack/hook.d.ts +4 -4
  162. package/build-types/heading/component.d.ts +1 -1
  163. package/build-types/heading/hook.d.ts +4 -4
  164. package/build-types/item-group/item/hook.d.ts +4 -4
  165. package/build-types/item-group/item-group/hook.d.ts +4 -4
  166. package/build-types/menu-item/index.d.ts +1 -1
  167. package/build-types/menu-item/stories/index.story.d.ts +4 -4
  168. package/build-types/navigation/styles/navigation-styles.d.ts +2 -2
  169. package/build-types/navigator/navigator-back-button/hook.d.ts +4 -4
  170. package/build-types/navigator/navigator-button/hook.d.ts +4 -4
  171. package/build-types/number-control/index.d.ts +1 -1
  172. package/build-types/number-control/stories/index.story.d.ts +1 -1
  173. package/build-types/palette-edit/styles.d.ts +3 -3
  174. package/build-types/range-control/index.d.ts +1 -1
  175. package/build-types/range-control/styles/range-control-styles.d.ts +1 -1
  176. package/build-types/resizable-box/index.d.ts +1 -1
  177. package/build-types/resizable-box/resize-tooltip/index.d.ts +1 -1
  178. package/build-types/resizable-box/stories/index.story.d.ts +2 -2
  179. package/build-types/scrollable/hook.d.ts +4 -4
  180. package/build-types/spacer/hook.d.ts +4 -4
  181. package/build-types/surface/hook.d.ts +4 -4
  182. package/build-types/text/hook.d.ts +4 -4
  183. package/build-types/theme/styles.d.ts.map +1 -1
  184. package/build-types/toggle-control/stories/index.story.d.ts +2 -2
  185. package/build-types/toggle-group-control/toggle-group-control/utils.d.ts.map +1 -1
  186. package/build-types/toggle-group-control/toggle-group-control-option-icon/component.d.ts +1 -1
  187. package/build-types/toolbar/toolbar-button/index.d.ts +3 -3
  188. package/build-types/tools-panel/tools-panel/hook.d.ts +4 -4
  189. package/build-types/tools-panel/tools-panel-header/hook.d.ts +4 -4
  190. package/build-types/tools-panel/tools-panel-item/hook.d.ts +4 -4
  191. package/build-types/tooltip/index.d.ts +1 -1
  192. package/build-types/tooltip/index.d.ts.map +1 -1
  193. package/build-types/tooltip/stories/index.story.d.ts +1 -1
  194. package/build-types/tooltip/stories/index.story.d.ts.map +1 -1
  195. package/build-types/tooltip/types.d.ts +1 -1
  196. package/build-types/tooltip/types.d.ts.map +1 -1
  197. package/build-types/truncate/hook.d.ts +4 -4
  198. package/build-types/unit-control/index.d.ts +1 -1
  199. package/build-types/unit-control/styles/unit-control-styles.d.ts +1 -1
  200. package/build-types/v-stack/hook.d.ts +4 -4
  201. package/build-types/v-stack/stories/index.story.d.ts +1 -1
  202. package/package.json +19 -19
  203. package/src/border-box-control/border-box-control/component.tsx +0 -1
  204. package/src/border-box-control/border-box-control/hook.ts +5 -1
  205. package/src/border-box-control/types.ts +6 -0
  206. package/src/border-control/border-control/component.tsx +4 -0
  207. package/src/border-control/border-control/hook.ts +22 -16
  208. package/src/border-control/border-control-dropdown/component.tsx +2 -1
  209. package/src/border-control/border-control-style-picker/component.tsx +31 -66
  210. package/src/border-control/styles.ts +0 -15
  211. package/src/border-control/types.ts +15 -1
  212. package/src/box-control/all-input-control.tsx +57 -34
  213. package/src/box-control/axial-input-controls.tsx +79 -69
  214. package/src/box-control/index.tsx +47 -54
  215. package/src/box-control/input-controls.tsx +114 -83
  216. package/src/box-control/styles/box-control-styles.ts +21 -61
  217. package/src/box-control/test/index.tsx +126 -18
  218. package/src/box-control/types.ts +10 -21
  219. package/src/box-control/utils.ts +43 -8
  220. package/src/button/README.md +1 -1
  221. package/src/button/index.tsx +21 -33
  222. package/src/button/test/index.tsx +122 -0
  223. package/src/button/types.ts +7 -3
  224. package/src/circular-option-picker/test/index.tsx +10 -16
  225. package/src/color-picker/hsl-input.tsx +56 -30
  226. package/src/color-picker/test/index.tsx +190 -16
  227. package/src/custom-select-control-v2/index.tsx +5 -2
  228. package/src/palette-edit/test/index.tsx +326 -10
  229. package/src/slot-fill/bubbles-virtually/use-slot-fills.ts +1 -1
  230. package/src/tabs/test/index.tsx +3 -1
  231. package/src/theme/styles.ts +3 -1
  232. package/src/toggle-group-control/test/__snapshots__/index.tsx.snap +6 -6
  233. package/src/toggle-group-control/test/index.tsx +73 -36
  234. package/src/toggle-group-control/toggle-group-control/utils.ts +8 -3
  235. package/src/tooltip/index.tsx +29 -29
  236. package/src/tooltip/test/index.tsx +32 -13
  237. package/src/tooltip/types.ts +1 -1
  238. package/tsconfig.tsbuildinfo +1 -1
  239. package/build/border-control/border-control-style-picker/hook.js +0 -41
  240. package/build/border-control/border-control-style-picker/hook.js.map +0 -1
  241. package/build/box-control/styles/box-control-visualizer-styles.js +0 -93
  242. package/build/box-control/styles/box-control-visualizer-styles.js.map +0 -1
  243. package/build/box-control/unit-control.js +0 -76
  244. package/build/box-control/unit-control.js.map +0 -1
  245. package/build-module/border-control/border-control-style-picker/hook.js +0 -32
  246. package/build-module/border-control/border-control-style-picker/hook.js.map +0 -1
  247. package/build-module/box-control/styles/box-control-visualizer-styles.js +0 -86
  248. package/build-module/box-control/styles/box-control-visualizer-styles.js.map +0 -1
  249. package/build-module/box-control/unit-control.js +0 -68
  250. package/build-module/box-control/unit-control.js.map +0 -1
  251. package/build-types/border-control/border-control-style-picker/hook.d.ts +0 -267
  252. package/build-types/border-control/border-control-style-picker/hook.d.ts.map +0 -1
  253. package/build-types/box-control/styles/box-control-visualizer-styles.d.ts +0 -46
  254. package/build-types/box-control/styles/box-control-visualizer-styles.d.ts.map +0 -1
  255. package/build-types/box-control/unit-control.d.ts +0 -4
  256. package/build-types/box-control/unit-control.d.ts.map +0 -1
  257. package/src/border-control/border-control-style-picker/hook.ts +0 -35
  258. package/src/box-control/styles/box-control-visualizer-styles.ts +0 -75
  259. 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 UnitControl from './unit-control';
6
- import { LABELS } from './utils';
7
- import { Layout } from './styles/box-control-styles';
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 createHandleOnHoverOn = ( side: GroupedSide ) => () => {
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
- <Layout
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
- <UnitControl
133
- { ...props }
134
- isFirst={ first === side }
135
- isLast={ last === side }
136
- isOnly={ only === side }
137
- value={ [
138
- parsedQuantity,
139
- selectedUnit ?? parsedUnit,
140
- ].join( '' ) }
141
- onChange={ createHandleOnChange( side ) }
142
- onUnitChange={ createHandleOnUnitChange( side ) }
143
- onFocus={ createHandleOnFocus( side ) }
144
- onHoverOn={ createHandleOnHoverOn( side ) }
145
- onHoverOff={ createHandleOnHoverOff( side ) }
146
- label={ LABELS[ side ] }
147
- key={ side }
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
- </Layout>
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
- Root,
21
- Header,
22
- HeaderControlWrapper,
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
- <Root id={ id } role="group" aria-labelledby={ headingId }>
159
- <Header className="component-box-control__header">
160
- <FlexItem>
161
- <BaseControl.VisualLabel id={ headingId }>
162
- { label }
163
- </BaseControl.VisualLabel>
164
- </FlexItem>
165
- { allowReset && (
166
- <FlexItem>
167
- <Button
168
- className="component-box-control__reset-button"
169
- variant="secondary"
170
- size="small"
171
- onClick={ handleOnReset }
172
- disabled={ ! isDirty }
173
- >
174
- { __( 'Reset' ) }
175
- </Button>
176
- </FlexItem>
177
- ) }
178
- </Header>
179
- <HeaderControlWrapper className="component-box-control__header-control-wrapper">
180
- <FlexItem>
181
- <BoxControlIcon side={ side } sides={ sides } />
182
- </FlexItem>
183
- { isLinked && (
184
- <FlexBlock>
185
- <AllInputControl
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
- </Root>
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 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
  `;