Skip to content

Commit 464961e

Browse files
authored
Components: Add opt-in prop for 40px default size for BoxControl, BorderControl, and BorderBoxControl (#56185)
* Add 40px size to BoxControl * Add 40px size to BorderControl * Add 40px size to BorderBoxControl * Move logic to hook for BorderControl * Move logic to hook for `BorderBoxControl` * Update changelog
1 parent 71da85a commit 464961e

File tree

12 files changed

+45
-5
lines changed

12 files changed

+45
-5
lines changed

packages/components/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
- `Tooltip`: no-op when nested inside other `Tooltip` components ([#57202](https://github.com/WordPress/gutenberg/pull/57202)).
3838
- `PaletteEdit`: improve unit tests ([#57645](https://github.com/WordPress/gutenberg/pull/57645)).
3939
- `ColorPalette` and `CircularOptionPicker`: improve unit tests ([#57809](https://github.com/WordPress/gutenberg/pull/57809)).
40+
- `BoxControl`, `BorderControl`, `BorderBoxControl`: Add opt-in prop for 40px default size ([#56185](https://github.com/WordPress/gutenberg/pull/56185)).
4041

4142
### Experimental
4243

packages/components/src/border-box-control/border-box-control/component.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,6 @@ const UnconnectedBorderBoxControl = (
8989
);
9090

9191
const mergedRef = useMergeRefs( [ setPopoverAnchor, forwardedRef ] );
92-
9392
return (
9493
<View className={ className } { ...otherProps } ref={ mergedRef }>
9594
<BorderLabel

packages/components/src/border-box-control/border-box-control/hook.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,13 @@ export function useBorderBoxControl(
3535
size = 'default',
3636
value,
3737
__experimentalIsRenderedInSidebar = false,
38+
__next40pxDefaultSize,
3839
...otherProps
3940
} = useContextSystem( props, 'BorderBoxControl' );
4041

42+
const computedSize =
43+
size === 'default' && __next40pxDefaultSize ? '__unstable-large' : size;
44+
4145
const mixedBorders = hasMixedBorders( value );
4246
const splitBorders = hasSplitBorders( value );
4347

@@ -133,7 +137,7 @@ export function useBorderBoxControl(
133137
onSplitChange,
134138
toggleLinked,
135139
linkedValue,
136-
size,
140+
size: computedSize,
137141
splitValue,
138142
wrapperClassName,
139143
__experimentalIsRenderedInSidebar,

packages/components/src/border-box-control/types.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,12 @@ export type BorderBoxControlProps = ColorProps &
4545
* properties but for each side; `top`, `right`, `bottom`, and `left`.
4646
*/
4747
value: AnyBorder;
48+
/**
49+
* Start opting into the larger default height that will become the default size in a future version.
50+
*
51+
* @default false
52+
*/
53+
__next40pxDefaultSize?: boolean;
4854
};
4955

5056
export type LinkedButtonProps = Pick< BorderBoxControlProps, 'size' > & {

packages/components/src/border-control/border-control/component.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ const UnconnectedBorderControl = (
3838
forwardedRef: React.ForwardedRef< any >
3939
) => {
4040
const {
41+
__next40pxDefaultSize = false,
4142
colors,
4243
disableCustomColors,
4344
disableUnits,
@@ -112,6 +113,7 @@ const UnconnectedBorderControl = (
112113
step={ [ 'px', '%' ].includes( widthUnit ) ? 1 : 0.1 }
113114
value={ widthValue || undefined }
114115
withInputField={ false }
116+
__next40pxDefaultSize={ __next40pxDefaultSize }
115117
/>
116118
) }
117119
</HStack>

packages/components/src/border-control/border-control/hook.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,13 @@ export function useBorderControl(
4141
value: border,
4242
width,
4343
__experimentalIsRenderedInSidebar = false,
44+
__next40pxDefaultSize,
4445
...otherProps
4546
} = useContextSystem( props, 'BorderControl' );
4647

48+
const computedSize =
49+
size === 'default' && __next40pxDefaultSize ? '__unstable-large' : size;
50+
4751
const [ widthValue, originalWidthUnit ] = parseQuantityAndUnitFromRawValue(
4852
border?.width
4953
);
@@ -130,10 +134,10 @@ export function useBorderControl(
130134
}
131135
const innerWrapperClassName = useMemo( () => {
132136
const widthStyle = !! wrapperWidth && styles.wrapperWidth;
133-
const heightStyle = styles.wrapperHeight( size );
137+
const heightStyle = styles.wrapperHeight( computedSize );
134138

135139
return cx( styles.innerWrapper(), widthStyle, heightStyle );
136-
}, [ wrapperWidth, cx, size ] );
140+
}, [ wrapperWidth, cx, computedSize ] );
137141

138142
const sliderClassName = useMemo( () => {
139143
return cx( styles.borderSlider() );
@@ -155,7 +159,8 @@ export function useBorderControl(
155159
value: border,
156160
widthUnit,
157161
widthValue,
158-
size,
162+
size: computedSize,
159163
__experimentalIsRenderedInSidebar,
164+
__next40pxDefaultSize,
160165
};
161166
}

packages/components/src/border-control/types.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,12 @@ export type BorderControlProps = ColorProps &
9999
* `RangeControl` for additional control over a border's width.
100100
*/
101101
withSlider?: boolean;
102+
/**
103+
* Start opting into the larger default height that will become the default size in a future version.
104+
*
105+
* @default false
106+
*/
107+
__next40pxDefaultSize?: boolean;
102108
};
103109

104110
export type DropdownProps = ColorProps &

packages/components/src/box-control/all-input-control.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import {
2525
const noop = () => {};
2626

2727
export default function AllInputControl( {
28+
__next40pxDefaultSize,
2829
onChange = noop,
2930
onFocus = noop,
3031
values,
@@ -74,6 +75,7 @@ export default function AllInputControl( {
7475
<HStack>
7576
<StyledUnitControl
7677
{ ...props }
78+
__next40pxDefaultSize={ __next40pxDefaultSize }
7779
className="component-box-control__unit-control"
7880
disableUnits={ isMixed }
7981
id={ inputId }
@@ -89,6 +91,7 @@ export default function AllInputControl( {
8991

9092
<FlexedRangeControl
9193
__nextHasNoMarginBottom
94+
__next40pxDefaultSize={ __next40pxDefaultSize }
9295
aria-controls={ inputId }
9396
label={ LABELS.all }
9497
hideLabelFromVision

packages/components/src/box-control/axial-input-controls.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ const groupedSides = [ 'vertical', 'horizontal' ] as const;
2020
type GroupedSide = ( typeof groupedSides )[ number ];
2121

2222
export default function AxialInputControls( {
23+
__next40pxDefaultSize,
2324
onChange,
2425
onFocus,
2526
values,
@@ -105,6 +106,7 @@ export default function AxialInputControls( {
105106
<Tooltip placement="top-end" text={ LABELS[ side ] }>
106107
<StyledUnitControl
107108
{ ...props }
109+
__next40pxDefaultSize={ __next40pxDefaultSize }
108110
className="component-box-control__unit-control"
109111
id={ inputId }
110112
isPressEnterToChange
@@ -126,6 +128,7 @@ export default function AxialInputControls( {
126128
</Tooltip>
127129
<FlexedRangeControl
128130
__nextHasNoMarginBottom
131+
__next40pxDefaultSize={ __next40pxDefaultSize }
129132
aria-controls={ inputId }
130133
label={ LABELS[ side ] }
131134
hideLabelFromVision

packages/components/src/box-control/index.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ function useUniqueId( idProp?: string ) {
7272
* ```
7373
*/
7474
function BoxControl( {
75+
__next40pxDefaultSize = false,
7576
id: idProp,
7677
inputProps = defaultInputProps,
7778
onChange = noop,
@@ -151,6 +152,7 @@ function BoxControl( {
151152
values: inputValues,
152153
onMouseOver,
153154
onMouseOut,
155+
__next40pxDefaultSize,
154156
};
155157

156158
return (

0 commit comments

Comments
 (0)