Skip to content

Commit

Permalink
Button: Keep deprecated props in type definitions (WordPress#59913)
Browse files Browse the repository at this point in the history
* Button: Keep deprecated props in type definitions

* Remove hard deprecation verison for `isDefault`

* Add changelog

* Add package namespace to deprecation message

Co-authored-by: mirka <0mirka00@git.wordpress.org>
Co-authored-by: tyxla <tyxla@git.wordpress.org>
Co-authored-by: andrewhayward <andrewhayward@git.wordpress.org>
Co-authored-by: t-hamano <wildworks@git.wordpress.org>
  • Loading branch information
5 people authored and carstingaxion committed Mar 27, 2024
1 parent e61458a commit 2f61ccd
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 8 deletions.
4 changes: 4 additions & 0 deletions packages/components/CHANGELOG.md
Expand Up @@ -8,6 +8,10 @@

- `TextControl`: Add typings for `date`, `time` and `datetime-local` ([#59666](https://github.com/WordPress/gutenberg/pull/59666)).

### Internal

- `Button`: Keep deprecated props in type definitions ([#59913](https://github.com/WordPress/gutenberg/pull/59913)).

## 27.1.0 (2024-03-06)

### Bug Fix
Expand Down
5 changes: 2 additions & 3 deletions packages/components/src/button/index.tsx
Expand Up @@ -65,10 +65,9 @@ function useDeprecatedProps( {
}

if ( isDefault ) {
deprecated( 'Button isDefault prop', {
deprecated( 'wp.components.Button `isDefault` prop', {
since: '5.4',
alternative: 'variant="secondary"',
version: '6.2',
} );

computedVariant ??= 'secondary';
Expand All @@ -87,7 +86,7 @@ function useDeprecatedProps( {
}

export function UnforwardedButton(
props: ButtonProps,
props: ButtonProps & DeprecatedButtonProps,
ref: ForwardedRef< any >
) {
const {
Expand Down
5 changes: 0 additions & 5 deletions packages/components/src/button/test/index.tsx
Expand Up @@ -554,33 +554,28 @@ describe( 'Button', () => {

describe( 'deprecated props', () => {
it( 'should not break when the legacy isPrimary prop is passed', () => {
// @ts-expect-error
render( <Button isPrimary /> );
expect( screen.getByRole( 'button' ) ).toHaveClass( 'is-primary' );
} );

it( 'should not break when the legacy isSecondary prop is passed', () => {
// @ts-expect-error
render( <Button isSecondary /> );
expect( screen.getByRole( 'button' ) ).toHaveClass(
'is-secondary'
);
} );

it( 'should not break when the legacy isTertiary prop is passed', () => {
// @ts-expect-error
render( <Button isTertiary /> );
expect( screen.getByRole( 'button' ) ).toHaveClass( 'is-tertiary' );
} );

it( 'should not break when the legacy isLink prop is passed', () => {
// @ts-expect-error
render( <Button isLink /> );
expect( screen.getByRole( 'button' ) ).toHaveClass( 'is-link' );
} );

it( 'should warn when the isDefault prop is passed', () => {
// @ts-expect-error
render( <Button isDefault /> );
expect( screen.getByRole( 'button' ) ).toHaveClass(
'is-secondary'
Expand Down
30 changes: 30 additions & 0 deletions packages/components/src/button/types.ts
Expand Up @@ -149,10 +149,40 @@ type AnchorProps = {
};

export type DeprecatedButtonProps = {
/**
* Gives the button a default style.
*
* @deprecated Use the `'secondary'` value on the `variant` prop instead.
* @ignore
*/
isDefault?: boolean;
/**
* Gives the button a link style.
*
* @deprecated Use the `'link'` value on the `variant` prop instead.
* @ignore
*/
isLink?: boolean;
/**
* Gives the button a primary style.
*
* @deprecated Use the `'primary'` value on the `variant` prop instead.
* @ignore
*/
isPrimary?: boolean;
/**
* Gives the button a default style.
*
* @deprecated Use the `'secondary'` value on the `variant` prop instead.
* @ignore
*/
isSecondary?: boolean;
/**
* Gives the button a text-based style.
*
* @deprecated Use the `'tertiary'` value on the `variant` prop instead.
* @ignore
*/
isTertiary?: boolean;
};

Expand Down

0 comments on commit 2f61ccd

Please sign in to comment.