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

CustomSelectControl: Add flag for larger default size #39401

Merged
merged 6 commits into from
Mar 21, 2022
Merged
Show file tree
Hide file tree
Changes from 3 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 @@ -10,6 +10,7 @@
- `InputControl`: Allow `onBlur` for empty values to commit the change when `isPressEnterToChange` is true, and move reset behavior to the ESCAPE key. ([#39109](https://github.com/WordPress/gutenberg/pull/39109)).
- `TreeGrid`: Add tests for Home/End keyboard navigation. Add `onFocusRow` callback for Home/End keyboard navigation, this was missed in the implementation PR. Modify test for expanding/collapsing a row as row 1 implements this now. Update README with latest changes. ([#39302](https://github.com/WordPress/gutenberg/pull/39302))
- `ToggleGroupControlOption`: Calculate width from button content and remove `LabelPlaceholderView` ([#39345](https://github.com/WordPress/gutenberg/pull/39345))
- `CustomSelectControl`: Add `__next36pxDefaultSize` flag for larger default size ([#39401](https://github.com/WordPress/gutenberg/pull/39401)).

### Bug Fix

Expand Down
10 changes: 8 additions & 2 deletions packages/components/src/custom-select-control/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ const stateReducer = (
}
};
export default function CustomSelectControl( {
/** Start opting into the larger default height that will become the default size in a future version. */
__next36pxDefaultSize = false,
className,
hideLabelFromVision,
label,
Expand Down Expand Up @@ -141,8 +143,11 @@ export default function CustomSelectControl( {
// This is needed because some speech recognition software don't support `aria-labelledby`.
'aria-label': label,
'aria-labelledby': undefined,
className: 'components-custom-select-control__button',
isSmall: true,
className: classnames(
'components-custom-select-control__button',
{ 'is-next-36px-default-size': __next36pxDefaultSize }
),
isSmall: ! __next36pxDefaultSize,
Copy link
Contributor

Choose a reason for hiding this comment

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

Love it when we rely on composability instead of style overrides

describedBy: getDescribedBy(),
} ) }
>
Expand All @@ -169,6 +174,7 @@ export default function CustomSelectControl( {
'is-highlighted':
index === highlightedIndex,
'has-hint': !! item.__experimentalHint,
'is-next-36px-default-size': __next36pxDefaultSize,
}
),
style: item.style,
Expand Down
151 changes: 77 additions & 74 deletions packages/components/src/custom-select-control/stories/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,81 +6,84 @@ import CustomSelectControl from '../';
export default {
title: 'Components/CustomSelectControl',
component: CustomSelectControl,
};

const defaultOptions = [
{
key: 'small',
name: 'Small',
style: { fontSize: '50%' },
},
{
key: 'normal',
name: 'Normal',
style: { fontSize: '100%' },
className: 'can-apply-custom-class-to-option',
},
{
key: 'large',
name: 'Large',
style: { fontSize: '200%' },
},
{
key: 'huge',
name: 'Huge',
style: { fontSize: '300%' },
},
];
export const _default = () => (
<CustomSelectControl label="Font size" options={ defaultOptions } />
);

const longLabelOptions = [
{
key: 'reallylonglabel1',
name: 'Really long labels are good for stress testing',
},
{
key: 'reallylonglabel2',
name: 'But they can take a long time to type.',
},
{
key: 'reallylonglabel3',
name:
'That really is ok though because you should stress test your UIs.',
argTypes: {
__next36pxDefaultSize: {
control: { type: 'boolean' },
},
},
];
};

export const longLabels = () => (
<CustomSelectControl
label="Testing long labels"
options={ longLabelOptions }
/>
);
export const Default = CustomSelectControl.bind( {} );
Default.args = {
label: 'Label',
options: [
{
key: 'small',
name: 'Small',
style: { fontSize: '50%' },
},
{
key: 'normal',
name: 'Normal',
style: { fontSize: '100%' },
className: 'can-apply-custom-class-to-option',
},
{
key: 'large',
name: 'Large',
style: { fontSize: '200%' },
},
{
key: 'huge',
name: 'Huge',
style: { fontSize: '300%' },
},
],
};

const withHintsOptions = [
{
key: 'thumbnail',
name: 'Thumbnail',
__experimentalHint: '150x150',
},
{
key: 'medium',
name: 'Medium',
__experimentalHint: '250x250',
},
{
key: 'large',
name: 'Large',
__experimentalHint: '1024x1024',
},
{
key: 'full',
name: 'Full Size',
__experimentalHint: '1600x1600',
},
];
export const WithLongLabels = CustomSelectControl.bind( {} );
WithLongLabels.args = {
...Default.args,
options: [
{
key: 'reallylonglabel1',
name: 'Really long labels are good for stress testing',
},
{
key: 'reallylonglabel2',
name: 'But they can take a long time to type.',
},
{
key: 'reallylonglabel3',
name:
'That really is ok though because you should stress test your UIs.',
},
],
};

export const hints = () => (
<CustomSelectControl label="Testing hints" options={ withHintsOptions } />
);
export const WithHints = CustomSelectControl.bind( {} );
WithHints.args = {
...Default.args,
options: [
{
key: 'thumbnail',
name: 'Thumbnail',
__experimentalHint: '150x150',
},
{
key: 'medium',
name: 'Medium',
__experimentalHint: '250x250',
},
{
key: 'large',
name: 'Large',
__experimentalHint: '1024x1024',
},
{
key: 'full',
name: 'Full Size',
__experimentalHint: '1600x1600',
},
],
};
17 changes: 14 additions & 3 deletions packages/components/src/custom-select-control/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,22 @@
.components-custom-select-control__button {
border: 1px solid $gray-700;
border-radius: $radius-block-ui;
min-height: 30px;
min-width: 130px;
position: relative;
text-align: left;

&:not(.is-next-36px-default-size) {
min-height: 30px;
}

// For all button sizes allow sufficient space for the
// dropdown "arrow" icon to display.
&.components-custom-select-control__button {
padding-right: $icon-size;
padding-right: $icon-size + $grid-unit-05;

&:not(.is-next-36px-default-size) {
padding-right: $icon-size;
}
}

&:focus:not(:disabled) {
Expand Down Expand Up @@ -61,10 +68,14 @@
display: grid;
grid-template-columns: auto auto;
list-style-type: none;
padding: $grid-unit-10;
padding: $grid-unit-10 $grid-unit-15;
cursor: default;
line-height: $icon-size + $grid-unit-05;

&:not(.is-next-36px-default-size) {
padding: $grid-unit-10;
}

&.has-hint {
grid-template-columns: auto auto 30px;
}
Expand Down