Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ToggleGroupControl: Update large button size to 32px #57338

Merged
merged 4 commits into from
Dec 25, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,13 @@ const isIconStyles = ( {
}: Pick< ToggleGroupControlProps, 'size' > ) => {
const iconButtonSizes = {
default: '30px',
'__unstable-large': '34px',
'__unstable-large': '32px',
};

return css`
color: ${ COLORS.gray[ 900 ] };
width: ${ iconButtonSizes[ size ] };
height: ${ iconButtonSizes[ size ] };
mirka marked this conversation as resolved.
Show resolved Hide resolved
padding-left: 0;
padding-right: 0;
`;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ function UnconnectedToggleGroupControl(
} = useContextSystem( props, 'ToggleGroupControl' );

const baseId = useInstanceId( ToggleGroupControl, 'toggle-group-control' );
const normalizedSize =
__next40pxDefaultSize && size === 'default' ? '__unstable-large' : size;
Comment on lines +50 to +51
Copy link
Member Author

Choose a reason for hiding this comment

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

We usually don't do this kind of preemptive size normalization in other components, but in this specific case it was a lot cleaner this way. Otherwise we'd have to drill the prop down to multiple subcomponents, touching a handful of more files.

Copy link
Contributor

Choose a reason for hiding this comment

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

Agreed. We should be able to clean this up after the migration is over and we remove temporary props and size values


const cx = useCx();

Expand All @@ -56,13 +58,12 @@ function UnconnectedToggleGroupControl(
styles.toggleGroupControl( {
isBlock,
isDeselectable,
size,
__next40pxDefaultSize,
size: normalizedSize,
} ),
isBlock && styles.block,
className
),
[ className, cx, isBlock, isDeselectable, size, __next40pxDefaultSize ]
[ className, cx, isBlock, isDeselectable, normalizedSize ]
);

const MainControl = isDeselectable
Expand All @@ -86,7 +87,7 @@ function UnconnectedToggleGroupControl(
label={ label }
onChange={ onChange }
ref={ forwardedRef }
size={ size }
size={ normalizedSize }
value={ value }
>
<LayoutGroup id={ baseId }>{ children }</LayoutGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,17 @@ export const toggleGroupControl = ( {
isBlock,
isDeselectable,
size,
__next40pxDefaultSize,
}: Pick<
ToggleGroupControlProps,
'isBlock' | 'isDeselectable' | '__next40pxDefaultSize'
> & {
}: Pick< ToggleGroupControlProps, 'isBlock' | 'isDeselectable' > & {
size: NonNullable< ToggleGroupControlProps[ 'size' ] >;
} ) => css`
background: ${ COLORS.ui.background };
border: 1px solid transparent;
border-radius: ${ CONFIG.controlBorderRadius };
display: inline-flex;
min-width: 0;
padding: 2px;
position: relative;

${ toggleGroupControlSize( size, __next40pxDefaultSize ) }
${ toggleGroupControlSize( size ) }
${ ! isDeselectable && enclosingBorders( isBlock ) }
`;

Expand Down Expand Up @@ -57,21 +52,20 @@ const enclosingBorders = ( isBlock: ToggleGroupControlProps[ 'isBlock' ] ) => {
};

export const toggleGroupControlSize = (
size: NonNullable< ToggleGroupControlProps[ 'size' ] >,
__next40pxDefaultSize: ToggleGroupControlProps[ '__next40pxDefaultSize' ]
size: NonNullable< ToggleGroupControlProps[ 'size' ] >
) => {
const heights = {
default: '40px',
'__unstable-large': '40px',
const styles = {
default: css`
min-height: 36px;
padding: 2px;
`,
'__unstable-large': css`
min-height: 40px;
padding: 3px;
`,
Comment on lines +57 to +65
Copy link
Member Author

Choose a reason for hiding this comment

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

I am tempted to simplify this down to a

if ( size === 'default` ) {
  return css`/* ... */`;
}
return css`/* ... */`;

but I'm going to keep this size variant object around because I think we'll be asked to make a 32px compact size variant soon.

};

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

return css`
min-height: ${ heights[ size ] };
`;
return styles[ size ];
};

export const block = css`
Expand Down