@wordpress/components 19.9.0 → 19.10.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 (185) hide show
  1. package/CHANGELOG.md +30 -0
  2. package/CONTRIBUTING.md +80 -7
  3. package/build/angle-picker-control/angle-circle.js +5 -7
  4. package/build/angle-picker-control/angle-circle.js.map +1 -1
  5. package/build/box-control/index.js +0 -21
  6. package/build/box-control/index.js.map +1 -1
  7. package/build/box-control/utils.js +1 -8
  8. package/build/box-control/utils.js.map +1 -1
  9. package/build/button/index.js +3 -5
  10. package/build/button/index.js.map +1 -1
  11. package/build/circular-option-picker/index.js +1 -2
  12. package/build/circular-option-picker/index.js.map +1 -1
  13. package/build/disabled/index.js +4 -76
  14. package/build/disabled/index.js.map +1 -1
  15. package/build/input-control/index.js +3 -2
  16. package/build/input-control/index.js.map +1 -1
  17. package/build/input-control/styles/input-control-styles.js +42 -30
  18. package/build/input-control/styles/input-control-styles.js.map +1 -1
  19. package/build/mobile/bottom-sheet-select-control/index.native.js +1 -0
  20. package/build/mobile/bottom-sheet-select-control/index.native.js.map +1 -1
  21. package/build/popover/index.js +6 -52
  22. package/build/popover/index.js.map +1 -1
  23. package/build/select-control/index.js +31 -4
  24. package/build/select-control/index.js.map +1 -1
  25. package/build/select-control/styles/select-control-styles.js +8 -8
  26. package/build/select-control/styles/select-control-styles.js.map +1 -1
  27. package/build/text-control/index.js +35 -28
  28. package/build/text-control/index.js.map +1 -1
  29. package/build/text-control/types.js +6 -0
  30. package/build/text-control/types.js.map +1 -0
  31. package/build/toggle-group-control/toggle-group-control-option-icon/component.js +6 -4
  32. package/build/toggle-group-control/toggle-group-control-option-icon/component.js.map +1 -1
  33. package/build/tools-panel/tools-panel-header/component.js +52 -36
  34. package/build/tools-panel/tools-panel-header/component.js.map +1 -1
  35. package/build/unit-control/index.js +3 -3
  36. package/build/unit-control/index.js.map +1 -1
  37. package/build/unit-control/styles/unit-control-styles.js +11 -20
  38. package/build/unit-control/styles/unit-control-styles.js.map +1 -1
  39. package/build/unit-control/utils.js.map +1 -1
  40. package/build-module/angle-picker-control/angle-circle.js +5 -7
  41. package/build-module/angle-picker-control/angle-circle.js.map +1 -1
  42. package/build-module/box-control/index.js +1 -20
  43. package/build-module/box-control/index.js.map +1 -1
  44. package/build-module/box-control/utils.js +0 -6
  45. package/build-module/box-control/utils.js.map +1 -1
  46. package/build-module/button/index.js +3 -4
  47. package/build-module/button/index.js.map +1 -1
  48. package/build-module/circular-option-picker/index.js +1 -2
  49. package/build-module/circular-option-picker/index.js.map +1 -1
  50. package/build-module/disabled/index.js +5 -76
  51. package/build-module/disabled/index.js.map +1 -1
  52. package/build-module/input-control/index.js +3 -2
  53. package/build-module/input-control/index.js.map +1 -1
  54. package/build-module/input-control/styles/input-control-styles.js +42 -30
  55. package/build-module/input-control/styles/input-control-styles.js.map +1 -1
  56. package/build-module/mobile/bottom-sheet-select-control/index.native.js +1 -0
  57. package/build-module/mobile/bottom-sheet-select-control/index.native.js.map +1 -1
  58. package/build-module/popover/index.js +6 -52
  59. package/build-module/popover/index.js.map +1 -1
  60. package/build-module/select-control/index.js +29 -3
  61. package/build-module/select-control/index.js.map +1 -1
  62. package/build-module/select-control/styles/select-control-styles.js +8 -8
  63. package/build-module/select-control/styles/select-control-styles.js.map +1 -1
  64. package/build-module/text-control/index.js +35 -27
  65. package/build-module/text-control/index.js.map +1 -1
  66. package/build-module/text-control/types.js +2 -0
  67. package/build-module/text-control/types.js.map +1 -0
  68. package/build-module/toggle-group-control/toggle-group-control-option-icon/component.js +1 -5
  69. package/build-module/toggle-group-control/toggle-group-control-option-icon/component.js.map +1 -1
  70. package/build-module/tools-panel/tools-panel-header/component.js +51 -36
  71. package/build-module/tools-panel/tools-panel-header/component.js.map +1 -1
  72. package/build-module/unit-control/index.js +3 -3
  73. package/build-module/unit-control/index.js.map +1 -1
  74. package/build-module/unit-control/styles/unit-control-styles.js +11 -20
  75. package/build-module/unit-control/styles/unit-control-styles.js.map +1 -1
  76. package/build-module/unit-control/utils.js.map +1 -1
  77. package/build-style/style-rtl.css +7 -0
  78. package/build-style/style.css +7 -0
  79. package/build-types/button/index.d.ts.map +1 -1
  80. package/build-types/circular-option-picker/index.d.ts.map +1 -1
  81. package/build-types/color-picker/styles.d.ts +3 -3
  82. package/build-types/disabled/index.d.ts.map +1 -1
  83. package/build-types/input-control/index.d.ts +4 -3
  84. package/build-types/input-control/index.d.ts.map +1 -1
  85. package/build-types/input-control/stories/index.d.ts +5 -5
  86. package/build-types/input-control/stories/index.d.ts.map +1 -1
  87. package/build-types/input-control/styles/input-control-styles.d.ts +1 -0
  88. package/build-types/input-control/styles/input-control-styles.d.ts.map +1 -1
  89. package/build-types/input-control/types.d.ts +6 -0
  90. package/build-types/input-control/types.d.ts.map +1 -1
  91. package/build-types/number-control/styles/number-control-styles.d.ts +1 -1
  92. package/build-types/popover/index.d.ts +0 -1
  93. package/build-types/popover/index.d.ts.map +1 -1
  94. package/build-types/select-control/index.d.ts +30 -26
  95. package/build-types/select-control/index.d.ts.map +1 -1
  96. package/build-types/select-control/stories/index.d.ts +23 -0
  97. package/build-types/select-control/stories/index.d.ts.map +1 -0
  98. package/build-types/select-control/styles/select-control-styles.d.ts +3 -4
  99. package/build-types/select-control/styles/select-control-styles.d.ts.map +1 -1
  100. package/build-types/select-control/test/select-control.d.ts +2 -0
  101. package/build-types/select-control/test/select-control.d.ts.map +1 -0
  102. package/build-types/select-control/types.d.ts +52 -1
  103. package/build-types/select-control/types.d.ts.map +1 -1
  104. package/build-types/text-control/index.d.ts +32 -0
  105. package/build-types/text-control/index.d.ts.map +1 -0
  106. package/build-types/text-control/stories/index.d.ts +13 -0
  107. package/build-types/text-control/stories/index.d.ts.map +1 -0
  108. package/build-types/text-control/types.d.ts +25 -0
  109. package/build-types/text-control/types.d.ts.map +1 -0
  110. package/build-types/toggle-group-control/toggle-group-control-option-icon/component.d.ts.map +1 -1
  111. package/build-types/tools-panel/tools-panel-header/component.d.ts.map +1 -1
  112. package/build-types/tools-panel/types.d.ts +0 -1
  113. package/build-types/tools-panel/types.d.ts.map +1 -1
  114. package/build-types/unit-control/index.d.ts +2 -2
  115. package/build-types/unit-control/index.d.ts.map +1 -1
  116. package/build-types/unit-control/styles/unit-control-styles.d.ts.map +1 -1
  117. package/build-types/unit-control/test/index.d.ts +2 -0
  118. package/build-types/unit-control/test/index.d.ts.map +1 -0
  119. package/build-types/unit-control/test/utils.d.ts +2 -0
  120. package/build-types/unit-control/test/utils.d.ts.map +1 -0
  121. package/build-types/unit-control/types.d.ts +1 -1
  122. package/build-types/unit-control/types.d.ts.map +1 -1
  123. package/build-types/unit-control/utils.d.ts +3 -3
  124. package/build-types/unit-control/utils.d.ts.map +1 -1
  125. package/package.json +17 -17
  126. package/src/angle-picker-control/angle-circle.js +3 -3
  127. package/src/box-control/README.md +0 -74
  128. package/src/box-control/index.js +0 -15
  129. package/src/box-control/stories/index.js +0 -29
  130. package/src/box-control/utils.js +0 -7
  131. package/src/button/index.js +2 -4
  132. package/src/button/test/index.js +16 -1
  133. package/src/circular-option-picker/index.js +1 -2
  134. package/src/color-palette/README.md +0 -1
  135. package/src/color-palette/test/__snapshots__/index.js.snap +2 -3
  136. package/src/confirm-dialog/stories/index.js +87 -99
  137. package/src/date-time/stories/index.js +19 -0
  138. package/src/date-time/test/date.js +107 -78
  139. package/src/dimension-control/test/__snapshots__/index.test.js.snap +4 -4
  140. package/src/disabled/index.js +5 -90
  141. package/src/form-file-upload/test/index.js +15 -12
  142. package/src/input-control/README.md +1 -1
  143. package/src/input-control/index.tsx +3 -2
  144. package/src/input-control/stories/index.tsx +1 -1
  145. package/src/input-control/styles/input-control-styles.tsx +19 -5
  146. package/src/input-control/types.ts +6 -0
  147. package/src/menu-item/style.scss +10 -0
  148. package/src/mobile/bottom-sheet/bottom-sheet-navigation/test/navigation-container.native.js +8 -1
  149. package/src/mobile/bottom-sheet-select-control/index.native.js +1 -0
  150. package/src/mobile/html-text-input/style.android.scss +1 -0
  151. package/src/mobile/html-text-input/style.ios.scss +1 -0
  152. package/src/mobile/link-settings/test/link-settings-navigation.native.js +9 -1
  153. package/src/popover/index.js +5 -51
  154. package/src/select-control/README.md +2 -2
  155. package/src/select-control/index.tsx +30 -29
  156. package/src/select-control/stories/index.tsx +90 -0
  157. package/src/select-control/styles/select-control-styles.ts +9 -8
  158. package/src/select-control/test/{select-control.js → select-control.tsx} +2 -2
  159. package/src/select-control/types.ts +66 -1
  160. package/src/text-control/index.tsx +84 -0
  161. package/src/text-control/stories/index.tsx +66 -0
  162. package/src/text-control/types.ts +29 -0
  163. package/src/toggle-group-control/toggle-group-control-option-icon/component.tsx +1 -5
  164. package/src/tools-panel/test/__snapshots__/index.js.snap +1 -1
  165. package/src/tools-panel/test/index.js +71 -18
  166. package/src/tools-panel/tools-panel-header/component.tsx +75 -33
  167. package/src/tools-panel/types.ts +0 -1
  168. package/src/tooltip/test/index.js +6 -0
  169. package/src/unit-control/index.tsx +2 -5
  170. package/src/unit-control/styles/unit-control-styles.ts +3 -13
  171. package/src/unit-control/test/__snapshots__/index.tsx.snap +33 -0
  172. package/src/unit-control/test/{index.js → index.tsx} +214 -165
  173. package/src/unit-control/test/{utils.js → utils.ts} +38 -19
  174. package/src/unit-control/types.ts +4 -1
  175. package/src/unit-control/utils.ts +5 -3
  176. package/tsconfig.json +2 -1
  177. package/tsconfig.tsbuildinfo +1 -1
  178. package/build/box-control/visualizer.js +0 -165
  179. package/build/box-control/visualizer.js.map +0 -1
  180. package/build-module/box-control/visualizer.js +0 -154
  181. package/build-module/box-control/visualizer.js.map +0 -1
  182. package/src/box-control/visualizer.js +0 -116
  183. package/src/select-control/stories/index.js +0 -104
  184. package/src/text-control/index.js +0 -72
  185. package/src/text-control/stories/index.js +0 -46
