Skip to content

Commit

Permalink
Radio: Deprecate 36px default size (#66572)
Browse files Browse the repository at this point in the history
* Radio: Deprecate 36px default size

* Add changelog

* Fix changelog

Co-authored-by: mirka <[email protected]>
Co-authored-by: tyxla <[email protected]>
  • Loading branch information
3 people authored Oct 31, 2024
1 parent fc2bf3a commit f73888a
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 15 deletions.
4 changes: 4 additions & 0 deletions packages/components/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Unreleased

### Deprecations

- `Radio`: Deprecate 36px default size ([#66572](https://github.com/WordPress/gutenberg/pull/66572)).

### Enhancements

- `MenuItem`: Add 40px size prop on Button ([#66596](https://github.com/WordPress/gutenberg/pull/66596)).
Expand Down
16 changes: 8 additions & 8 deletions packages/components/src/radio-group/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,10 @@ const MyControlledRadioRadioGroup = () => {
const [ checked, setChecked ] = useState( '25' );
return (
<RadioGroup label="Width" onChange={ setChecked } checked={ checked }>
<Radio value="25">25%</Radio>
<Radio value="50">50%</Radio>
<Radio value="75">75%</Radio>
<Radio value="100">100%</Radio>
<Radio __next40pxDefaultSize value="25">25%</Radio>
<Radio __next40pxDefaultSize value="50">50%</Radio>
<Radio __next40pxDefaultSize value="75">75%</Radio>
<Radio __next40pxDefaultSize value="100">100%</Radio>
</RadioGroup>
);
};
Expand All @@ -80,10 +80,10 @@ import {
const MyUncontrolledRadioRadioGroup = () => {
return (
<RadioGroup label="Width" defaultChecked="25">
<Radio value="25">25%</Radio>
<Radio value="50">50%</Radio>
<Radio value="75">75%</Radio>
<Radio value="100">100%</Radio>
<Radio __next40pxDefaultSize value="25">25%</Radio>
<Radio __next40pxDefaultSize value="50">50%</Radio>
<Radio __next40pxDefaultSize value="75">75%</Radio>
<Radio __next40pxDefaultSize value="100">100%</Radio>
</RadioGroup>
);
};
Expand Down
7 changes: 7 additions & 0 deletions packages/components/src/radio-group/radio.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import Button from '../button';
import { RadioGroupContext } from './context';
import type { WordPressComponentProps } from '../context';
import type { RadioProps } from './types';
import { maybeWarnDeprecated36pxSize } from '../utils/deprecated-36px-size';

function UnforwardedRadio(
{
Expand All @@ -30,6 +31,12 @@ function UnforwardedRadio(
const selectedValue = useStoreState( store, 'value' );
const isChecked = selectedValue !== undefined && selectedValue === value;

maybeWarnDeprecated36pxSize( {
componentName: 'Radio',
size: undefined,
__next40pxDefaultSize: props.__next40pxDefaultSize,
} );

return (
<Ariakit.Radio
disabled={ disabled }
Expand Down
20 changes: 16 additions & 4 deletions packages/components/src/radio-group/stories/index.story.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,13 @@ const meta: Meta< typeof RadioGroup > = {
parameters: {
actions: { argTypesRegex: '^on.*' },
controls: { expanded: true },
docs: { canvas: { sourceState: 'shown' } },
docs: {
canvas: { sourceState: 'shown' },
description: {
component:
'This component is deprecated. Use `RadioControl` or `ToggleGroupControl` instead.',
},
},
},
};
export default meta;
Expand All @@ -44,9 +50,15 @@ Default.args = {
defaultChecked: 'option2',
children: (
<>
<Radio value="option1">Option 1</Radio>
<Radio value="option2">Option 2</Radio>
<Radio value="option3">Option 3</Radio>
<Radio __next40pxDefaultSize value="option1">
Option 1
</Radio>
<Radio __next40pxDefaultSize value="option2">
Option 2
</Radio>
<Radio __next40pxDefaultSize value="option3">
Option 3
</Radio>
</>
),
};
Expand Down
7 changes: 6 additions & 1 deletion packages/components/src/radio-group/types.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
/**
* Internal dependencies
*/
import type { ButtonProps } from '../button/types';

export type RadioGroupProps = {
/**
* Accessible label for the radio group
Expand Down Expand Up @@ -27,7 +32,7 @@ export type RadioGroupProps = {
children: React.ReactNode;
};

export type RadioProps = {
export type RadioProps = Pick< ButtonProps, '__next40pxDefaultSize' > & {
/**
* The actual value of the radio element.
*/
Expand Down
7 changes: 5 additions & 2 deletions packages/components/src/utils/deprecated-36px-size.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,12 @@ export function maybeWarnDeprecated36pxSize( {
}: {
componentName: string;
__next40pxDefaultSize: boolean | undefined;
size: string;
size: string | undefined;
} ) {
if ( __next40pxDefaultSize || size !== 'default' ) {
if (
__next40pxDefaultSize ||
( size !== undefined && size !== 'default' )
) {
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ export function CreateTemplatePartModalContents( {
{ templatePartAreas.map(
( { icon, label, area: value, description } ) => (
<Radio
__next40pxDefaultSize
key={ label }
value={ value }
className="editor-create-template-part-modal__area-radio"
Expand Down

0 comments on commit f73888a

Please sign in to comment.