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

NavigatorButton: Reuse Button types #47754

Merged
merged 3 commits into from
Feb 7, 2023
Merged
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
1 change: 1 addition & 0 deletions packages/components/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)).
Expand Down
7 changes: 5 additions & 2 deletions packages/components/src/button/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
17 changes: 6 additions & 11 deletions packages/components/src/navigator/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
*/
import type { ReactNode } from 'react';

/**
* Internal dependencies
*/
import type { ButtonAsButtonProps } from '../button/types';

type NavigateOptions = {
focusTargetSelector?: string;
};
Expand Down Expand Up @@ -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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea to simplify this!


export type NavigatorButtonProps = NavigatorBackButtonProps & {
/**
Expand Down