diff --git a/ui/components/app/modals/eth-sign-modal/eth-sign-modal.js b/ui/components/app/modals/eth-sign-modal/eth-sign-modal.js index 47b056a7b..41944bb58 100644 --- a/ui/components/app/modals/eth-sign-modal/eth-sign-modal.js +++ b/ui/components/app/modals/eth-sign-modal/eth-sign-modal.js @@ -9,6 +9,7 @@ import { ButtonLink, ButtonPrimary, ButtonSecondary, + ButtonSecondarySize, FormTextField, Icon, IconName, @@ -152,7 +153,11 @@ const EthSignModal = ({ hideModal }) => { gap={4} marginTop={6} > - hideModal()} size={Size.LG} block> + hideModal()} + size={ButtonSecondarySize.Lg} + block + > {t('cancel')} {showTextField ? ( diff --git a/ui/components/component-library/button-secondary/README.mdx b/ui/components/component-library/button-secondary/README.mdx index 177cde8d0..35570acf3 100644 --- a/ui/components/component-library/button-secondary/README.mdx +++ b/ui/components/component-library/button-secondary/README.mdx @@ -12,33 +12,28 @@ The `ButtonSecondary` is an extension of `ButtonBase` to support secondary style ## Props -The `ButtonSecondary` accepts all props below as well as all [Box](/docs/components-ui-box--default-story#props) and [ButtonBase](/docs/components-componentlibrary-buttonbase--default-story#props) component props - ### Size -Use the `size` prop and the `Size` object from `./ui/helpers/constants/design-system.js` to change the size of `ButtonSecondary`. Defaults to `Size.MD` - -Optional: `BUTTON_SIZES` from `./button-base` object can be used instead of `Size`. +Use the `size` prop and the `ButtonSecondarySize` enum from `./ui/components/component-library` to change the size of `ButtonSecondary`. Defaults to `ButtonSecondarySize.Md` Possible sizes include: -- `Size.SM` 32px -- `Size.MD` 40px -- `Size.LG` 48px +- `ButtonSecondarySize.Sm` 32px +- `ButtonSecondarySize.Md` 40px +- `ButtonSecondarySize.Lg` 48px ```jsx -import { Size } from '../../../helpers/constants/design-system'; -import { ButtonSecondary } from '../../component-library'; +import { ButtonSecondary, ButtonSecondarySize } from '../../component-library'; - - - + + + ``` ### Danger diff --git a/ui/components/component-library/button-secondary/__snapshots__/button-secondary.test.js.snap b/ui/components/component-library/button-secondary/__snapshots__/button-secondary.test.tsx.snap similarity index 100% rename from ui/components/component-library/button-secondary/__snapshots__/button-secondary.test.js.snap rename to ui/components/component-library/button-secondary/__snapshots__/button-secondary.test.tsx.snap diff --git a/ui/components/component-library/button-secondary/button-secondary.constants.js b/ui/components/component-library/button-secondary/button-secondary.constants.js deleted file mode 100644 index 28181aa04..000000000 --- a/ui/components/component-library/button-secondary/button-secondary.constants.js +++ /dev/null @@ -1,7 +0,0 @@ -import { Size } from '../../../helpers/constants/design-system'; - -export const BUTTON_SECONDARY_SIZES = { - SM: Size.SM, - MD: Size.MD, - LG: Size.LG, -}; diff --git a/ui/components/component-library/button-secondary/button-secondary.js b/ui/components/component-library/button-secondary/button-secondary.js deleted file mode 100644 index 399ea67fe..000000000 --- a/ui/components/component-library/button-secondary/button-secondary.js +++ /dev/null @@ -1,54 +0,0 @@ -import React from 'react'; -import PropTypes from 'prop-types'; -import classnames from 'classnames'; - -import { ButtonBase } from '../button-base'; -import { Color } from '../../../helpers/constants/design-system'; -import { BUTTON_SECONDARY_SIZES } from './button-secondary.constants'; - -export const ButtonSecondary = ({ - className, - danger, - disabled, - size = BUTTON_SECONDARY_SIZES.MD, - ...props -}) => { - const buttonColor = danger ? Color.errorDefault : Color.primaryDefault; - return ( - - ); -}; - -ButtonSecondary.propTypes = { - /** - * An additional className to apply to the ButtonSecondary. - */ - className: PropTypes.string, - /** - * When true, ButtonSecondary color becomes Danger. - */ - danger: PropTypes.bool, - /** - * Boolean to disable button - */ - disabled: PropTypes.bool, - /** - * Possible size values: 'SIZES.SM'(32px), 'SIZES.MD'(40px), 'SIZES.LG'(48px). - * Default value is 'SIZES.MD'. - */ - size: PropTypes.oneOf(Object.values(BUTTON_SECONDARY_SIZES)), - /** - * ButtonSecondary accepts all the props from ButtonBase - */ - ...ButtonBase.propTypes, -}; diff --git a/ui/components/component-library/button-secondary/button-secondary.scss b/ui/components/component-library/button-secondary/button-secondary.scss index f602270bf..c279ce88a 100644 --- a/ui/components/component-library/button-secondary/button-secondary.scss +++ b/ui/components/component-library/button-secondary/button-secondary.scss @@ -1,5 +1,5 @@ .mm-button-secondary { - &:hover { + &:hover:not(&--disabled) { color: var(--color-primary-inverse); background-color: var(--color-primary-default); box-shadow: var(--component-button-primary-shadow); @@ -12,7 +12,7 @@ } // Danger type - &--type-danger { + &--type-danger:not(&--disabled) { color: var(--color-error-default); border: 1px solid var(--color-error-default); background-color: transparent; diff --git a/ui/components/component-library/button-secondary/button-secondary.stories.js b/ui/components/component-library/button-secondary/button-secondary.stories.tsx similarity index 77% rename from ui/components/component-library/button-secondary/button-secondary.stories.js rename to ui/components/component-library/button-secondary/button-secondary.stories.tsx index 94166d359..a7883213f 100644 --- a/ui/components/component-library/button-secondary/button-secondary.stories.js +++ b/ui/components/component-library/button-secondary/button-secondary.stories.tsx @@ -1,14 +1,9 @@ import React from 'react'; -import { - AlignItems, - DISPLAY, - Size, -} from '../../../helpers/constants/design-system'; -import Box from '../../ui/box/box'; -import { IconName } from '..'; -import { ButtonSecondary } from './button-secondary'; -import { BUTTON_SECONDARY_SIZES } from './button-secondary.constants'; +import { StoryFn, Meta } from '@storybook/react'; +import { AlignItems, Display } from '../../../helpers/constants/design-system'; +import { IconName, Box } from '..'; import README from './README.mdx'; +import { ButtonSecondary, ButtonSecondarySize } from '.'; const marginSizeControlOptions = [ undefined, @@ -84,7 +79,7 @@ export default { }, size: { control: 'select', - options: Object.values(BUTTON_SECONDARY_SIZES), + options: Object.values(ButtonSecondarySize), }, marginTop: { options: marginSizeControlOptions, @@ -110,29 +105,29 @@ export default { args: { children: 'Button Secondary', }, -}; +} as Meta; export const DefaultStory = (args) => ; DefaultStory.storyName = 'Default'; -export const SizeStory = (args) => ( - - +export const SizeStory: StoryFn = (args) => ( + + Small Button - + Medium (Default) Button - + Large Button ); SizeStory.storyName = 'Size'; -export const Danger = (args) => ( - +export const Danger: StoryFn = (args) => ( + Normal {/* Test Anchor tag to match exactly as button */} diff --git a/ui/components/component-library/button-secondary/button-secondary.test.js b/ui/components/component-library/button-secondary/button-secondary.test.tsx similarity index 77% rename from ui/components/component-library/button-secondary/button-secondary.test.js rename to ui/components/component-library/button-secondary/button-secondary.test.tsx index 0529664cd..f8730d34a 100644 --- a/ui/components/component-library/button-secondary/button-secondary.test.js +++ b/ui/components/component-library/button-secondary/button-secondary.test.tsx @@ -2,8 +2,7 @@ import { render } from '@testing-library/react'; import React from 'react'; import { IconName } from '..'; -import { ButtonSecondary } from './button-secondary'; -import { BUTTON_SECONDARY_SIZES } from './button-secondary.constants'; +import { ButtonSecondary, ButtonSecondarySize } from '.'; describe('ButtonSecondary', () => { it('should render button element correctly', () => { @@ -45,28 +44,28 @@ describe('ButtonSecondary', () => { const { getByTestId } = render( <> , ); - expect(getByTestId(BUTTON_SECONDARY_SIZES.SM)).toHaveClass( - `mm-button-base--size-${BUTTON_SECONDARY_SIZES.SM}`, + expect(getByTestId(ButtonSecondarySize.Sm)).toHaveClass( + `mm-button-base--size-${ButtonSecondarySize.Sm}`, ); - expect(getByTestId(BUTTON_SECONDARY_SIZES.MD)).toHaveClass( - `mm-button-base--size-${BUTTON_SECONDARY_SIZES.MD}`, + expect(getByTestId(ButtonSecondarySize.Md)).toHaveClass( + `mm-button-base--size-${ButtonSecondarySize.Md}`, ); - expect(getByTestId(BUTTON_SECONDARY_SIZES.LG)).toHaveClass( - `mm-button-base--size-${BUTTON_SECONDARY_SIZES.LG}`, + expect(getByTestId(ButtonSecondarySize.Lg)).toHaveClass( + `mm-button-base--size-${ButtonSecondarySize.Lg}`, ); }); diff --git a/ui/components/component-library/button-secondary/button-secondary.tsx b/ui/components/component-library/button-secondary/button-secondary.tsx new file mode 100644 index 000000000..404b97301 --- /dev/null +++ b/ui/components/component-library/button-secondary/button-secondary.tsx @@ -0,0 +1,40 @@ +import React from 'react'; +import classnames from 'classnames'; + +import { ButtonBase, ButtonBaseProps } from '../button-base'; +import { Color } from '../../../helpers/constants/design-system'; +import { PolymorphicRef } from '../box'; +import type { ButtonSecondaryProps } from './button-secondary.types'; +import { + ButtonSecondarySize, + ButtonSecondaryComponent, +} from './button-secondary.types'; + +export const ButtonSecondary: ButtonSecondaryComponent = React.forwardRef( + ( + { + className = '', + danger, + disabled, + size = ButtonSecondarySize.Md, + ...props + }: ButtonSecondaryProps, + ref?: PolymorphicRef, + ) => { + const buttonColor = danger ? Color.errorDefault : Color.primaryDefault; + return ( + ) }} + /> + ); + }, +); diff --git a/ui/components/component-library/button-secondary/button-secondary.types.ts b/ui/components/component-library/button-secondary/button-secondary.types.ts new file mode 100644 index 000000000..e3d73d467 --- /dev/null +++ b/ui/components/component-library/button-secondary/button-secondary.types.ts @@ -0,0 +1,38 @@ +import type { ButtonBaseStyleUtilityProps } from '../button-base/button-base.types'; +import type { PolymorphicComponentPropWithRef } from '../box'; + +export enum ButtonSecondarySize { + Sm = 'sm', + Md = 'md', + Lg = 'lg', +} + +export interface ButtonSecondaryStyleUtilityProps + extends Omit { + /** + * An additional className to apply to the ButtonSecondary. + */ + className?: string; + /** + * When true, ButtonSecondary color becomes Danger. + */ + danger?: boolean; + /** + * Boolean to disable button + */ + disabled?: boolean; + /** + * Possible size values: 'ButtonSecondarySize.Sm'(32px), 'ButtonSecondarySize.Md'(40px), 'ButtonSecondarySize.Lg'(48px). + * Default value is 'ButtonSecondarySize.Md'. + */ + size?: ButtonSecondarySize; +} + +export type ButtonSecondaryProps = + PolymorphicComponentPropWithRef; + +export type ButtonSecondaryComponent = < + C extends React.ElementType = 'button' | 'a', +>( + props: ButtonSecondaryProps, +) => React.ReactElement | null; diff --git a/ui/components/component-library/button-secondary/index.js b/ui/components/component-library/button-secondary/index.js deleted file mode 100644 index bccde44c2..000000000 --- a/ui/components/component-library/button-secondary/index.js +++ /dev/null @@ -1,2 +0,0 @@ -export { ButtonSecondary } from './button-secondary'; -export { BUTTON_SECONDARY_SIZES } from './button-secondary.constants'; diff --git a/ui/components/component-library/button-secondary/index.ts b/ui/components/component-library/button-secondary/index.ts new file mode 100644 index 000000000..5f7818004 --- /dev/null +++ b/ui/components/component-library/button-secondary/index.ts @@ -0,0 +1,3 @@ +export { ButtonSecondary } from './button-secondary'; +export { ButtonSecondarySize } from './button-secondary.types'; +export type { ButtonSecondaryProps } from './button-secondary.types'; diff --git a/ui/components/component-library/index.js b/ui/components/component-library/index.js index a993c763a..f7ee14fb1 100644 --- a/ui/components/component-library/index.js +++ b/ui/components/component-library/index.js @@ -20,7 +20,7 @@ export { ButtonBase, ButtonBaseSize } from './button-base'; export { ButtonIcon, ButtonIconSize } from './button-icon'; export { ButtonLink, ButtonLinkSize } from './button-link'; export { ButtonPrimary, ButtonPrimarySize } from './button-primary'; -export { ButtonSecondary, BUTTON_SECONDARY_SIZES } from './button-secondary'; +export { ButtonSecondary, ButtonSecondarySize } from './button-secondary'; export { Checkbox } from './checkbox'; export { FormTextField } from './form-text-field'; export { HeaderBase } from './header-base'; diff --git a/ui/components/multichain/account-details/account-details-display.js b/ui/components/multichain/account-details/account-details-display.js index 7e70bfaae..410515089 100644 --- a/ui/components/multichain/account-details/account-details-display.js +++ b/ui/components/multichain/account-details/account-details-display.js @@ -13,7 +13,7 @@ import { } from '../../../selectors'; import { isAbleToExportAccount } from '../../../helpers/utils/util'; import { - BUTTON_SECONDARY_SIZES, + ButtonSecondarySize, ButtonSecondary, Box, } from '../../component-library'; @@ -74,7 +74,7 @@ export const AccountDetailsDisplay = ({ {exportPrivateKeyFeatureEnabled ? ( { trackEvent({ diff --git a/ui/components/multichain/import-account/bottom-buttons.js b/ui/components/multichain/import-account/bottom-buttons.js index d9b32af61..426f53588 100644 --- a/ui/components/multichain/import-account/bottom-buttons.js +++ b/ui/components/multichain/import-account/bottom-buttons.js @@ -5,7 +5,7 @@ import { ButtonPrimary, ButtonSecondary, Box, - BUTTON_SECONDARY_SIZES, + ButtonSecondarySize, } from '../../component-library'; import { Display } from '../../../helpers/constants/design-system'; import { useI18nContext } from '../../../hooks/useI18nContext'; @@ -32,7 +32,7 @@ export default function BottomButtons({ dispatch(actions.hideWarning()); onActionComplete(); }} - size={BUTTON_SECONDARY_SIZES.LG} + size={ButtonSecondarySize.Lg} block > {t('cancel')} @@ -49,7 +49,7 @@ export default function BottomButtons({ } }} disabled={isPrimaryDisabled} - size={BUTTON_SECONDARY_SIZES.LG} + size={ButtonSecondarySize.Lg} data-testid="import-account-confirm-button" block > diff --git a/ui/components/multichain/import-nfts-modal/import-nfts-modal.js b/ui/components/multichain/import-nfts-modal/import-nfts-modal.js index b399c0fb9..0d5544660 100644 --- a/ui/components/multichain/import-nfts-modal/import-nfts-modal.js +++ b/ui/components/multichain/import-nfts-modal/import-nfts-modal.js @@ -44,6 +44,7 @@ import { Modal, ButtonPrimary, ButtonSecondary, + ButtonSecondarySize, Box, FormTextField, Label, @@ -258,7 +259,7 @@ export const ImportNftsModal = ({ onClose }) => { paddingBottom={4} > onClose()} block className="import-nfts-modal__cancel-button" diff --git a/ui/components/multichain/network-list-menu/network-list-menu.js b/ui/components/multichain/network-list-menu/network-list-menu.js index aa410abf8..5cac6e04e 100644 --- a/ui/components/multichain/network-list-menu/network-list-menu.js +++ b/ui/components/multichain/network-list-menu/network-list-menu.js @@ -29,7 +29,7 @@ import { TextColor, } from '../../../helpers/constants/design-system'; import { - BUTTON_SECONDARY_SIZES, + ButtonSecondarySize, ButtonSecondary, Modal, ModalContent, @@ -242,7 +242,7 @@ export const NetworkListMenu = ({ onClose }) => { ) : null} {