Skip to content
Closed
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import { FontWeight, TextVariant } from '@metamask/design-system-shared';
import {
ButtonSize,
FontWeight,
TextVariant,
} from '@metamask/design-system-shared';
import React from 'react';
import { GestureResponderEvent } from 'react-native';

import {
BoxAlignItems,
BoxBackgroundColor,
ButtonIconSize,
ButtonSize,
BoxFlexDirection,
IconName,
} from '../../types';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { ButtonSize, ButtonVariant } from '@metamask/design-system-shared';
import { useTailwind } from '@metamask/design-system-twrnc-preset';
import type { Meta, StoryObj } from '@storybook/react-native';
import React from 'react';
import { View } from 'react-native';

import { ButtonSize, ButtonVariant } from '../../types';
import { IconName } from '../Icon';

import { Button } from './Button';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { ButtonVariant } from '@metamask/design-system-shared';
import { render } from '@testing-library/react-native';
import React from 'react';

import { ButtonVariant } from '../../types';

import { Button } from './Button';

describe('Button', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { ButtonVariant } from '@metamask/design-system-shared';
import React from 'react';

import { ButtonVariant } from '../../types';

import type { ButtonProps } from './Button.types';
import { ButtonPrimary } from './variants/ButtonPrimary';
import { ButtonSecondary } from './variants/ButtonSecondary';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { ButtonVariant } from '../../types';
import type { ButtonVariant } from '@metamask/design-system-shared';

import type { ButtonPrimaryProps } from './variants/ButtonPrimary';
import type { ButtonSecondaryProps } from './variants/ButtonSecondary';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export { ButtonSize, ButtonVariant } from '../../types';
export { ButtonSize, ButtonVariant } from '@metamask/design-system-shared';
export { Button } from './Button';
export type { ButtonProps } from './Button.types';
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { ButtonPrimarySize } from '@metamask/design-system-shared';
import { useTailwind } from '@metamask/design-system-twrnc-preset';
import type { Meta, StoryObj } from '@storybook/react-native';
import { View } from 'react-native';

import { ButtonPrimarySize } from '../../../../types';
import { IconName } from '../../../Icon';

import { ButtonPrimary } from './ButtonPrimary';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { ButtonBaseSize } from '@metamask/design-system-shared';
import { useTailwind } from '@metamask/design-system-twrnc-preset';
import { renderHook } from '@testing-library/react-hooks';
import { render } from '@testing-library/react-native';
import React from 'react';
import * as ReactTestRenderer from 'react-test-renderer';

import { ButtonBaseSize } from '../../../../types';

import { ButtonPrimary } from './ButtonPrimary';

describe('ButtonPrimary', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export { ButtonPrimarySize } from '../../../../types';
export { ButtonPrimarySize } from '@metamask/design-system-shared';
export { ButtonPrimary } from './ButtonPrimary';
export type { ButtonPrimaryProps } from './ButtonPrimary.types';
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { ButtonSecondarySize } from '@metamask/design-system-shared';
import { useTailwind } from '@metamask/design-system-twrnc-preset';
import type { Meta, StoryObj } from '@storybook/react-native';
import { View } from 'react-native';

import { ButtonSecondarySize } from '../../../../types';
import { IconName } from '../../../Icon';

import { ButtonSecondary } from './ButtonSecondary';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { ButtonBaseSize } from '@metamask/design-system-shared';
import { useTailwind } from '@metamask/design-system-twrnc-preset';
import { renderHook } from '@testing-library/react-hooks';
import { render } from '@testing-library/react-native';
import React from 'react';
import * as ReactTestRenderer from 'react-test-renderer';

import { ButtonBaseSize } from '../../../../types';

import { ButtonSecondary } from './ButtonSecondary';

describe('ButtonSecondary', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export { ButtonSecondarySize } from '../../../../types';
export { ButtonSecondarySize } from '@metamask/design-system-shared';
export { ButtonSecondary } from './ButtonSecondary';
export type { ButtonSecondaryProps } from './ButtonSecondary.types';
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { ButtonTertiarySize } from '@metamask/design-system-shared';
import { useTailwind } from '@metamask/design-system-twrnc-preset';
import type { Meta, StoryObj } from '@storybook/react-native';
import { View } from 'react-native';

import { ButtonTertiarySize } from '../../../../types';
import { IconName } from '../../../Icon';

import { ButtonTertiary } from './ButtonTertiary';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { ButtonBaseSize } from '@metamask/design-system-shared';
import { useTailwind } from '@metamask/design-system-twrnc-preset';
import { renderHook } from '@testing-library/react-hooks';
import { render } from '@testing-library/react-native';
import React from 'react';
import * as ReactTestRenderer from 'react-test-renderer';

import { ButtonBaseSize } from '../../../../types';

import { ButtonTertiary } from './ButtonTertiary';

describe('ButtonTertiary', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export { ButtonTertiarySize } from '../../../../types';
export { ButtonTertiarySize } from '@metamask/design-system-shared';
export { ButtonTertiary } from './ButtonTertiary';
export type { ButtonTertiaryProps } from './ButtonTertiary.types';
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ButtonBaseSize } from '../../types';
import { ButtonBaseSize } from '@metamask/design-system-shared';

export const TWCLASSMAP_BUTTONBASE_SIZE_DIMENSION: Record<
ButtonBaseSize,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { ButtonBaseSize } from '@metamask/design-system-shared';
import type { Meta, StoryObj } from '@storybook/react-native';

import { BoxFlexDirection, ButtonBaseSize } from '../../types';
import { BoxFlexDirection } from '../../types';
import { Box } from '../Box';
import { IconName } from '../Icon';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { ButtonBaseSize } from '@metamask/design-system-shared';
import { useTailwind } from '@metamask/design-system-twrnc-preset';
import { renderHook } from '@testing-library/react-hooks';
import { render, fireEvent, waitFor } from '@testing-library/react-native';
import React from 'react';
import { View, Text } from 'react-native';
import * as ReactTestRenderer from 'react-test-renderer';

import { ButtonBaseSize, IconName } from '../../types';
import { IconName } from '../../types';

import { ButtonBase } from './ButtonBase';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { ButtonBaseSize } from '@metamask/design-system-shared';
import { useTailwind } from '@metamask/design-system-twrnc-preset';
import React, { useMemo } from 'react';
import { View } from 'react-native';
import type { StyleProp, ViewStyle } from 'react-native';

import { ButtonBaseSize } from '../../types';
import { Icon, IconColor, IconSize } from '../Icon';
import { ButtonAnimated } from '../temp-components/ButtonAnimated';
import { Spinner } from '../temp-components/Spinner';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,39 +1,18 @@
import type { ButtonBasePropsShared } from '@metamask/design-system-shared';
import type { PressableProps, StyleProp, ViewStyle } from 'react-native';

import type { ButtonBaseSize } from '../../types';
import type { IconProps, IconName } from '../Icon';
import type { SpinnerProps } from '../temp-components/Spinner';
import type { TextProps } from '../Text';

/**
* ButtonBase component props.
*/
export type ButtonBaseProps = {
/**
* Required prop for the content to be rendered within the ButtonBase
*/
children: React.ReactNode | string;
export type ButtonBaseProps = ButtonBasePropsShared & {
/**
* Optional props to be passed to the Text component when children is a string
*/
textProps?: Omit<Partial<TextProps>, 'children'>;
/**
* Optional prop to control the size of the ButtonBase
* Possible values: ButtonBaseSize.Sm (32px), ButtonBaseSize.Md (40px), ButtonBaseSize.Lg (48px)
*
* @default ButtonBaseSize.Lg
*/
size?: ButtonBaseSize;
/**
* Optional prop that when true, shows a loading spinner
*
* @default false
*/
isLoading?: boolean;
/**
* Optional prop for text to display when button is in loading state
*/
loadingText?: string;
/**
* Optional prop to pass additional properties to the end icon
*/
Expand Down Expand Up @@ -62,18 +41,6 @@ export type ButtonBaseProps = {
* Optional prop for a custom element to show at the end of the button
*/
endAccessory?: React.ReactNode;
/**
* Optional prop that when true, disables the button
*
* @default false
*/
isDisabled?: boolean;
/**
* Optional prop that when true, makes the button take up the full width of its container
*
* @default false
*/
isFullWidth?: boolean;
/**
* Optional prop to add twrnc overriding classNames.
* Can be a string or a function that receives pressed state and returns a string.
Expand Down Expand Up @@ -121,10 +88,10 @@ export type ButtonBaseProps = {
nativeEvent: { actionName: string };
}) => void;
} & Omit<
PressableProps,
| 'accessibilityRole'
| 'accessibilityLabel'
| 'accessibilityHint'
| 'accessibilityActions'
| 'onAccessibilityAction'
>;
PressableProps,
| 'accessibilityRole'
| 'accessibilityLabel'
| 'accessibilityHint'
| 'accessibilityActions'
| 'onAccessibilityAction'
>;
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export { ButtonBaseSize } from '../../types';
export { ButtonBaseSize } from '@metamask/design-system-shared';
export { ButtonBase } from './ButtonBase';
export { TWCLASSMAP_BUTTONBASE_SIZE_DIMENSION } from './ButtonBase.constants';
export type { ButtonBaseProps } from './ButtonBase.types';
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { ButtonHeroSize } from '@metamask/design-system-shared';
import type { Meta, StoryObj } from '@storybook/react-native';
import React from 'react';
import { View } from 'react-native';

import { ButtonHeroSize } from '../../types';
import { IconName } from '../Icon';

import { ButtonHero } from './ButtonHero';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export { ButtonHero } from './ButtonHero';
export type { ButtonHeroProps } from './ButtonHero.types';
export { ButtonHeroSize } from '../../types';
export { ButtonHeroSize } from '@metamask/design-system-shared';
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { ButtonVariant } from '@metamask/design-system-shared';
import type { Meta, StoryObj } from '@storybook/react-native';
import { useState, useRef } from 'react';
import { View } from 'react-native';

import { ButtonVariant } from '../../types';
import { Button } from '../Button';

import { Checkbox } from './Checkbox';
Expand Down
32 changes: 0 additions & 32 deletions packages/design-system-react-native/src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,38 +211,6 @@ export enum BoxBorderColor {
Transparent = 'border-transparent',
}

/**
Comment thread
cursor[bot] marked this conversation as resolved.
* ButtonBase - size
*/
export enum ButtonBaseSize {
/**
* Represents a small button size (32px).
*/
Sm = 'sm',
/**
* Represents a medium button size (40px).
*/
Md = 'md',
/**
* Represents a large button size (48px).
*/
Lg = 'lg',
}
export { ButtonBaseSize as ButtonSize };
export { ButtonBaseSize as ButtonPrimarySize };
export { ButtonBaseSize as ButtonSecondarySize };
export { ButtonBaseSize as ButtonTertiarySize };
export { ButtonBaseSize as ButtonHeroSize };

/**
* Button - variant
*/
export enum ButtonVariant {
Primary = 'primary',
Secondary = 'secondary',
Tertiary = 'tertiary',
}

/**
* ButtonIcon - size
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import { FontWeight, TextVariant } from '@metamask/design-system-shared';
import {
ButtonSize,
FontWeight,
TextVariant,
} from '@metamask/design-system-shared';
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

BannerBase wasn't part of the original ButtonBase/Button migration scope, but removing ButtonSize from src/types/index.ts surfaced it as a broken consumer. Moving ButtonSize into the @metamask/design-system-shared import alongside FontWeight and TextVariant is the correct fix — the same pattern applies identically in both the React and React Native versions of this file.

import React, { forwardRef } from 'react';

import {
BoxAlignItems,
BoxBackgroundColor,
ButtonIconSize,
ButtonSize,
BoxFlexDirection,
IconName,
} from '../../types';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ButtonSize, ButtonVariant } from '@metamask/design-system-shared';
import type { Meta, StoryObj } from '@storybook/react-vite';
import React from 'react';

import { ButtonVariant, ButtonSize } from '../../types';
import { IconName } from '../Icon';

import { Button } from './Button';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ButtonVariant } from '@metamask/design-system-shared';
import { render, screen } from '@testing-library/react';
import React, { createRef } from 'react';

import { ButtonVariant } from '../../types';
import { IconName } from '../Icon';

import { Button } from './Button';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { ButtonVariant } from '@metamask/design-system-shared';
import React, { forwardRef } from 'react';

import { ButtonVariant } from '../../types';

import type { ButtonProps } from './Button.types';
import { ButtonPrimary } from './variants/ButtonPrimary';
import type { ButtonPrimaryProps } from './variants/ButtonPrimary';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { ButtonVariant } from '../../types';
import { ButtonVariant } from '@metamask/design-system-shared';

import type { ButtonPrimaryProps } from './variants/ButtonPrimary';
import type { ButtonSecondaryProps } from './variants/ButtonSecondary';
Expand All @@ -13,12 +13,12 @@ export type ButtonProps = {
variant?: ButtonVariant;
} & (
| (Omit<ButtonPrimaryProps, 'ref'> & {
variant?: ButtonVariant.Primary;
variant?: typeof ButtonVariant.Primary;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

typeof ButtonVariant.Primary is the idiomatic way to narrow a discriminated union member when working with ADR-0003 const objects. It resolves to the string literal type 'primary' at compile time, but unlike a bare string literal it keeps a live reference to the const object — so if the value ever changes, this type stays in sync automatically. Extract<ButtonVariant, 'primary'> was an earlier workaround that works but obscures intent; typeof ButtonVariant.X makes the narrowing intent explicit. Switching from import type to import is required so the const object value is available for typeof to reference.

})
| (Omit<ButtonSecondaryProps, 'ref'> & {
variant?: ButtonVariant.Secondary;
variant?: typeof ButtonVariant.Secondary;
})
| (Omit<ButtonTertiaryProps, 'ref'> & {
variant?: ButtonVariant.Tertiary;
variant?: typeof ButtonVariant.Tertiary;
})
);
Loading
Loading