@@ -7,21 +7,28 @@ import {
7
7
  getValidParsedQuantityAndUnit,
8
8
  getUnitsWithCurrentUnit,
9
9
  } from '../utils';
10
+ import type { WPUnitControlUnit } from '../types';
10
11
 
11
12
  describe( 'UnitControl utils', () => {
12
13
  describe( 'useCustomUnits', () => {
13
14
  it( 'should return filtered css units', () => {
14
- const cssUnits = [ { value: 'px' }, { value: '%' } ];
15
+ const cssUnits = [
16
+ { value: 'px', label: 'pixel' },
17
+ { value: '%', label: 'percent' },
18
+ ];
15
19
  const units = useCustomUnits( {
16
20
  availableUnits: [ 'em', 'px' ],
17
21
  units: cssUnits,
18
22
  } );
19
23
 
20
- expect( units ).toEqual( [ { value: 'px' } ] );
24
+ expect( units ).toEqual( [ { value: 'px', label: 'pixel' } ] );
21
25
  } );
22
26
 
23
27
  it( 'should add default values to available units', () => {
24
- const cssUnits = [ { value: 'px' }, { value: '%' } ];
28
+ const cssUnits = [
29
+ { value: 'px', label: 'pixel' },
30
+ { value: '%', label: 'percent' },
31
+ ];
25
32
  const units = useCustomUnits( {
26
33
  availableUnits: [ '%', 'px' ],
27
34
  defaultValues: { '%': 10, px: 10 },
@@ -29,8 +36,8 @@ describe( 'UnitControl utils', () => {
29
36
  } );
30
37
 
31
38
  expect( units ).toEqual( [
32
- { value: 'px', default: 10 },
33
- { value: '%', default: 10 },
39
+ { value: 'px', label: 'pixel', default: 10 },
40
+ { value: '%', label: 'percent', default: 10 },
34
41
  ] );
35
42
  } );
36
43
 
@@ -38,24 +45,32 @@ describe( 'UnitControl utils', () => {
38
45
  // Although the public APIs of the component expect a `number` as the type of the
39
46
  // default values, it's still good to test for strings (as it can happen in un-typed
40
47
  // environments)
41
- const cssUnits = [ { value: 'px' }, { value: '%' } ];
48
+ const cssUnits = [
49
+ { value: 'px', label: 'pixel' },
50
+ { value: '%', label: 'percent' },
51
+ ];
42
52
  const units = useCustomUnits( {
43
53
  availableUnits: [ '%', 'px' ],
44
54
  defaultValues: {
55
+ // @ts-expect-error (passing a string instead of a number is the point of the test)
45
56
  '%': '14',
57
+ // @ts-expect-error (passing a string instead of a number is the point of the test)
46
58
  px: 'not a valid numeric quantity',
47
59
  },
48
60
  units: cssUnits,
49
61
  } );
50
62
 
51
63
  expect( units ).toEqual( [
52
- { value: 'px', default: undefined },
53
- { value: '%', default: 14 },
64
+ { value: 'px', label: 'pixel', default: undefined },
65
+ { value: '%', label: 'percent', default: 14 },
54
66
  ] );
55
67
  } );
56
68
 
57
69
  it( 'should return an empty array where availableUnits match no preferred css units', () => {
58
- const cssUnits = [ { value: 'em' }, { value: 'vh' } ];
70
+ const cssUnits = [
71
+ { value: 'em', label: 'em' },
72
+ { value: 'vh', label: 'vh' },
73
+ ];
59
74
  const units = useCustomUnits( {
60
75
  availableUnits: [ '%', 'px' ],
61
76
  defaultValues: { '%': 10, px: 10 },
@@ -69,16 +84,19 @@ describe( 'UnitControl utils', () => {
69
84
  describe( 'filterUnitsWithSettings', () => {
70
85
  it( 'should return filtered units array', () => {
71
86
  const preferredUnits = [ '%', 'px' ];
72
- const availableUnits = [ { value: 'px' }, { value: 'em' } ];
87
+ const availableUnits = [
88
+ { value: 'px', label: 'pixel' },
89
+ { value: 'em', label: 'em' },
90
+ ];
73
91
 
74
92
  expect(
75
93
  filterUnitsWithSettings( preferredUnits, availableUnits )
76
- ).toEqual( [ { value: 'px' } ] );
94
+ ).toEqual( [ { value: 'px', label: 'pixel' } ] );
77
95
  } );
78
96
 
79
97
  it( 'should return empty array where preferred units match no available css unit', () => {
80
98
  const preferredUnits = [ '%', 'px' ];
81
- const availableUnits = [ { value: 'em' } ];
99
+ const availableUnits = [ { value: 'em', label: 'em' } ];
82
100
 
83
101
  expect(
84
102
  filterUnitsWithSettings( preferredUnits, availableUnits )
@@ -92,13 +110,14 @@ describe( 'UnitControl utils', () => {
92
110
  const availableUnits = false;
93
111
 
94
112
  expect(
113
+ // @ts-expect-error (passing `false` instead of a valid array of units is the point of the test)
95
114
  filterUnitsWithSettings( preferredUnits, availableUnits )
96
115
  ).toEqual( [] );
97
116
  } );
98
117
 
99
118
  it( 'should return empty array where available units is set to an empty array', () => {
100
119
  const preferredUnits = [ '%', 'px' ];
101
- const availableUnits = [];
120
+ const availableUnits: WPUnitControlUnit[] = [];
102
121
 
103
122
  expect(
104
123
  filterUnitsWithSettings( preferredUnits, availableUnits )
@@ -127,7 +146,7 @@ describe( 'UnitControl utils', () => {
127
146
 
128
147
  it( 'should return fallback value', () => {
129
148
  const nextValue = 'thirteen';
130
- const preferredUnits = [ { value: 'em' } ];
149
+ const preferredUnits = [ { value: 'em', label: 'em' } ];
131
150
  const fallbackValue = 13;
132
151
 
133
152
  expect(
@@ -155,7 +174,7 @@ describe( 'UnitControl utils', () => {
155
174
 
156
175
  it( 'should return first unit in preferred units collection as second fallback unit', () => {
157
176
  const nextValue = 101;
158
- const preferredUnits = [ { value: 'px' } ];
177
+ const preferredUnits = [ { value: 'px', label: 'pixel' } ];
159
178
 
160
179
  expect(
161
180
  getValidParsedQuantityAndUnit( nextValue, preferredUnits )
@@ -185,8 +204,8 @@ describe( 'UnitControl utils', () => {
185
204
  expect( result ).toHaveLength( 3 );
186
205
 
187
206
  const currentUnit = result.shift();
188
- expect( currentUnit.value ).toBe( '%' );
189
- expect( currentUnit.label ).toBe( '%' );
207
+ expect( currentUnit?.value ).toBe( '%' );
208
+ expect( currentUnit?.label ).toBe( '%' );
190
209
  expect( result ).toEqual( limitedUnits );
191
210
  } );
192
211
 
@@ -196,8 +215,8 @@ describe( 'UnitControl utils', () => {
196
215
  expect( result ).toHaveLength( 3 );
197
216
 
198
217
  const currentUnit = result.shift();
199
- expect( currentUnit.value ).toBe( '%' );
200
- expect( currentUnit.label ).toBe( '%' );
218
+ expect( currentUnit?.value ).toBe( '%' );
219
+ expect( currentUnit?.label ).toBe( '%' );
201
220
  expect( result ).toEqual( limitedUnits );
202
221
  } );
203
222
 
@@ -74,7 +74,10 @@ export type UnitSelectControlProps = {
74
74
 
75
75
  // TODO: when available, should (partially) extend `NumberControl` props.
76
76
  export type UnitControlProps = Omit< UnitSelectControlProps, 'unit' > &
77
- Pick< InputControlProps, 'hideLabelFromVision' > & {
77
+ Pick<
78
+ InputControlProps,
79
+ 'hideLabelFromVision' | '__next36pxDefaultSize'
80
+ > & {
78
81
  __unstableStateReducer?: StateReducer;
79
82
  __unstableInputWidth?: CSSProperties[ 'width' ];
80
83
  /**
@@ -155,7 +155,9 @@ export function getParsedQuantityAndUnit(
155
155
  * @param units List of units.
156
156
  * @return Whether the list actually contains any units.
157
157
  */
158
- export function hasUnits( units?: WPUnitControlUnit[] ): boolean {
158
+ export function hasUnits(
159
+ units?: WPUnitControlUnit[]
160
+ ): units is WPUnitControlUnit[] {
159
161
  // Although the `isArray` check shouldn't be necessary (given the signature of
160
162
  // this typed function), it's better to stay on the side of caution, since
161
163
  // this function may be called from un-typed environments.
@@ -218,7 +220,7 @@ export function parseQuantityAndUnitFromRawValue(
218
220
  */
219
221
  export function getValidParsedQuantityAndUnit(
220
222
  rawValue: string | number,
221
- allowedUnits: WPUnitControlUnit[],
223
+ allowedUnits?: WPUnitControlUnit[],
222
224
  fallbackQuantity?: number,
223
225
  fallbackUnit?: string
224
226
  ): [ number | undefined, string | undefined ] {
@@ -295,7 +297,7 @@ export const useCustomUnits = ( {
295
297
  }: {
296
298
  units?: WPUnitControlUnit[];
297
299
  availableUnits?: string[];
298
- defaultValues: Record< string, number >;
300
+ defaultValues?: Record< string, number >;
299
301
  } ): WPUnitControlUnit[] => {
300
302
  const customUnitsToReturn = filterUnitsWithSettings(
301
303
  availableUnits,
package/tsconfig.json CHANGED
@@ -8,7 +8,7 @@
8
8
  "gutenberg-test-env",
9
9
  "jest",
10
10
  "@testing-library/jest-dom",
11
- "snapshot-diff",
11
+ "snapshot-diff"
12
12
  ],
13
13
  // Some errors in Reakit types with TypeScript 4.3
14
14
  // Remove the following line when they've been addressed.
@@ -77,6 +77,7 @@
77
77
  "src/spinner/**/*",
78
78
  "src/surface/**/*",
79
79
  "src/text/**/*",
80
+ "src/text-control/**/*",
80
81
  "src/tip/**/*",
81
82
  "src/toggle-group-control/**/*",
82
83
  "src/tools-panel/**/*",