Skip to content

Commit

Permalink
Button: Keep deprecated props in type definitions (#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 <[email protected]>
Co-authored-by: tyxla <[email protected]>
Co-authored-by: andrewhayward <[email protected]>
Co-authored-by: t-hamano <[email protected]>
  • Loading branch information
5 people authored Mar 18, 2024
1 parent d575ec7 commit 2bcd06b
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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 2bcd06b

Please sign in to comment.