1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-22 09:57:02 +01:00

Adding correct types so ButtonBase and all button variants ButtonPrimary, ButtonSecondary, ButtonLink and Button accept Text props (#20647)

This commit is contained in:
George Marshall 2023-08-29 12:09:01 -07:00 committed by GitHub
parent 6a17d76efc
commit e2789cbe82
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 10 additions and 11 deletions

View File

@ -1,10 +1,7 @@
import { ReactNode } from 'react'; import { ReactNode } from 'react';
import type { import type { PolymorphicComponentPropWithRef } from '../box';
StyleUtilityProps,
PolymorphicComponentPropWithRef,
} from '../box';
import { IconColor } from '../../../helpers/constants/design-system'; import { IconColor } from '../../../helpers/constants/design-system';
import { TextDirection, TextProps } from '../text'; import { TextDirection, TextProps, TextStyleUtilityProps } from '../text';
import { IconName } from '../icon'; import { IconName } from '../icon';
import type { IconProps } from '../icon'; import type { IconProps } from '../icon';
@ -15,7 +12,9 @@ export enum ButtonBaseSize {
} }
export type ValidButtonTagType = 'button' | 'a'; export type ValidButtonTagType = 'button' | 'a';
export interface ButtonBaseStyleUtilityProps extends StyleUtilityProps {
export interface ButtonBaseStyleUtilityProps
extends Omit<TextStyleUtilityProps, 'as' | 'children' | 'ellipsis'> {
/** /**
* The polymorphic `as` prop allows you to change the root HTML element of the Button component between `button` and `a` tag * The polymorphic `as` prop allows you to change the root HTML element of the Button component between `button` and `a` tag
* *

View File

@ -13,7 +13,7 @@ import { ButtonLinkSize, ButtonLinkComponent } from './button-link.types';
export const ButtonLink: ButtonLinkComponent = React.forwardRef( export const ButtonLink: ButtonLinkComponent = React.forwardRef(
<C extends React.ElementType = 'button' | 'a'>( <C extends React.ElementType = 'button' | 'a'>(
{ {
className, className = '',
color, color,
danger = false, danger = false,
disabled = false, disabled = false,

View File

@ -17,7 +17,7 @@ import {
export const ButtonPrimary: ButtonPrimaryComponent = React.forwardRef( export const ButtonPrimary: ButtonPrimaryComponent = React.forwardRef(
<C extends React.ElementType = 'button' | 'a'>( <C extends React.ElementType = 'button' | 'a'>(
{ {
className, className = '',
danger = false, danger = false,
disabled = false, disabled = false,
size = ButtonPrimarySize.Md, size = ButtonPrimarySize.Md,

View File

@ -23,15 +23,15 @@ type ButtonPropsByVariant = {
[ButtonVariant.Primary]: { [ButtonVariant.Primary]: {
variant?: ButtonVariant.Primary; variant?: ButtonVariant.Primary;
size?: ValidButtonSize; // Allows for only ButtonSize.Sm, ButtonSize.Md, ButtonSize.Lg size?: ValidButtonSize; // Allows for only ButtonSize.Sm, ButtonSize.Md, ButtonSize.Lg
} & Omit<ButtonPrimaryStyleUtilityProps, 'size'>; } & Omit<ButtonPrimaryStyleUtilityProps, 'size' | 'variant'>;
[ButtonVariant.Secondary]: { [ButtonVariant.Secondary]: {
variant?: ButtonVariant.Secondary; variant?: ButtonVariant.Secondary;
size?: ValidButtonSize; // Allows for only ButtonSize.Sm, ButtonSize.Md, ButtonSize.Lg size?: ValidButtonSize; // Allows for only ButtonSize.Sm, ButtonSize.Md, ButtonSize.Lg
} & Omit<ButtonSecondaryStyleUtilityProps, 'size'>; } & Omit<ButtonSecondaryStyleUtilityProps, 'size' | 'variant'>;
[ButtonVariant.Link]: { [ButtonVariant.Link]: {
variant?: ButtonVariant.Link; variant?: ButtonVariant.Link;
size?: ButtonSize; size?: ButtonSize;
} & Omit<ButtonLinkStyleUtilityProps, 'size'>; } & Omit<ButtonLinkStyleUtilityProps, 'size' | 'variant'>;
}; };
type ButtonPropsMap = { type ButtonPropsMap = {