Skip to content

Commit

Permalink
ToggleGroupControl: Add opt-in prop for 40px default size (#55789)
Browse files Browse the repository at this point in the history
* `ToggleGroupControl`: Add opt-in prop for 40px default size

* Update changelog
  • Loading branch information
brookewp authored Nov 6, 2023
1 parent 90d5306 commit f4389b9
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 6 deletions.
4 changes: 4 additions & 0 deletions packages/components/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@

- Migrate `Divider` from `reakit` to `ariakit` ([#55622](https://github.com/WordPress/gutenberg/pull/55622))

### Enhancements

- `ToggleGroupControl`: Add opt-in prop for 40px default size ([#55789](https://github.com/WordPress/gutenberg/pull/55789)).

## 25.11.0 (2023-11-02)

### Enhancements
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ function UnconnectedToggleGroupControl(
) {
const {
__nextHasNoMarginBottom = false,
__next40pxDefaultSize = false,
className,
isAdaptiveWidth = false,
isBlock = false,
Expand All @@ -52,11 +53,16 @@ function UnconnectedToggleGroupControl(
const classes = useMemo(
() =>
cx(
styles.toggleGroupControl( { isBlock, isDeselectable, size } ),
styles.toggleGroupControl( {
isBlock,
isDeselectable,
size,
__next40pxDefaultSize,
} ),
isBlock && styles.block,
className
),
[ className, cx, isBlock, isDeselectable, size ]
[ className, cx, isBlock, isDeselectable, size, __next40pxDefaultSize ]
);

const MainControl = isDeselectable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@ export const toggleGroupControl = ( {
isBlock,
isDeselectable,
size,
}: Pick< ToggleGroupControlProps, 'isBlock' | 'isDeselectable' > & {
__next40pxDefaultSize,
}: Pick<
ToggleGroupControlProps,
'isBlock' | 'isDeselectable' | '__next40pxDefaultSize'
> & {
size: NonNullable< ToggleGroupControlProps[ 'size' ] >;
} ) => css`
background: ${ COLORS.ui.background };
Expand All @@ -25,7 +29,7 @@ export const toggleGroupControl = ( {
padding: 2px;
position: relative;
${ toggleGroupControlSize( size ) }
${ toggleGroupControlSize( size, __next40pxDefaultSize ) }
${ ! isDeselectable && enclosingBorders( isBlock ) }
`;

Expand Down Expand Up @@ -53,13 +57,18 @@ const enclosingBorders = ( isBlock: ToggleGroupControlProps[ 'isBlock' ] ) => {
};

export const toggleGroupControlSize = (
size: NonNullable< ToggleGroupControlProps[ 'size' ] >
size: NonNullable< ToggleGroupControlProps[ 'size' ] >,
__next40pxDefaultSize: ToggleGroupControlProps[ '__next40pxDefaultSize' ]
) => {
const heights = {
default: '36px',
default: '40px',
'__unstable-large': '40px',
};

if ( ! __next40pxDefaultSize ) {
heights.default = '36px';
}

return css`
min-height: ${ heights[ size ] };
`;
Expand Down
6 changes: 6 additions & 0 deletions packages/components/src/toggle-group-control/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,12 @@ export type ToggleGroupControlProps = Pick<
* @default 'default'
*/
size?: 'default' | '__unstable-large';
/**
* Start opting into the larger default height that will become the default size in a future version.
*
* @default false
*/
__next40pxDefaultSize?: boolean;
};

export type ToggleGroupControlContextProps = {
Expand Down

1 comment on commit f4389b9

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Flaky tests detected in f4389b9.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/6777417978
📝 Reported issues:

Please sign in to comment.