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: Deprecate 36px default size #67441

Merged
merged 3 commits into from
Dec 2, 2024
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.
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 @@ -153,6 +153,7 @@ export default function FontAppearanceControl( props ) {
{ ...otherProps }
className="components-font-appearance-control"
__next40pxDefaultSize={ __next40pxDefaultSize }
__shouldNotWarnDeprecated36pxSize
label={ label }
describedBy={ getDescribedBy() }
options={ selectOptions }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ export default function FontFamilyControl( {
return (
<CustomSelectControl
__next40pxDefaultSize={ __next40pxDefaultSize }
__shouldNotWarnDeprecated36pxSize
label={ __( 'Font' ) }
value={ value }
onChange={ ( { selectedItem } ) => onChange( selectedItem.key ) }
Expand Down
2 changes: 2 additions & 0 deletions packages/components/src/custom-select-control/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ function MyCustomSelectControl() {
const [ , setFontSize ] = useState();
return (
<CustomSelectControl
__next40pxDefaultSize
label="Font Size"
options={ options }
onChange={ ( { selectedItem } ) => setFontSize( selectedItem ) }
Expand All @@ -52,6 +53,7 @@ function MyControlledCustomSelectControl() {
const [ fontSize, setFontSize ] = useState( options[ 0 ] );
return (
<CustomSelectControl
__next40pxDefaultSize
label="Font Size"
options={ options }
onChange={ ( { selectedItem } ) => setFontSize( selectedItem ) }
Expand Down
9 changes: 9 additions & 0 deletions packages/components/src/custom-select-control/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import CustomSelectItem from '../custom-select-control-v2/item';
import * as Styled from '../custom-select-control-v2/styles';
import type { CustomSelectProps, CustomSelectOption } from './types';
import { VisuallyHidden } from '../visually-hidden';
import { maybeWarnDeprecated36pxSize } from '../utils/deprecated-36px-size';

function useDeprecatedProps< T extends CustomSelectOption >( {
__experimentalShowSelectedHint,
Expand Down Expand Up @@ -56,6 +57,7 @@ function CustomSelectControl< T extends CustomSelectOption >(
) {
const {
__next40pxDefaultSize = false,
__shouldNotWarnDeprecated36pxSize,
describedBy,
options,
onChange,
Expand All @@ -66,6 +68,13 @@ function CustomSelectControl< T extends CustomSelectOption >(
...restProps
} = useDeprecatedProps( props );

maybeWarnDeprecated36pxSize( {
componentName: 'CustomSelectControl',
__next40pxDefaultSize,
size,
__shouldNotWarnDeprecated36pxSize,
} );

const descriptionId = useInstanceId(
CustomSelectControl,
'custom-select-control__description'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ const Template: StoryFn< typeof CustomSelectControl > = ( props ) => {

export const Default = Template.bind( {} );
Default.args = {
__next40pxDefaultSize: true,
label: 'Label',
options: [
{
Expand Down
22 changes: 13 additions & 9 deletions packages/components/src/custom-select-control/test/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@ import { useState } from '@wordpress/element';
/**
* Internal dependencies
*/
import UncontrolledCustomSelectControl from '..';
import _CustomSelectControl from '..';

const UncontrolledCustomSelectControl = (
props: React.ComponentProps< typeof _CustomSelectControl >
) => <_CustomSelectControl __next40pxDefaultSize { ...props } />;

const customClassName = 'amber-skies';
const customStyles = {
Expand Down Expand Up @@ -716,7 +720,7 @@ describe( 'Type checking', () => {

const onChange = (): void => {};

<UncontrolledCustomSelectControl
<_CustomSelectControl
Copy link
Member Author

Choose a reason for hiding this comment

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

Interestingly, changing this to the thinly wrapped version (UncontrolledCustomSelectControl) started changing some results to these static type tests (which, granted, are testing some advanced type inference logic). I guess React.ComponentProps<> can warp the types a bit, much like some other type utils (e.g. Omit<>).

label="Label"
options={ options }
value={ {
Expand All @@ -726,7 +730,7 @@ describe( 'Type checking', () => {
onChange={ onChange }
/>;

<UncontrolledCustomSelectControl
<_CustomSelectControl
label="Label"
options={ options }
value={ {
Expand All @@ -736,7 +740,7 @@ describe( 'Type checking', () => {
onChange={ onChange }
/>;

<UncontrolledCustomSelectControl
<_CustomSelectControl
label="Label"
options={ options }
value={ {
Expand All @@ -748,7 +752,7 @@ describe( 'Type checking', () => {
onChange={ onChange }
/>;

<UncontrolledCustomSelectControl
<_CustomSelectControl
label="Label"
options={ options }
value={ {
Expand All @@ -764,7 +768,7 @@ describe( 'Type checking', () => {
}
/>;

<UncontrolledCustomSelectControl
<_CustomSelectControl
label="Label"
options={ optionsReadOnly }
value={ {
Expand All @@ -774,7 +778,7 @@ describe( 'Type checking', () => {
onChange={ onChange }
/>;

<UncontrolledCustomSelectControl
<_CustomSelectControl
label="Label"
options={ optionsReadOnly }
value={ {
Expand All @@ -785,7 +789,7 @@ describe( 'Type checking', () => {
onChange={ onChange }
/>;

<UncontrolledCustomSelectControl
<_CustomSelectControl
label="Label"
options={ optionsReadOnly }
value={ {
Expand All @@ -797,7 +801,7 @@ describe( 'Type checking', () => {
onChange={ onChange }
/>;

<UncontrolledCustomSelectControl
<_CustomSelectControl
label="Label"
options={ optionsReadOnly }
value={ {
Expand Down
7 changes: 7 additions & 0 deletions packages/components/src/custom-select-control/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,4 +120,11 @@ export type CustomSelectProps< T extends CustomSelectOption > = {
* @default false
*/
__next40pxDefaultSize?: boolean;
/**
* Do not throw a warning for the deprecated 36px default size.
* For internal components of other components that already throw the warning.
*
* @ignore
*/
__shouldNotWarnDeprecated36pxSize?: boolean;
};
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ const FontSizePickerSelect = ( props: FontSizePickerSelectProps ) => {
return (
<CustomSelectControl
__next40pxDefaultSize={ __next40pxDefaultSize }
__shouldNotWarnDeprecated36pxSize
className="components-font-size-picker__select"
label={ __( 'Font size' ) }
hideLabelFromVision
Expand Down
Loading