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

ButtonIcon background & ButtonBase disabled update (#19976)

* button background hover updates

* add buttonlink underline

* update button base disabled

* fix size auto

* Update ui/components/component-library/button-link/button-link.stories.js

Co-authored-by: George Marshall <george.marshall@consensys.net>

* remove underline

---------

Co-authored-by: George Marshall <george.marshall@consensys.net>
This commit is contained in:
Garrett Bear 2023-07-13 13:22:40 -07:00 committed by GitHub
parent 719d8a499b
commit 090476d9a2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 67 additions and 44 deletions

View File

@ -33,7 +33,7 @@
&--disabled, &--disabled,
&:disabled { &:disabled {
opacity: 0.3; opacity: var(--opacity-disabled);
cursor: not-allowed; cursor: not-allowed;
} }

View File

@ -1,7 +1,5 @@
.mm-button-icon { .mm-button-icon {
--button-icon-size: var(--size, 24px); --button-icon-size: var(--size, 24px);
--button-icon-opacity-hover: 0.5; // TODO: replace with design tokens
--button-icon-opacity-disabled: 0.3; // TODO: replace with design tokens
height: var(--button-icon-size); height: var(--button-icon-size);
width: var(--button-icon-size); width: var(--button-icon-size);
@ -9,15 +7,24 @@
cursor: pointer; cursor: pointer;
// ButtonIcon default states // ButtonIcon default states
&:active,
&:hover { &:hover {
opacity: var(--button-icon-opacity-hover); background-color: var(--color-background-hover);
}
&:active {
background-color: var(--color-background-pressed);
} }
&--disabled, &--disabled,
&:disabled { &:disabled {
opacity: var(--button-icon-opacity-disabled); opacity: var(--opacity-disabled);
cursor: not-allowed; cursor: not-allowed;
&:hover,
&:active {
background-color: transparent;
}
} }
// ButtonIcon Sizes // ButtonIcon Sizes
@ -25,6 +32,10 @@
--button-icon-size: 24px; --button-icon-size: 24px;
} }
&--size-md {
--button-icon-size: 28px;
}
&--size-lg { &--size-lg {
--button-icon-size: 32px; --button-icon-size: 32px;
} }

View File

@ -1,6 +1,6 @@
import React from 'react'; import React from 'react';
import { ComponentStory, ComponentMeta } from '@storybook/react'; import { StoryFn, Meta } from '@storybook/react';
import { Color } from '../../../helpers/constants/design-system'; import { IconColor } from '../../../helpers/constants/design-system';
import { IconName } from '..'; import { IconName } from '..';
import { ButtonIconSize } from './button-icon.types'; import { ButtonIconSize } from './button-icon.types';
import { ButtonIcon } from './button-icon'; import { ButtonIcon } from './button-icon';
@ -21,11 +21,9 @@ export default {
options: ['button', 'a'], options: ['button', 'a'],
}, },
}, },
} as ComponentMeta<typeof ButtonIcon>; } as Meta<typeof ButtonIcon>;
const Template: ComponentStory<typeof ButtonIcon> = (args) => ( const Template: StoryFn<typeof ButtonIcon> = (args) => <ButtonIcon {...args} />;
<ButtonIcon {...args} />
);
export const DefaultStory = Template.bind({}); export const DefaultStory = Template.bind({});
@ -36,7 +34,7 @@ DefaultStory.args = {
DefaultStory.storyName = 'Default'; DefaultStory.storyName = 'Default';
export const IconNameStory: ComponentStory<typeof ButtonIcon> = (args) => ( export const IconNameStory: StoryFn<typeof ButtonIcon> = (args) => (
<ButtonIcon {...args} /> <ButtonIcon {...args} />
); );
@ -47,7 +45,7 @@ IconNameStory.args = {
IconNameStory.storyName = 'IconName'; IconNameStory.storyName = 'IconName';
export const SizeStory: ComponentStory<typeof ButtonIcon> = (args) => ( export const SizeStory: StoryFn<typeof ButtonIcon> = (args) => (
<> <>
<ButtonIcon <ButtonIcon
{...args} {...args}
@ -55,10 +53,16 @@ export const SizeStory: ComponentStory<typeof ButtonIcon> = (args) => (
iconName={IconName.Close} iconName={IconName.Close}
ariaLabel="Close" ariaLabel="Close"
/> />
<ButtonIcon
{...args}
size={ButtonIconSize.Md}
iconName={IconName.Close}
ariaLabel="Close"
/>
<ButtonIcon <ButtonIcon
{...args} {...args}
size={ButtonIconSize.Lg} size={ButtonIconSize.Lg}
color={Color.primaryDefault} color={IconColor.primaryDefault}
iconName={IconName.Close} iconName={IconName.Close}
ariaLabel="Close" ariaLabel="Close"
/> />
@ -67,60 +71,60 @@ export const SizeStory: ComponentStory<typeof ButtonIcon> = (args) => (
SizeStory.storyName = 'Size'; SizeStory.storyName = 'Size';
export const AriaLabel: ComponentStory<typeof ButtonIcon> = (args) => ( export const AriaLabel: StoryFn<typeof ButtonIcon> = (args) => (
<> <>
<ButtonIcon <ButtonIcon
{...args}
as="button" as="button"
iconName={IconName.Close} iconName={IconName.Close}
ariaLabel="Close" ariaLabel="Close"
{...args}
/> />
<ButtonIcon <ButtonIcon
{...args}
as="a" as="a"
href="https://metamask.io/" href="https://metamask.io/"
target="_blank" target="_blank"
color={Color.primaryDefault} color={IconColor.primaryDefault}
iconName={IconName.Export} iconName={IconName.Export}
ariaLabel="Visit MetaMask.io" ariaLabel="Visit MetaMask.io"
{...args}
/> />
</> </>
); );
export const As: ComponentStory<typeof ButtonIcon> = (args) => ( export const As: StoryFn<typeof ButtonIcon> = (args) => (
<> <>
<ButtonIcon {...args} iconName={IconName.Close} ariaLabel="close" /> <ButtonIcon {...args} iconName={IconName.Close} ariaLabel="close" />
<ButtonIcon <ButtonIcon
as="a" as="a"
href="#" href="#"
{...args} {...args}
color={Color.primaryDefault} color={IconColor.primaryDefault}
iconName={IconName.Export} iconName={IconName.Export}
ariaLabel="demo" ariaLabel="demo"
/> />
</> </>
); );
export const Href: ComponentStory<typeof ButtonIcon> = (args) => ( export const Href: StoryFn<typeof ButtonIcon> = (args) => (
<ButtonIcon iconName={IconName.Export} {...args} target="_blank" /> <ButtonIcon {...args} iconName={IconName.Export} target="_blank" />
); );
Href.args = { Href.args = {
ariaLabel: 'Visit Metamask.io', ariaLabel: 'Visit Metamask.io',
href: 'https://metamask.io/', href: 'https://metamask.io/',
color: Color.primaryDefault, color: IconColor.primaryDefault,
}; };
export const ColorStory: ComponentStory<typeof ButtonIcon> = (args) => ( export const ColorStory: StoryFn<typeof ButtonIcon> = (args) => (
<ButtonIcon {...args} iconName={IconName.Close} ariaLabel="close" /> <ButtonIcon {...args} iconName={IconName.Close} ariaLabel="close" />
); );
ColorStory.storyName = 'Color'; ColorStory.storyName = 'Color';
ColorStory.args = { ColorStory.args = {
color: Color.primaryDefault, color: IconColor.primaryDefault,
}; };
export const Disabled: ComponentStory<typeof ButtonIcon> = (args) => ( export const Disabled: StoryFn<typeof ButtonIcon> = (args) => (
<ButtonIcon {...args} iconName={IconName.Close} ariaLabel="close" /> <ButtonIcon {...args} iconName={IconName.Close} ariaLabel="close" />
); );

View File

@ -56,6 +56,12 @@ describe('ButtonIcon', () => {
size={ButtonIconSize.Sm} size={ButtonIconSize.Sm}
data-testid={ButtonIconSize.Sm} data-testid={ButtonIconSize.Sm}
/> />
<ButtonIcon
iconName={IconName.AddSquare}
ariaLabel="add"
size={ButtonIconSize.Md}
data-testid={ButtonIconSize.Md}
/>
<ButtonIcon <ButtonIcon
iconName={IconName.AddSquare} iconName={IconName.AddSquare}
ariaLabel="add" ariaLabel="add"
@ -67,6 +73,9 @@ describe('ButtonIcon', () => {
expect(getByTestId(ButtonIconSize.Sm)).toHaveClass( expect(getByTestId(ButtonIconSize.Sm)).toHaveClass(
`mm-button-icon--size-${ButtonIconSize.Sm}`, `mm-button-icon--size-${ButtonIconSize.Sm}`,
); );
expect(getByTestId(ButtonIconSize.Md)).toHaveClass(
`mm-button-icon--size-${ButtonIconSize.Md}`,
);
expect(getByTestId(ButtonIconSize.Lg)).toHaveClass( expect(getByTestId(ButtonIconSize.Lg)).toHaveClass(
`mm-button-icon--size-${ButtonIconSize.Lg}`, `mm-button-icon--size-${ButtonIconSize.Lg}`,
); );

View File

@ -5,7 +5,7 @@ import {
AlignItems, AlignItems,
BackgroundColor, BackgroundColor,
BorderRadius, BorderRadius,
DISPLAY, Display,
IconColor, IconColor,
JustifyContent, JustifyContent,
} from '../../../helpers/constants/design-system'; } from '../../../helpers/constants/design-system';
@ -17,6 +17,7 @@ import { ButtonIconSize, ButtonIconProps } from './button-icon.types';
const buttonIconSizeToIconSize: Record<ButtonIconSize, IconSize> = { const buttonIconSizeToIconSize: Record<ButtonIconSize, IconSize> = {
[ButtonIconSize.Sm]: IconSize.Sm, [ButtonIconSize.Sm]: IconSize.Sm,
[ButtonIconSize.Md]: IconSize.Md,
[ButtonIconSize.Lg]: IconSize.Lg, [ButtonIconSize.Lg]: IconSize.Lg,
}; };
@ -52,7 +53,7 @@ export const ButtonIcon = React.forwardRef(
)} )}
color={color} color={color}
{...(isDisabled ? { disabled: true } : {})} // only allow disabled attribute to be passed down to the Box when the as prop is equal to a button element {...(isDisabled ? { disabled: true } : {})} // only allow disabled attribute to be passed down to the Box when the as prop is equal to a button element
display={DISPLAY.INLINE_FLEX} display={Display.InlineFlex}
justifyContent={JustifyContent.center} justifyContent={JustifyContent.center}
alignItems={AlignItems.center} alignItems={AlignItems.center}
borderRadius={BorderRadius.LG} borderRadius={BorderRadius.LG}

View File

@ -5,6 +5,7 @@ import { IconColor } from '../../../helpers/constants/design-system';
export enum ButtonIconSize { export enum ButtonIconSize {
Sm = 'sm', Sm = 'sm',
Md = 'md',
Lg = 'lg', Lg = 'lg',
} }

View File

@ -1,36 +1,27 @@
.mm-button-link {
&:hover {
opacity: 0.5;
}
.mm-button-link {
&:active { &:active {
opacity: 0.5; color: var(--color-primary-alternative);
} }
&--disabled { &--disabled {
&:hover {
opacity: 0.3;
}
&:active { &:active {
opacity: 0.3; color: var(--color-primary-default);
} }
} }
&--type-danger { &--type-danger {
&:hover { &:hover {
color: var(--color-error-default); color: var(--color-error-default);
opacity: 0.5;
} }
&:active { &:active {
color: var(--color-error-default); color: var(--color-error-alternative);
opacity: 0.5;
} }
} }
&--type-danger#{&}--disabled:hover { &--type-danger#{&}--disabled:active {
opacity: 0.3; color: var(--color-error-default);
} }
&--size-auto { &--size-auto {

View File

@ -4,6 +4,12 @@
* This will help improve specificity and reduce the chance of * This will help improve specificity and reduce the chance of
* unintended overrides. * unintended overrides.
**/ **/
// Temp CSS Variables
:root {
--opacity-disabled: 0.5;
}
// Atoms // Atoms
@import 'box/box'; @import 'box/box';
@import 'text/text'; @import 'text/text';