@wordpress/components 21.1.2-next.4d3b314fd5.0 → 21.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +14 -1
- package/build/border-box-control/utils.js +42 -2
- package/build/border-box-control/utils.js.map +1 -1
- package/build/combobox-control/index.js +0 -1
- package/build/combobox-control/index.js.map +1 -1
- package/build/custom-select-control/index.js +4 -2
- package/build/custom-select-control/index.js.map +1 -1
- package/build/font-size-picker/index.js +46 -55
- package/build/font-size-picker/index.js.map +1 -1
- package/build/font-size-picker/styles.js +73 -0
- package/build/font-size-picker/styles.js.map +1 -0
- package/build/font-size-picker/types.js +6 -0
- package/build/font-size-picker/types.js.map +1 -0
- package/build/font-size-picker/utils.js +17 -15
- package/build/font-size-picker/utils.js.map +1 -1
- package/build/form-token-field/token-input.js +20 -1
- package/build/form-token-field/token-input.js.map +1 -1
- package/build/index.js +6 -0
- package/build/index.js.map +1 -1
- package/build/navigator/navigator-screen/component.js +8 -1
- package/build/navigator/navigator-screen/component.js.map +1 -1
- package/build/resizable-box/resize-tooltip/utils.js +12 -14
- package/build/resizable-box/resize-tooltip/utils.js.map +1 -1
- package/build/sandbox/index.js +13 -8
- package/build/sandbox/index.js.map +1 -1
- package/build/sandbox/index.native.js +3 -1
- package/build/sandbox/index.native.js.map +1 -1
- package/build/search-control/index.native.js +6 -2
- package/build/search-control/index.native.js.map +1 -1
- package/build/slot-fill/bubbles-virtually/slot-fill-context.js +8 -2
- package/build/slot-fill/bubbles-virtually/slot-fill-context.js.map +1 -1
- package/build/slot-fill/bubbles-virtually/slot-fill-provider.js +31 -41
- package/build/slot-fill/bubbles-virtually/slot-fill-provider.js.map +1 -1
- package/build/slot-fill/bubbles-virtually/use-slot-fills.js +39 -0
- package/build/slot-fill/bubbles-virtually/use-slot-fills.js.map +1 -0
- package/build/slot-fill/bubbles-virtually/use-slot.js +13 -4
- package/build/slot-fill/bubbles-virtually/use-slot.js.map +1 -1
- package/build/slot-fill/index.js +8 -0
- package/build/slot-fill/index.js.map +1 -1
- package/build/toggle-group-control/toggle-group-control-option-base/styles.js +8 -8
- package/build/toggle-group-control/toggle-group-control-option-base/styles.js.map +1 -1
- package/build-module/border-box-control/utils.js +36 -1
- package/build-module/border-box-control/utils.js.map +1 -1
- package/build-module/combobox-control/index.js +0 -1
- package/build-module/combobox-control/index.js.map +1 -1
- package/build-module/custom-select-control/index.js +2 -1
- package/build-module/custom-select-control/index.js.map +1 -1
- package/build-module/font-size-picker/index.js +45 -53
- package/build-module/font-size-picker/index.js.map +1 -1
- package/build-module/font-size-picker/styles.js +62 -0
- package/build-module/font-size-picker/styles.js.map +1 -0
- package/build-module/font-size-picker/types.js +2 -0
- package/build-module/font-size-picker/types.js.map +1 -0
- package/build-module/font-size-picker/utils.js +21 -15
- package/build-module/font-size-picker/utils.js.map +1 -1
- package/build-module/form-token-field/token-input.js +21 -2
- package/build-module/form-token-field/token-input.js.map +1 -1
- package/build-module/index.js +1 -1
- package/build-module/index.js.map +1 -1
- package/build-module/navigator/navigator-screen/component.js +8 -1
- package/build-module/navigator/navigator-screen/component.js.map +1 -1
- package/build-module/resizable-box/resize-tooltip/utils.js +13 -15
- package/build-module/resizable-box/resize-tooltip/utils.js.map +1 -1
- package/build-module/sandbox/index.js +13 -8
- package/build-module/sandbox/index.js.map +1 -1
- package/build-module/sandbox/index.native.js +3 -1
- package/build-module/sandbox/index.native.js.map +1 -1
- package/build-module/search-control/index.native.js +6 -2
- package/build-module/search-control/index.native.js.map +1 -1
- package/build-module/slot-fill/bubbles-virtually/slot-fill-context.js +7 -2
- package/build-module/slot-fill/bubbles-virtually/slot-fill-context.js.map +1 -1
- package/build-module/slot-fill/bubbles-virtually/slot-fill-provider.js +30 -42
- package/build-module/slot-fill/bubbles-virtually/slot-fill-provider.js.map +1 -1
- package/build-module/slot-fill/bubbles-virtually/use-slot-fills.js +27 -0
- package/build-module/slot-fill/bubbles-virtually/use-slot-fills.js.map +1 -0
- package/build-module/slot-fill/bubbles-virtually/use-slot.js +13 -5
- package/build-module/slot-fill/bubbles-virtually/use-slot.js.map +1 -1
- package/build-module/slot-fill/index.js +1 -0
- package/build-module/slot-fill/index.js.map +1 -1
- package/build-module/toggle-group-control/toggle-group-control-option-base/styles.js +7 -7
- package/build-module/toggle-group-control/toggle-group-control-option-base/styles.js.map +1 -1
- package/build-style/style-rtl.css +1 -98
- package/build-style/style.css +1 -98
- package/build-types/border-box-control/utils.d.ts +1 -3
- package/build-types/border-box-control/utils.d.ts.map +1 -1
- package/build-types/custom-select-control/index.d.ts +13 -0
- package/build-types/custom-select-control/index.d.ts.map +1 -0
- package/build-types/custom-select-control/styles.d.ts +9 -0
- package/build-types/custom-select-control/styles.d.ts.map +1 -0
- package/build-types/font-size-picker/index.d.ts +5 -0
- package/build-types/font-size-picker/index.d.ts.map +1 -0
- package/build-types/font-size-picker/stories/e2e/index.d.ts +16 -0
- package/build-types/font-size-picker/stories/e2e/index.d.ts.map +1 -0
- package/build-types/font-size-picker/stories/index.d.ts +31 -0
- package/build-types/font-size-picker/stories/index.d.ts.map +1 -0
- package/build-types/font-size-picker/styles.d.ts +27 -0
- package/build-types/font-size-picker/styles.d.ts.map +1 -0
- package/build-types/font-size-picker/test/index.d.ts +2 -0
- package/build-types/font-size-picker/test/index.d.ts.map +1 -0
- package/build-types/font-size-picker/test/utils.d.ts +2 -0
- package/build-types/font-size-picker/test/utils.d.ts.map +1 -0
- package/build-types/font-size-picker/types.d.ts +93 -0
- package/build-types/font-size-picker/types.d.ts.map +1 -0
- package/build-types/font-size-picker/utils.d.ts +41 -0
- package/build-types/font-size-picker/utils.d.ts.map +1 -0
- package/build-types/form-token-field/token-input.d.ts.map +1 -1
- package/build-types/navigator/navigator-screen/component.d.ts.map +1 -1
- package/build-types/slot-fill/bubbles-virtually/slot-fill-context.d.ts +2 -2
- package/build-types/slot-fill/bubbles-virtually/slot-fill-context.d.ts.map +1 -1
- package/build-types/slot-fill/bubbles-virtually/slot-fill-provider.d.ts.map +1 -1
- package/build-types/slot-fill/bubbles-virtually/use-slot-fills.d.ts +2 -0
- package/build-types/slot-fill/bubbles-virtually/use-slot-fills.d.ts.map +1 -0
- package/build-types/slot-fill/bubbles-virtually/use-slot.d.ts.map +1 -1
- package/build-types/slot-fill/index.d.ts +1 -0
- package/build-types/slot-fill/index.d.ts.map +1 -1
- package/build-types/toggle-group-control/toggle-group-control-option-base/styles.d.ts +1 -1
- package/build-types/toggle-group-control/toggle-group-control-option-base/styles.d.ts.map +1 -1
- package/package.json +19 -18
- package/src/alignment-matrix-control/test/index.js +17 -62
- package/src/border-box-control/test/utils.js +48 -0
- package/src/border-box-control/utils.ts +44 -1
- package/src/combobox-control/index.js +0 -5
- package/src/custom-select-control/index.js +2 -1
- package/src/font-size-picker/{index.js → index.tsx} +113 -79
- package/src/font-size-picker/stories/e2e/{index.js → index.tsx} +13 -4
- package/src/font-size-picker/stories/{index.js → index.tsx} +42 -36
- package/src/font-size-picker/styles.ts +44 -0
- package/src/font-size-picker/test/{index.js → index.tsx} +1 -1
- package/src/font-size-picker/test/{utils.js → utils.ts} +6 -2
- package/src/font-size-picker/types.ts +98 -0
- package/src/font-size-picker/{utils.js → utils.ts} +51 -27
- package/src/form-token-field/test/index.tsx +22 -1
- package/src/form-token-field/token-input.tsx +25 -3
- package/src/index.js +1 -0
- package/src/navigator/navigator-screen/component.tsx +8 -1
- package/src/navigator/test/index.js +119 -54
- package/src/placeholder/style.scss +2 -2
- package/src/resizable-box/resize-tooltip/utils.ts +13 -13
- package/src/sandbox/index.js +13 -7
- package/src/sandbox/index.native.js +3 -0
- package/src/search-control/index.native.js +6 -0
- package/src/slot-fill/bubbles-virtually/slot-fill-context.js +6 -2
- package/src/slot-fill/bubbles-virtually/slot-fill-provider.js +51 -58
- package/src/slot-fill/bubbles-virtually/use-slot-fills.js +24 -0
- package/src/slot-fill/bubbles-virtually/use-slot.js +11 -6
- package/src/slot-fill/index.js +1 -0
- package/src/style.scss +0 -1
- package/src/toggle-group-control/test/__snapshots__/index.tsx.snap +1 -0
- package/src/toggle-group-control/toggle-group-control-option-base/styles.ts +9 -7
- package/tsconfig.json +0 -2
- package/tsconfig.tsbuildinfo +1 -1
- package/src/font-size-picker/style.scss +0 -78
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* External dependencies
|
|
3
3
|
*/
|
|
4
|
-
import
|
|
4
|
+
import type { ReactNode, ForwardedRef } from 'react';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* WordPress dependencies
|
|
@@ -14,7 +14,6 @@ import { useState, useMemo, forwardRef } from '@wordpress/element';
|
|
|
14
14
|
/**
|
|
15
15
|
* Internal dependencies
|
|
16
16
|
*/
|
|
17
|
-
import { BaseControl } from '../base-control';
|
|
18
17
|
import Button from '../button';
|
|
19
18
|
import RangeControl from '../range-control';
|
|
20
19
|
import { Flex, FlexItem } from '../flex';
|
|
@@ -34,31 +33,50 @@ import {
|
|
|
34
33
|
} from './utils';
|
|
35
34
|
import { VStack } from '../v-stack';
|
|
36
35
|
import { HStack } from '../h-stack';
|
|
36
|
+
import type {
|
|
37
|
+
FontSizePickerProps,
|
|
38
|
+
FontSizeSelectOption,
|
|
39
|
+
FontSizeToggleGroupOption,
|
|
40
|
+
} from './types';
|
|
41
|
+
import {
|
|
42
|
+
Container,
|
|
43
|
+
HeaderHint,
|
|
44
|
+
HeaderLabel,
|
|
45
|
+
Controls,
|
|
46
|
+
ResetButton,
|
|
47
|
+
} from './styles';
|
|
48
|
+
import { Spacer } from '../spacer';
|
|
37
49
|
|
|
38
50
|
// This conditional is needed to maintain the spacing before the slider in the `withSlider` case.
|
|
39
|
-
const MaybeVStack = ( {
|
|
51
|
+
const MaybeVStack = ( {
|
|
52
|
+
__nextHasNoMarginBottom,
|
|
53
|
+
children,
|
|
54
|
+
}: {
|
|
55
|
+
__nextHasNoMarginBottom: boolean;
|
|
56
|
+
children: ReactNode;
|
|
57
|
+
} ) =>
|
|
40
58
|
! __nextHasNoMarginBottom ? (
|
|
41
|
-
children
|
|
59
|
+
<>{ children }</>
|
|
42
60
|
) : (
|
|
43
61
|
<VStack spacing={ 6 } children={ children } />
|
|
44
62
|
);
|
|
45
63
|
|
|
46
|
-
|
|
47
|
-
|
|
64
|
+
const UnforwardedFontSizePicker = (
|
|
65
|
+
props: FontSizePickerProps,
|
|
66
|
+
ref: ForwardedRef< any >
|
|
67
|
+
) => {
|
|
68
|
+
const {
|
|
48
69
|
/** Start opting into the new margin-free styles that will become the default in a future version. */
|
|
49
70
|
__nextHasNoMarginBottom = false,
|
|
50
71
|
fallbackFontSize,
|
|
51
72
|
fontSizes = [],
|
|
52
73
|
disableCustomFontSizes = false,
|
|
53
74
|
onChange,
|
|
54
|
-
/** @type {'default' | '__unstable-large'} */
|
|
55
75
|
size = 'default',
|
|
56
76
|
value,
|
|
57
77
|
withSlider = false,
|
|
58
78
|
withReset = true,
|
|
59
|
-
}
|
|
60
|
-
ref
|
|
61
|
-
) {
|
|
79
|
+
} = props;
|
|
62
80
|
if ( ! __nextHasNoMarginBottom ) {
|
|
63
81
|
deprecated( 'Bottom margin styles for wp.components.FontSizePicker', {
|
|
64
82
|
since: '6.1',
|
|
@@ -70,7 +88,7 @@ function FontSizePicker(
|
|
|
70
88
|
const hasUnits = [ typeof value, typeof fontSizes?.[ 0 ]?.size ].includes(
|
|
71
89
|
'string'
|
|
72
90
|
);
|
|
73
|
-
const noUnitsValue = ! hasUnits ? value : parseInt( value );
|
|
91
|
+
const noUnitsValue = ! hasUnits ? value : parseInt( String( value ) );
|
|
74
92
|
const isPixelValue = typeof value === 'number' || value?.endsWith?.( 'px' );
|
|
75
93
|
const units = useCustomUnits( {
|
|
76
94
|
availableUnits: [ 'px', 'em', 'rem' ],
|
|
@@ -106,10 +124,15 @@ function FontSizePicker(
|
|
|
106
124
|
// If we have a custom value that is not available in the font sizes,
|
|
107
125
|
// show it as a hint as long as it's a simple CSS value.
|
|
108
126
|
if ( isCustomValue ) {
|
|
109
|
-
return
|
|
127
|
+
return (
|
|
128
|
+
value !== undefined &&
|
|
129
|
+
isSimpleCssValue( value ) &&
|
|
130
|
+
`(${ value })`
|
|
131
|
+
);
|
|
110
132
|
}
|
|
111
133
|
if ( shouldUseSelectControl ) {
|
|
112
134
|
return (
|
|
135
|
+
selectedOption?.size !== undefined &&
|
|
113
136
|
isSimpleCssValue( selectedOption?.size ) &&
|
|
114
137
|
`(${ selectedOption?.size })`
|
|
115
138
|
);
|
|
@@ -146,59 +169,65 @@ function FontSizePicker(
|
|
|
146
169
|
__( 'Currently selected font size: %s' ),
|
|
147
170
|
selectedOption.name
|
|
148
171
|
);
|
|
149
|
-
const baseClassName = 'components-font-size-picker';
|
|
150
172
|
return (
|
|
151
|
-
<
|
|
173
|
+
<Container ref={ ref } className="components-font-size-picker">
|
|
152
174
|
<VisuallyHidden as="legend">{ __( 'Font size' ) }</VisuallyHidden>
|
|
153
|
-
<
|
|
154
|
-
<
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
175
|
+
<Spacer>
|
|
176
|
+
<HStack className="components-font-size-picker__header">
|
|
177
|
+
<HeaderLabel>
|
|
178
|
+
{ __( 'Size' ) }
|
|
179
|
+
{ headerHint && (
|
|
180
|
+
<HeaderHint className="components-font-size-picker__header__hint">
|
|
181
|
+
{ headerHint }
|
|
182
|
+
</HeaderHint>
|
|
183
|
+
) }
|
|
184
|
+
</HeaderLabel>
|
|
185
|
+
{ ! disableCustomFontSizes && (
|
|
186
|
+
<Button
|
|
187
|
+
label={
|
|
188
|
+
showCustomValueControl
|
|
189
|
+
? __( 'Use size preset' )
|
|
190
|
+
: __( 'Set custom size' )
|
|
191
|
+
}
|
|
192
|
+
icon={ settings }
|
|
193
|
+
onClick={ () => {
|
|
194
|
+
setShowCustomValueControl(
|
|
195
|
+
! showCustomValueControl
|
|
196
|
+
);
|
|
197
|
+
} }
|
|
198
|
+
isPressed={ showCustomValueControl }
|
|
199
|
+
isSmall
|
|
200
|
+
/>
|
|
160
201
|
) }
|
|
161
|
-
</
|
|
162
|
-
|
|
163
|
-
<Button
|
|
164
|
-
label={
|
|
165
|
-
showCustomValueControl
|
|
166
|
-
? __( 'Use size preset' )
|
|
167
|
-
: __( 'Set custom size' )
|
|
168
|
-
}
|
|
169
|
-
icon={ settings }
|
|
170
|
-
onClick={ () => {
|
|
171
|
-
setShowCustomValueControl(
|
|
172
|
-
! showCustomValueControl
|
|
173
|
-
);
|
|
174
|
-
} }
|
|
175
|
-
isPressed={ showCustomValueControl }
|
|
176
|
-
isSmall
|
|
177
|
-
/>
|
|
178
|
-
) }
|
|
179
|
-
</HStack>
|
|
202
|
+
</HStack>
|
|
203
|
+
</Spacer>
|
|
180
204
|
<MaybeVStack __nextHasNoMarginBottom={ __nextHasNoMarginBottom }>
|
|
181
|
-
<
|
|
182
|
-
className=
|
|
183
|
-
|
|
184
|
-
} ) }
|
|
205
|
+
<Controls
|
|
206
|
+
className="components-font-size-picker__controls"
|
|
207
|
+
__nextHasNoMarginBottom={ __nextHasNoMarginBottom }
|
|
185
208
|
>
|
|
186
209
|
{ !! fontSizes.length &&
|
|
187
210
|
shouldUseSelectControl &&
|
|
188
211
|
! showCustomValueControl && (
|
|
189
212
|
<CustomSelectControl
|
|
190
213
|
__nextUnconstrainedWidth
|
|
191
|
-
className=
|
|
214
|
+
className="components-font-size-picker__select"
|
|
192
215
|
label={ __( 'Font size' ) }
|
|
193
216
|
hideLabelFromVision
|
|
194
217
|
describedBy={ currentFontSizeSR }
|
|
195
|
-
options={ options }
|
|
196
|
-
value={
|
|
218
|
+
options={ options as FontSizeSelectOption[] }
|
|
219
|
+
value={ (
|
|
220
|
+
options as FontSizeSelectOption[]
|
|
221
|
+
).find(
|
|
197
222
|
( option ) =>
|
|
198
223
|
option.key === selectedOption.slug
|
|
199
224
|
) }
|
|
200
|
-
onChange={ ( {
|
|
201
|
-
|
|
225
|
+
onChange={ ( {
|
|
226
|
+
selectedItem,
|
|
227
|
+
}: {
|
|
228
|
+
selectedItem: FontSizeSelectOption;
|
|
229
|
+
} ) => {
|
|
230
|
+
onChange?.(
|
|
202
231
|
hasUnits
|
|
203
232
|
? selectedItem.size
|
|
204
233
|
: Number( selectedItem.size )
|
|
@@ -219,31 +248,30 @@ function FontSizePicker(
|
|
|
219
248
|
hideLabelFromVision
|
|
220
249
|
value={ value }
|
|
221
250
|
onChange={ ( newValue ) => {
|
|
222
|
-
onChange(
|
|
251
|
+
onChange?.(
|
|
223
252
|
hasUnits ? newValue : Number( newValue )
|
|
224
253
|
);
|
|
225
254
|
} }
|
|
226
255
|
isBlock
|
|
227
256
|
size={ size }
|
|
228
257
|
>
|
|
229
|
-
{
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
258
|
+
{ ( options as FontSizeToggleGroupOption[] ).map(
|
|
259
|
+
( option ) => (
|
|
260
|
+
<ToggleGroupControlOption
|
|
261
|
+
key={ option.key }
|
|
262
|
+
value={ option.value }
|
|
263
|
+
label={ option.label }
|
|
264
|
+
aria-label={ option.name }
|
|
265
|
+
showTooltip={ true }
|
|
266
|
+
/>
|
|
267
|
+
)
|
|
268
|
+
) }
|
|
238
269
|
</ToggleGroupControl>
|
|
239
270
|
) }
|
|
240
271
|
{ ! withSlider &&
|
|
241
272
|
! disableCustomFontSizes &&
|
|
242
273
|
showCustomValueControl && (
|
|
243
|
-
<Flex
|
|
244
|
-
justify="space-between"
|
|
245
|
-
className={ `${ baseClassName }__custom-size-control` }
|
|
246
|
-
>
|
|
274
|
+
<Flex className="components-font-size-picker__custom-size-control">
|
|
247
275
|
<FlexItem isBlock>
|
|
248
276
|
<UnitControl
|
|
249
277
|
label={ __( 'Custom' ) }
|
|
@@ -252,12 +280,12 @@ function FontSizePicker(
|
|
|
252
280
|
value={ value }
|
|
253
281
|
onChange={ ( nextSize ) => {
|
|
254
282
|
if (
|
|
255
|
-
|
|
256
|
-
|
|
283
|
+
! nextSize ||
|
|
284
|
+
0 === parseFloat( nextSize )
|
|
257
285
|
) {
|
|
258
|
-
onChange( undefined );
|
|
286
|
+
onChange?.( undefined );
|
|
259
287
|
} else {
|
|
260
|
-
onChange(
|
|
288
|
+
onChange?.(
|
|
261
289
|
hasUnits
|
|
262
290
|
? nextSize
|
|
263
291
|
: parseInt(
|
|
@@ -272,40 +300,46 @@ function FontSizePicker(
|
|
|
272
300
|
/>
|
|
273
301
|
</FlexItem>
|
|
274
302
|
{ withReset && (
|
|
275
|
-
<FlexItem
|
|
276
|
-
<
|
|
277
|
-
className="components-color-palette__clear"
|
|
303
|
+
<FlexItem>
|
|
304
|
+
<ResetButton
|
|
278
305
|
disabled={ value === undefined }
|
|
279
306
|
onClick={ () => {
|
|
280
|
-
onChange( undefined );
|
|
307
|
+
onChange?.( undefined );
|
|
281
308
|
} }
|
|
282
309
|
isSmall
|
|
283
310
|
variant="secondary"
|
|
311
|
+
size={ size }
|
|
284
312
|
>
|
|
285
313
|
{ __( 'Reset' ) }
|
|
286
|
-
</
|
|
314
|
+
</ResetButton>
|
|
287
315
|
</FlexItem>
|
|
288
316
|
) }
|
|
289
317
|
</Flex>
|
|
290
318
|
) }
|
|
291
|
-
</
|
|
319
|
+
</Controls>
|
|
292
320
|
{ withSlider && (
|
|
293
321
|
<RangeControl
|
|
294
322
|
__nextHasNoMarginBottom={ __nextHasNoMarginBottom }
|
|
295
|
-
className=
|
|
323
|
+
className="components-font-size-picker__custom-input"
|
|
296
324
|
label={ __( 'Custom Size' ) }
|
|
297
|
-
value={
|
|
325
|
+
value={
|
|
326
|
+
isPixelValue && noUnitsValue
|
|
327
|
+
? Number( noUnitsValue )
|
|
328
|
+
: undefined
|
|
329
|
+
}
|
|
298
330
|
initialPosition={ fallbackFontSize }
|
|
299
331
|
onChange={ ( newValue ) => {
|
|
300
|
-
onChange( hasUnits ? newValue + 'px' : newValue );
|
|
332
|
+
onChange?.( hasUnits ? newValue + 'px' : newValue );
|
|
301
333
|
} }
|
|
302
334
|
min={ 12 }
|
|
303
335
|
max={ 100 }
|
|
304
336
|
/>
|
|
305
337
|
) }
|
|
306
338
|
</MaybeVStack>
|
|
307
|
-
</
|
|
339
|
+
</Container>
|
|
308
340
|
);
|
|
309
|
-
}
|
|
341
|
+
};
|
|
342
|
+
|
|
343
|
+
export const FontSizePicker = forwardRef( UnforwardedFontSizePicker );
|
|
310
344
|
|
|
311
|
-
export default
|
|
345
|
+
export default FontSizePicker;
|
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* External dependencies
|
|
3
|
+
*/
|
|
4
|
+
import type { ComponentStory } from '@storybook/react';
|
|
5
|
+
|
|
1
6
|
/**
|
|
2
7
|
* WordPress dependencies
|
|
3
8
|
*/
|
|
@@ -13,8 +18,11 @@ export default {
|
|
|
13
18
|
component: FontSizePicker,
|
|
14
19
|
};
|
|
15
20
|
|
|
16
|
-
const FontSizePickerWithState
|
|
17
|
-
|
|
21
|
+
const FontSizePickerWithState: ComponentStory< typeof FontSizePicker > = ( {
|
|
22
|
+
value,
|
|
23
|
+
...props
|
|
24
|
+
} ) => {
|
|
25
|
+
const [ fontSize, setFontSize ] = useState( value );
|
|
18
26
|
return (
|
|
19
27
|
<FontSizePicker
|
|
20
28
|
{ ...props }
|
|
@@ -24,7 +32,8 @@ const FontSizePickerWithState = ( { initialValue, ...props } ) => {
|
|
|
24
32
|
);
|
|
25
33
|
};
|
|
26
34
|
|
|
27
|
-
export const Default
|
|
35
|
+
export const Default: ComponentStory< typeof FontSizePicker > =
|
|
36
|
+
FontSizePickerWithState.bind( {} );
|
|
28
37
|
Default.args = {
|
|
29
38
|
fontSizes: [
|
|
30
39
|
{
|
|
@@ -43,5 +52,5 @@ Default.args = {
|
|
|
43
52
|
size: 26,
|
|
44
53
|
},
|
|
45
54
|
],
|
|
46
|
-
|
|
55
|
+
value: 16,
|
|
47
56
|
};
|
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* External dependencies
|
|
3
|
+
*/
|
|
4
|
+
import type { ComponentMeta, ComponentStory } from '@storybook/react';
|
|
5
|
+
|
|
1
6
|
/**
|
|
2
7
|
* WordPress dependencies
|
|
3
8
|
*/
|
|
@@ -8,53 +13,48 @@ import { useState } from '@wordpress/element';
|
|
|
8
13
|
*/
|
|
9
14
|
import FontSizePicker from '../';
|
|
10
15
|
|
|
11
|
-
|
|
16
|
+
const meta: ComponentMeta< typeof FontSizePicker > = {
|
|
12
17
|
title: 'Components/FontSizePicker',
|
|
13
18
|
component: FontSizePicker,
|
|
14
19
|
argTypes: {
|
|
15
|
-
|
|
16
|
-
fallbackFontSize: {
|
|
17
|
-
description:
|
|
18
|
-
'If no value exists, this prop defines the starting position for the font size picker slider. Only relevant if `withSlider` is `true`.',
|
|
19
|
-
},
|
|
20
|
-
size: {
|
|
21
|
-
control: { type: 'radio' },
|
|
22
|
-
options: [ 'default', '__unstable-large' ],
|
|
23
|
-
},
|
|
24
|
-
withReset: {
|
|
25
|
-
description:
|
|
26
|
-
'If `true`, a reset button will be displayed alongside the input field when a custom font size is active. Has no effect when `disableCustomFontSizes` or `withSlider` is `true`.',
|
|
27
|
-
control: { type: 'boolean' },
|
|
28
|
-
table: {
|
|
29
|
-
type: 'boolean',
|
|
30
|
-
defaultValue: { summary: true },
|
|
31
|
-
},
|
|
32
|
-
},
|
|
20
|
+
value: { control: { type: null } },
|
|
33
21
|
},
|
|
34
22
|
parameters: {
|
|
23
|
+
actions: { argTypesRegex: '^on.*' },
|
|
35
24
|
controls: { expanded: true },
|
|
36
25
|
docs: { source: { state: 'open' } },
|
|
37
26
|
},
|
|
38
27
|
};
|
|
28
|
+
export default meta;
|
|
39
29
|
|
|
40
|
-
const FontSizePickerWithState
|
|
41
|
-
|
|
30
|
+
const FontSizePickerWithState: ComponentStory< typeof FontSizePicker > = ( {
|
|
31
|
+
value,
|
|
32
|
+
onChange,
|
|
33
|
+
...props
|
|
34
|
+
} ) => {
|
|
35
|
+
const [ fontSize, setFontSize ] = useState( value );
|
|
42
36
|
return (
|
|
43
37
|
<FontSizePicker
|
|
44
38
|
{ ...props }
|
|
45
39
|
value={ fontSize }
|
|
46
|
-
onChange={
|
|
40
|
+
onChange={ ( nextValue ) => {
|
|
41
|
+
setFontSize( nextValue );
|
|
42
|
+
onChange?.( nextValue );
|
|
43
|
+
} }
|
|
47
44
|
/>
|
|
48
45
|
);
|
|
49
46
|
};
|
|
50
47
|
|
|
51
|
-
const TwoFontSizePickersWithState
|
|
48
|
+
const TwoFontSizePickersWithState: ComponentStory< typeof FontSizePicker > = ( {
|
|
49
|
+
fontSizes,
|
|
50
|
+
...props
|
|
51
|
+
} ) => {
|
|
52
52
|
return (
|
|
53
53
|
<>
|
|
54
54
|
<h2>Fewer font sizes</h2>
|
|
55
55
|
<FontSizePickerWithState
|
|
56
56
|
{ ...props }
|
|
57
|
-
fontSizes={ fontSizes
|
|
57
|
+
fontSizes={ fontSizes?.slice( 0, 4 ) }
|
|
58
58
|
/>
|
|
59
59
|
|
|
60
60
|
<h2>More font sizes</h2>
|
|
@@ -63,7 +63,8 @@ const TwoFontSizePickersWithState = ( { fontSizes, ...props } ) => {
|
|
|
63
63
|
);
|
|
64
64
|
};
|
|
65
65
|
|
|
66
|
-
export const Default
|
|
66
|
+
export const Default: ComponentStory< typeof FontSizePicker > =
|
|
67
|
+
FontSizePickerWithState.bind( {} );
|
|
67
68
|
Default.args = {
|
|
68
69
|
__nextHasNoMarginBottom: true,
|
|
69
70
|
disableCustomFontSizes: false,
|
|
@@ -84,15 +85,16 @@ Default.args = {
|
|
|
84
85
|
size: 26,
|
|
85
86
|
},
|
|
86
87
|
],
|
|
87
|
-
|
|
88
|
+
value: 16,
|
|
88
89
|
withSlider: false,
|
|
89
90
|
};
|
|
90
91
|
|
|
91
|
-
export const WithSlider
|
|
92
|
+
export const WithSlider: ComponentStory< typeof FontSizePicker > =
|
|
93
|
+
FontSizePickerWithState.bind( {} );
|
|
92
94
|
WithSlider.args = {
|
|
93
95
|
...Default.args,
|
|
94
96
|
fallbackFontSize: 16,
|
|
95
|
-
|
|
97
|
+
value: undefined,
|
|
96
98
|
withSlider: true,
|
|
97
99
|
};
|
|
98
100
|
|
|
@@ -100,7 +102,8 @@ WithSlider.args = {
|
|
|
100
102
|
* With custom font sizes disabled via the `disableCustomFontSizes` prop, the user will
|
|
101
103
|
* only be able to pick one of the predefined sizes passed in `fontSizes`.
|
|
102
104
|
*/
|
|
103
|
-
export const WithCustomSizesDisabled
|
|
105
|
+
export const WithCustomSizesDisabled: ComponentStory< typeof FontSizePicker > =
|
|
106
|
+
FontSizePickerWithState.bind( {} );
|
|
104
107
|
WithCustomSizesDisabled.args = {
|
|
105
108
|
...Default.args,
|
|
106
109
|
disableCustomFontSizes: true,
|
|
@@ -109,7 +112,8 @@ WithCustomSizesDisabled.args = {
|
|
|
109
112
|
/**
|
|
110
113
|
* When there are more than 5 font size options, the UI is no longer a toggle group.
|
|
111
114
|
*/
|
|
112
|
-
export const WithMoreFontSizes
|
|
115
|
+
export const WithMoreFontSizes: ComponentStory< typeof FontSizePicker > =
|
|
116
|
+
FontSizePickerWithState.bind( {} );
|
|
113
117
|
WithMoreFontSizes.args = {
|
|
114
118
|
...Default.args,
|
|
115
119
|
fontSizes: [
|
|
@@ -144,27 +148,29 @@ WithMoreFontSizes.args = {
|
|
|
144
148
|
size: 36,
|
|
145
149
|
},
|
|
146
150
|
],
|
|
147
|
-
|
|
151
|
+
value: 8,
|
|
148
152
|
};
|
|
149
153
|
|
|
150
154
|
/**
|
|
151
155
|
* When units like `px` are specified explicitly, it will be shown as a label hint.
|
|
152
156
|
*/
|
|
153
|
-
export const WithUnits
|
|
157
|
+
export const WithUnits: ComponentStory< typeof FontSizePicker > =
|
|
158
|
+
TwoFontSizePickersWithState.bind( {} );
|
|
154
159
|
WithUnits.args = {
|
|
155
160
|
...WithMoreFontSizes.args,
|
|
156
|
-
fontSizes: WithMoreFontSizes.args.fontSizes
|
|
161
|
+
fontSizes: WithMoreFontSizes.args.fontSizes?.map( ( option ) => ( {
|
|
157
162
|
...option,
|
|
158
163
|
size: `${ option.size }px`,
|
|
159
164
|
} ) ),
|
|
160
|
-
|
|
165
|
+
value: '8px',
|
|
161
166
|
};
|
|
162
167
|
|
|
163
168
|
/**
|
|
164
169
|
* The label hint will not be shown if it is a complex CSS value. Some examples of complex CSS values
|
|
165
170
|
* in this context are CSS functions like `calc()`, `clamp()`, and `var()`.
|
|
166
171
|
*/
|
|
167
|
-
export const WithComplexCSSValues
|
|
172
|
+
export const WithComplexCSSValues: ComponentStory< typeof FontSizePicker > =
|
|
173
|
+
TwoFontSizePickersWithState.bind( {} );
|
|
168
174
|
WithComplexCSSValues.args = {
|
|
169
175
|
...Default.args,
|
|
170
176
|
fontSizes: [
|
|
@@ -200,5 +206,5 @@ WithComplexCSSValues.args = {
|
|
|
200
206
|
size: '2.8rem',
|
|
201
207
|
},
|
|
202
208
|
],
|
|
203
|
-
|
|
209
|
+
value: '1.125rem',
|
|
204
210
|
};
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* External dependencies
|
|
3
|
+
*/
|
|
4
|
+
import styled from '@emotion/styled';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Internal dependencies
|
|
8
|
+
*/
|
|
9
|
+
import BaseControl from '../base-control';
|
|
10
|
+
import Button from '../button';
|
|
11
|
+
import { space } from '../ui/utils/space';
|
|
12
|
+
import { COLORS } from '../utils';
|
|
13
|
+
import type { FontSizePickerProps } from './types';
|
|
14
|
+
|
|
15
|
+
export const Container = styled.fieldset`
|
|
16
|
+
border: 0;
|
|
17
|
+
margin: 0;
|
|
18
|
+
padding: 0;
|
|
19
|
+
`;
|
|
20
|
+
|
|
21
|
+
export const HeaderLabel = styled( BaseControl.VisualLabel )`
|
|
22
|
+
margin-bottom: 0;
|
|
23
|
+
`;
|
|
24
|
+
|
|
25
|
+
export const HeaderHint = styled.span`
|
|
26
|
+
color: ${ COLORS.gray[ 700 ] };
|
|
27
|
+
margin-left: ${ space( 1 ) };
|
|
28
|
+
`;
|
|
29
|
+
|
|
30
|
+
export const Controls = styled.div< {
|
|
31
|
+
__nextHasNoMarginBottom: boolean;
|
|
32
|
+
} >`
|
|
33
|
+
${ ( props ) =>
|
|
34
|
+
! props.__nextHasNoMarginBottom && `margin-bottom: ${ space( 6 ) };` }
|
|
35
|
+
`;
|
|
36
|
+
|
|
37
|
+
export const ResetButton = styled( Button )< {
|
|
38
|
+
size: FontSizePickerProps[ 'size' ];
|
|
39
|
+
} >`
|
|
40
|
+
&&& {
|
|
41
|
+
height: ${ ( props ) =>
|
|
42
|
+
props.size === '__unstable-large' ? '40px' : '30px' };
|
|
43
|
+
}
|
|
44
|
+
`;
|
|
@@ -13,7 +13,7 @@ const getUnitSelect = () =>
|
|
|
13
13
|
const getUnitLabel = () =>
|
|
14
14
|
document.body.querySelector( '.components-unit-control__unit-label' );
|
|
15
15
|
|
|
16
|
-
const toggleCustomInput = ( showCustomInput ) => {
|
|
16
|
+
const toggleCustomInput = ( showCustomInput: boolean ) => {
|
|
17
17
|
const label = showCustomInput ? 'Set custom size' : 'Use size preset';
|
|
18
18
|
const toggleCustom = screen.getByLabelText( label, { selector: 'button' } );
|
|
19
19
|
fireEvent.click( toggleCustom );
|
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
getToggleGroupOptions,
|
|
8
8
|
} from '../utils';
|
|
9
9
|
|
|
10
|
-
const simpleCSSCases = [
|
|
10
|
+
const simpleCSSCases: [ number | string, boolean ][] = [
|
|
11
11
|
// Test integers and non-integers.
|
|
12
12
|
[ 1, true ],
|
|
13
13
|
[ 1.25, true ],
|
|
@@ -41,7 +41,11 @@ describe( 'isSimpleCssValue', () => {
|
|
|
41
41
|
);
|
|
42
42
|
} );
|
|
43
43
|
|
|
44
|
-
const splitValuesCases
|
|
44
|
+
const splitValuesCases: [
|
|
45
|
+
number | string,
|
|
46
|
+
string | undefined,
|
|
47
|
+
string | undefined
|
|
48
|
+
][] = [
|
|
45
49
|
// Test integers and non-integers.
|
|
46
50
|
[ 1, '1', undefined ],
|
|
47
51
|
[ 1.25, '1.25', undefined ],
|