Skip to content

Commit

Permalink
Components: Add opt-in prop for 40px default size for BoxControl, `…
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
brookewp authored Jan 15, 2024
1 parent 71da85a commit 464961e
Show file tree
Hide file tree
Showing 12 changed files with 45 additions and 5 deletions.
1 change: 1 addition & 0 deletions packages/components/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
- `Tooltip`: no-op when nested inside other `Tooltip` components ([#57202](https://github.com/WordPress/gutenberg/pull/57202)).
- `PaletteEdit`: improve unit tests ([#57645](https://github.com/WordPress/gutenberg/pull/57645)).
- `ColorPalette` and `CircularOptionPicker`: improve unit tests ([#57809](https://github.com/WordPress/gutenberg/pull/57809)).
- `BoxControl`, `BorderControl`, `BorderBoxControl`: Add opt-in prop for 40px default size ([#56185](https://github.com/WordPress/gutenberg/pull/56185)).

### Experimental

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ const UnconnectedBorderBoxControl = (
);

const mergedRef = useMergeRefs( [ setPopoverAnchor, forwardedRef ] );

return (
<View className={ className } { ...otherProps } ref={ mergedRef }>
<BorderLabel
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,13 @@ export function useBorderBoxControl(
size = 'default',
value,
__experimentalIsRenderedInSidebar = false,
__next40pxDefaultSize,
...otherProps
} = useContextSystem( props, 'BorderBoxControl' );

const computedSize =
size === 'default' && __next40pxDefaultSize ? '__unstable-large' : size;

const mixedBorders = hasMixedBorders( value );
const splitBorders = hasSplitBorders( value );

Expand Down Expand Up @@ -133,7 +137,7 @@ export function useBorderBoxControl(
onSplitChange,
toggleLinked,
linkedValue,
size,
size: computedSize,
splitValue,
wrapperClassName,
__experimentalIsRenderedInSidebar,
Expand Down
6 changes: 6 additions & 0 deletions packages/components/src/border-box-control/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ export type BorderBoxControlProps = ColorProps &
* properties but for each side; `top`, `right`, `bottom`, and `left`.
*/
value: AnyBorder;
/**
* Start opting into the larger default height that will become the default size in a future version.
*
* @default false
*/
__next40pxDefaultSize?: boolean;
};

export type LinkedButtonProps = Pick< BorderBoxControlProps, 'size' > & {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ const UnconnectedBorderControl = (
forwardedRef: React.ForwardedRef< any >
) => {
const {
__next40pxDefaultSize = false,
colors,
disableCustomColors,
disableUnits,
Expand Down Expand Up @@ -112,6 +113,7 @@ const UnconnectedBorderControl = (
step={ [ 'px', '%' ].includes( widthUnit ) ? 1 : 0.1 }
value={ widthValue || undefined }
withInputField={ false }
__next40pxDefaultSize={ __next40pxDefaultSize }
/>
) }
</HStack>
Expand Down
11 changes: 8 additions & 3 deletions packages/components/src/border-control/border-control/hook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,13 @@ export function useBorderControl(
value: border,
width,
__experimentalIsRenderedInSidebar = false,
__next40pxDefaultSize,
...otherProps
} = useContextSystem( props, 'BorderControl' );

const computedSize =
size === 'default' && __next40pxDefaultSize ? '__unstable-large' : size;

const [ widthValue, originalWidthUnit ] = parseQuantityAndUnitFromRawValue(
border?.width
);
Expand Down Expand Up @@ -130,10 +134,10 @@ export function useBorderControl(
}
const innerWrapperClassName = useMemo( () => {
const widthStyle = !! wrapperWidth && styles.wrapperWidth;
const heightStyle = styles.wrapperHeight( size );
const heightStyle = styles.wrapperHeight( computedSize );

return cx( styles.innerWrapper(), widthStyle, heightStyle );
}, [ wrapperWidth, cx, size ] );
}, [ wrapperWidth, cx, computedSize ] );

const sliderClassName = useMemo( () => {
return cx( styles.borderSlider() );
Expand All @@ -155,7 +159,8 @@ export function useBorderControl(
value: border,
widthUnit,
widthValue,
size,
size: computedSize,
__experimentalIsRenderedInSidebar,
__next40pxDefaultSize,
};
}
6 changes: 6 additions & 0 deletions packages/components/src/border-control/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,12 @@ export type BorderControlProps = ColorProps &
* `RangeControl` for additional control over a border's width.
*/
withSlider?: boolean;
/**
* Start opting into the larger default height that will become the default size in a future version.
*
* @default false
*/
__next40pxDefaultSize?: boolean;
};

export type DropdownProps = ColorProps &
Expand Down
3 changes: 3 additions & 0 deletions packages/components/src/box-control/all-input-control.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import {
const noop = () => {};

export default function AllInputControl( {
__next40pxDefaultSize,
onChange = noop,
onFocus = noop,
values,
Expand Down Expand Up @@ -74,6 +75,7 @@ export default function AllInputControl( {
<HStack>
<StyledUnitControl
{ ...props }
__next40pxDefaultSize={ __next40pxDefaultSize }
className="component-box-control__unit-control"
disableUnits={ isMixed }
id={ inputId }
Expand All @@ -89,6 +91,7 @@ export default function AllInputControl( {

<FlexedRangeControl
__nextHasNoMarginBottom
__next40pxDefaultSize={ __next40pxDefaultSize }
aria-controls={ inputId }
label={ LABELS.all }
hideLabelFromVision
Expand Down
3 changes: 3 additions & 0 deletions packages/components/src/box-control/axial-input-controls.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const groupedSides = [ 'vertical', 'horizontal' ] as const;
type GroupedSide = ( typeof groupedSides )[ number ];

export default function AxialInputControls( {
__next40pxDefaultSize,
onChange,
onFocus,
values,
Expand Down Expand Up @@ -105,6 +106,7 @@ export default function AxialInputControls( {
<Tooltip placement="top-end" text={ LABELS[ side ] }>
<StyledUnitControl
{ ...props }
__next40pxDefaultSize={ __next40pxDefaultSize }
className="component-box-control__unit-control"
id={ inputId }
isPressEnterToChange
Expand All @@ -126,6 +128,7 @@ export default function AxialInputControls( {
</Tooltip>
<FlexedRangeControl
__nextHasNoMarginBottom
__next40pxDefaultSize={ __next40pxDefaultSize }
aria-controls={ inputId }
label={ LABELS[ side ] }
hideLabelFromVision
Expand Down
2 changes: 2 additions & 0 deletions packages/components/src/box-control/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ function useUniqueId( idProp?: string ) {
* ```
*/
function BoxControl( {
__next40pxDefaultSize = false,
id: idProp,
inputProps = defaultInputProps,
onChange = noop,
Expand Down Expand Up @@ -151,6 +152,7 @@ function BoxControl( {
values: inputValues,
onMouseOver,
onMouseOut,
__next40pxDefaultSize,
};

return (
Expand Down
3 changes: 3 additions & 0 deletions packages/components/src/box-control/input-controls.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import type { BoxControlInputControlProps, BoxControlValue } from './types';
const noop = () => {};

export default function BoxInputControls( {
__next40pxDefaultSize,
onChange = noop,
onFocus = noop,
values,
Expand Down Expand Up @@ -107,6 +108,7 @@ export default function BoxInputControls( {
<Tooltip placement="top-end" text={ LABELS[ side ] }>
<StyledUnitControl
{ ...props }
__next40pxDefaultSize={ __next40pxDefaultSize }
className="component-box-control__unit-control"
id={ inputId }
isPressEnterToChange
Expand All @@ -131,6 +133,7 @@ export default function BoxInputControls( {

<FlexedRangeControl
__nextHasNoMarginBottom
__next40pxDefaultSize={ __next40pxDefaultSize }
aria-controls={ inputId }
label={ LABELS[ side ] }
hideLabelFromVision
Expand Down
6 changes: 6 additions & 0 deletions packages/components/src/box-control/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,12 @@ export type BoxControlProps = Pick<
* The current values of the control, expressed as an object of `top`, `right`, `bottom`, and `left` values.
*/
values?: BoxControlValue;
/**
* Start opting into the larger default height that will become the default size in a future version.
*
* @default false
*/
__next40pxDefaultSize?: boolean;
};

export type BoxControlInputControlProps = UnitControlPassthroughProps & {
Expand Down

0 comments on commit 464961e

Please sign in to comment.