From fec39ba3f62de700ed52a4b3988d4bf109bb14c2 Mon Sep 17 00:00:00 2001 From: Marco Ciampini Date: Sat, 4 Feb 2023 11:11:31 +0100 Subject: [PATCH 1/3] `NavigatorButton`: Reuse `Button` types --- packages/components/src/button/types.ts | 7 +++++-- packages/components/src/navigator/types.ts | 17 ++++++----------- 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/packages/components/src/button/types.ts b/packages/components/src/button/types.ts index 0a9f6e2718f61..d409dfaf01d2d 100644 --- a/packages/components/src/button/types.ts +++ b/packages/components/src/button/types.ts @@ -11,8 +11,11 @@ import type { PopoverProps } from '../popover/types'; import type { WordPressComponentProps } from '../ui/context/wordpress-component'; export type ButtonProps = - | WordPressComponentProps< BaseButtonProps & _ButtonProps, 'button', false > - | WordPressComponentProps< BaseButtonProps & AnchorProps, 'a', false >; + | WordPressComponentProps< ButtonAsButtonProps, 'button', false > + | WordPressComponentProps< ButtonAsAnchorProps, 'a', false >; + +export type ButtonAsButtonProps = BaseButtonProps & _ButtonProps; +export type ButtonAsAnchorProps = BaseButtonProps & AnchorProps; type BaseButtonProps = { /** diff --git a/packages/components/src/navigator/types.ts b/packages/components/src/navigator/types.ts index 0b1a6a077ea7a..62477db27a595 100644 --- a/packages/components/src/navigator/types.ts +++ b/packages/components/src/navigator/types.ts @@ -3,6 +3,11 @@ */ import type { ReactNode } from 'react'; +/** + * Internal dependencies + */ +import type { ButtonAsButtonProps } from '../button/types'; + type NavigateOptions = { focusTargetSelector?: string; }; @@ -45,17 +50,7 @@ export type NavigatorScreenProps = { children: ReactNode; }; -type ButtonProps = { - // TODO: should also extend `Button` prop types once the `Button` component - // is refactored to TypeScript. - variant?: 'primary' | 'secondary' | 'tertiary' | 'link'; -}; -export type NavigatorBackButtonProps = Omit< ButtonProps, 'href' > & { - /** - * The children elements. - */ - children: ReactNode; -}; +export type NavigatorBackButtonProps = ButtonAsButtonProps; export type NavigatorButtonProps = NavigatorBackButtonProps & { /** From 4416f3cc7e7b0f2d862f0be43616f9f50a2daae9 Mon Sep 17 00:00:00 2001 From: Marco Ciampini Date: Sat, 4 Feb 2023 11:29:02 +0100 Subject: [PATCH 2/3] CHANGELOG --- packages/components/CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/components/CHANGELOG.md b/packages/components/CHANGELOG.md index 4ea55262580bd..42c1bf6c769cb 100644 --- a/packages/components/CHANGELOG.md +++ b/packages/components/CHANGELOG.md @@ -8,6 +8,7 @@ ### Internal +- `NavigatorButton`: Reuse `Button` types ([47754](https://github.com/WordPress/gutenberg/pull/47754)). - `CustomSelectControl`: lock the `__experimentalShowSelectedHint` prop ([#47229](https://github.com/WordPress/gutenberg/pull/47229)). - Lock the `__experimentalPopoverPositionToPlacement` function and rename it to `__experimentalPopoverLegacyPositionToPlacement` ([#47505](https://github.com/WordPress/gutenberg/pull/47505)). - `ComboboxControl`: Convert to TypeScript ([#47581](https://github.com/WordPress/gutenberg/pull/47581)). From ceb13a1a2abf9ec285bcb44e4c87878876716975 Mon Sep 17 00:00:00 2001 From: Marco Ciampini Date: Tue, 7 Feb 2023 13:47:03 +0100 Subject: [PATCH 3/3] Tweak README --- packages/components/src/navigator/navigator-button/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/components/src/navigator/navigator-button/README.md b/packages/components/src/navigator/navigator-button/README.md index fc96c358cdb02..72154ec317da4 100644 --- a/packages/components/src/navigator/navigator-button/README.md +++ b/packages/components/src/navigator/navigator-button/README.md @@ -35,4 +35,4 @@ The path of the screen to navigate to. The value of this prop needs to be [a val ### Inherited props -`NavigatorButton` also inherits all of the [`Button` props](/packages/components/src/button/README.md#props), except for `href`. +`NavigatorButton` also inherits all of the [`Button` props](/packages/components/src/button/README.md#props), except for `href` and `target`.