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: Use __unstableSize prop in Typography panel #36162

Closed
wants to merge 5 commits into from
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ export default function FontAppearanceControl( props ) {
hasStylesOrWeights && (
<CustomSelectControl
className="components-font-appearance-control"
__unstableSize="large"
label={ label }
describedBy={ getDescribedBy() }
options={ selectOptions }
Expand Down
1 change: 1 addition & 0 deletions packages/block-editor/src/hooks/font-size.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ export function FontSizeEdit( props ) {

return (
<FontSizePicker
__unstableSize="large"
onChange={ onChange }
value={ fontSizeValue }
withReset={ false }
Expand Down
8 changes: 6 additions & 2 deletions packages/components/src/custom-select-control/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ const stateReducer = (
};
export default function CustomSelectControl( {
className,
__unstableSize,
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this have a default value of default, as suggested by the options defined in the Storybook example?

Copy link
Contributor

Choose a reason for hiding this comment

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

Also, in order to align values used across components, should we also consider allowing a value of small for this prop?

hideLabelFromVision,
label,
describedBy,
Expand Down Expand Up @@ -130,8 +131,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-unstable-size-large': __unstableSize === 'large' }
),
isSmall: __unstableSize !== 'large',
describedBy: getDescribedBy(),
} ) }
>
Expand Down
56 changes: 32 additions & 24 deletions packages/components/src/custom-select-control/stories/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ import CustomSelectControl from '../';
export default {
title: 'Components/CustomSelectControl',
component: CustomSelectControl,
argTypes: {
Copy link
Contributor

Choose a reason for hiding this comment

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

Controls FTW !

__unstableSize: {
options: [ 'default', 'large' ],
control: { type: 'select' },
},
},
};

const defaultOptions = [
Expand All @@ -31,29 +37,31 @@ const defaultOptions = [
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.',
},
];
export const Default = CustomSelectControl.bind( {} );
Default.args = {
hideLabelFromVision: false,
label: 'Font size',
options: defaultOptions,
};

export const longLabels = () => (
<CustomSelectControl
label="Testing long labels"
options={ longLabelOptions }
/>
);
export const LongLabels = CustomSelectControl.bind( {} );
LongLabels.args = {
...Default.args,
label: 'Testing long labels',
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.',
},
],
};
5 changes: 5 additions & 0 deletions packages/components/src/custom-select-control/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@
position: relative;
text-align: left;

&.is-unstable-size-large {
min-height: 40px;
padding-left: 16px;
}

// For all button sizes allow sufficient space for the
// dropdown "arrow" icon to display.
&.components-custom-select-control__button {
Expand Down
2 changes: 2 additions & 0 deletions packages/components/src/font-size-picker/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import {

function FontSizePicker(
{
__unstableSize,
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this also have a default value of default? Maybe this is fine to leave as undefined, since a default value will be potentially given by CustomSelectControl (see earlier comment)

fallbackFontSize,
fontSizes = [],
disableCustomFontSizes = false,
Expand Down Expand Up @@ -148,6 +149,7 @@ function FontSizePicker(
shouldUseSelectControl &&
! showCustomValueControl && (
<CustomSelectControl
__unstableSize={ __unstableSize }
className={ `${ baseClassName }__select` }
label={ __( 'Font size' ) }
hideLabelFromVision
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ export const TypographyPanel = () => {
isShownByDefault={ true }
>
<FontSizePicker
__unstableSize="large"
value={ fontSize }
onChange={ setFontSize }
fontSizes={ fontSizes }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ export default function TypographyPanel( { name } ) {
) }
{ supports.includes( 'fontSize' ) && (
<FontSizePicker
__unstableSize="large"
value={ fontSize }
onChange={ setFontSize }
fontSizes={ fontSizes }
Expand Down