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

Button: Deprecate 36px default size #68328

Draft
wants to merge 3 commits into
base: trunk
Choose a base branch
from
Draft
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
3 changes: 2 additions & 1 deletion packages/components/src/button/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ Lets users take actions and make choices with a single click or tap.

```jsx
import { Button } from '@wordpress/components';
const Mybutton = () => (
const MyButton = () => (
<Button
variant="primary"
onClick={ handleClick }
__next40pxDefaultSize
>
Click here
</Button>
Expand Down
14 changes: 13 additions & 1 deletion packages/components/src/button/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,13 @@ import Icon from '../icon';
import { VisuallyHidden } from '../visually-hidden';
import type { ButtonProps, DeprecatedButtonProps } from './types';
import { positionToPlacement } from '../popover/utils';
import { maybeWarnDeprecated36pxSize } from '../utils/deprecated-36px-size';

const disabledEventsOnDisabledButton = [ 'onMouseDown', 'onClick' ] as const;

function useDeprecatedProps( {
__experimentalIsFocusable,
__shouldNotWarnDeprecated36pxSize,
isDefault,
isPrimary,
isSecondary,
Expand Down Expand Up @@ -81,6 +83,15 @@ function useDeprecatedProps( {
computedVariant ??= 'link';
}

if ( computedVariant !== 'link' ) {
maybeWarnDeprecated36pxSize( {
componentName: 'Button',
size: computedSize,
__next40pxDefaultSize: otherProps.__next40pxDefaultSize,
__shouldNotWarnDeprecated36pxSize,
} );
}

return {
...newProps,
...otherProps,
Expand Down Expand Up @@ -292,10 +303,11 @@ export function UnforwardedButton(
*
* ```jsx
* import { Button } from '@wordpress/components';
* const Mybutton = () => (
* const MyButton = () => (
* <Button
* variant="primary"
* onClick={ handleClick }
* __next40pxDefaultSize
* >
* Click here
* </Button>
Expand Down
11 changes: 8 additions & 3 deletions packages/components/src/button/stories/index.story.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ const Template: StoryFn< typeof Button > = ( props ) => {
export const Default = Template.bind( {} );
Default.args = {
children: 'Code is poetry',
__next40pxDefaultSize: true,
};

/**
Expand Down Expand Up @@ -113,10 +114,14 @@ IsDestructive.args = {
isDestructive: true,
};

/**
* In most cases, the `"compact"` size should be used for icon buttons.
*/
export const Icon = Template.bind( {} );
Icon.args = {
label: 'Code is poetry',
icon: 'wordpress',
size: 'compact',
};

export const GroupedIcons = () => {
Expand All @@ -126,9 +131,9 @@ export const GroupedIcons = () => {

return (
<GroupContainer>
<Button icon={ formatBold } label="Bold" />
<Button icon={ formatItalic } label="Italic" />
<Button icon={ link } label="Link" />
<Button size="compact" icon={ formatBold } label="Bold" />
<Button size="compact" icon={ formatItalic } label="Italic" />
<Button size="compact" icon={ link } label="Link" />
</GroupContainer>
);
};
7 changes: 7 additions & 0 deletions packages/components/src/button/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@ type BaseButtonProps = {
* @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;
/**
* Whether to keep the button focusable when disabled.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ const NavigatorButtonWithSkipFocus = ( {
return (
<Button
{ ...props }
__next40pxDefaultSize
style={ {
marginInline: '8px',
...props.style,
Expand Down
19 changes: 14 additions & 5 deletions packages/components/src/utils/deprecated-36px-size.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,15 @@ export function maybeWarnDeprecated36pxSize( {
__next40pxDefaultSize,
size,
__shouldNotWarnDeprecated36pxSize,
feature,
hint,
}: {
componentName: string;
__next40pxDefaultSize: boolean | undefined;
size: string | undefined;
__shouldNotWarnDeprecated36pxSize?: boolean;
feature?: string;
hint?: string;
} ) {
if (
__shouldNotWarnDeprecated36pxSize ||
Expand All @@ -22,9 +26,14 @@ export function maybeWarnDeprecated36pxSize( {
return;
}

deprecated( `36px default size for wp.components.${ componentName }`, {
since: '6.8',
version: '7.1',
hint: 'Set the `__next40pxDefaultSize` prop to true to start opting into the new default size, which will become the default in a future version.',
} );
deprecated(
feature ?? `36px default size for wp.components.${ componentName }`,
{
since: '6.8',
version: '7.1',
hint:
hint ??
'Set the `__next40pxDefaultSize` prop to true to start opting into the new default size, which will become the default in a future version.',
}
);
}
Loading