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

Add compact size variant to InputControl-based components #57398

Merged
merged 2 commits into from
Jan 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/components/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
- `DropdownMenuV2`: do not collapse suffix width ([#57238](https://github.com/WordPress/gutenberg/pull/57238)).
- `DateTimePicker`: Adjustment of the dot position on DayButton and expansion of the button area. ([#55502](https://github.com/WordPress/gutenberg/pull/55502)).
- `Modal`: Improve application of body class names ([#55430](https://github.com/WordPress/gutenberg/pull/55430)).
- `InputControl`, `NumberControl`, `UnitControl`, `SelectControl`, `TreeSelect`: Add `compact` size variant ([#57398](https://github.com/WordPress/gutenberg/pull/57398)).
- `ToggleGroupControl`: Update button size in large variant to be 32px ([#57338](https://github.com/WordPress/gutenberg/pull/57338)).

### Experimental
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,11 @@ const disabledStyles = ( { disabled }: InputProps ) => {
} );
};

const fontSizeStyles = ( { inputSize: size }: InputProps ) => {
export const fontSizeStyles = ( { inputSize: size }: InputProps ) => {
const sizes = {
default: '13px',
small: '11px',
compact: '13px',
'__unstable-large': '13px',
};

Expand Down Expand Up @@ -138,6 +139,13 @@ export const getSizeConfig = ( {
paddingLeft: space( 2 ),
paddingRight: space( 2 ),
},
compact: {
height: 32,
lineHeight: 1,
minHeight: 32,
paddingLeft: space( 2 ),
paddingRight: space( 2 ),
},
'__unstable-large': {
height: 40,
lineHeight: 1,
Expand All @@ -148,13 +156,7 @@ export const getSizeConfig = ( {
};

if ( ! __next40pxDefaultSize ) {
sizes.default = {
height: 32,
lineHeight: 1,
minHeight: 32,
paddingLeft: space( 2 ),
paddingRight: space( 2 ),
};
sizes.default = sizes.compact;
}

return sizes[ size as Size ] || sizes.default;
Expand Down
2 changes: 1 addition & 1 deletion packages/components/src/input-control/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export type DragDirection = 'n' | 's' | 'e' | 'w';

export type DragProps = Parameters< Parameters< typeof useDrag >[ 0 ] >[ 0 ];

export type Size = 'default' | 'small' | '__unstable-large';
export type Size = 'default' | 'small' | 'compact' | '__unstable-large';

interface BaseProps {
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { COLORS, rtl } from '../../utils';
import { space } from '../../utils/space';
import type { SelectControlProps } from '../types';
import InputControlSuffixWrapper from '../../input-control/input-suffix-wrapper';
import { fontSizeStyles } from '../../input-control/styles/input-control-styles';

interface SelectProps
extends Pick<
Expand All @@ -30,27 +31,6 @@ const disabledStyles = ( { disabled }: SelectProps ) => {
} );
};

const fontSizeStyles = ( { selectSize = 'default' }: SelectProps ) => {
const sizes = {
default: '13px',
small: '11px',
'__unstable-large': '13px',
};

const fontSize = sizes[ selectSize ];
const fontSizeMobile = '16px';

if ( ! fontSize ) return '';

return css`
font-size: ${ fontSizeMobile };

@media ( min-width: 600px ) {
font-size: ${ fontSize };
}
`;
};
Comment on lines -33 to -52
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice 🧹


const sizeStyles = ( {
__next40pxDefaultSize,
multiple,
Expand All @@ -75,6 +55,12 @@ const sizeStyles = ( {
paddingTop: 0,
paddingBottom: 0,
},
compact: {
height: 32,
minHeight: 32,
paddingTop: 0,
paddingBottom: 0,
},
'__unstable-large': {
height: 40,
minHeight: 40,
Expand All @@ -84,12 +70,7 @@ const sizeStyles = ( {
};

if ( ! __next40pxDefaultSize ) {
sizes.default = {
height: 32,
minHeight: 32,
paddingTop: 0,
paddingBottom: 0,
};
sizes.default = sizes.compact;
}

const style = sizes[ selectSize ] || sizes.default;
Expand All @@ -107,11 +88,12 @@ const sizePaddings = ( {
const padding = {
default: 16,
small: 8,
compact: 8,
'__unstable-large': 16,
};

if ( ! __next40pxDefaultSize ) {
padding.default = 8;
padding.default = padding.compact;
}

const selectedPadding = padding[ selectSize ] || padding.default;
Expand Down
2 changes: 1 addition & 1 deletion packages/components/src/unit-control/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ function UnforwardedUnitControl(
isUnitSelectTabbable={ isUnitSelectTabbable }
onChange={ handleOnUnitChange }
size={
size === 'small' ||
[ 'small', 'compact' ].includes( size ) ||
( size === 'default' && ! props.__next40pxDefaultSize )
? 'small'
: 'default'
Expand Down
Loading