mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-11-23 02:10:12 +01:00
065c499753
* update ButtonIcon to TS lint updates fix lint issues add ref fix as prop test updates * box and icon updates for support * Update ui/components/component-library/text-field/README.mdx Co-authored-by: George Marshall <george.marshall@consensys.net> * fix disabled * update types for as * update readme * fix storybook * george changes to button icon * revert headerbase * box prop back to HTMLElementTagNameMap --------- Co-authored-by: George Marshall <george.marshall@consensys.net> Co-authored-by: legobeat <109787230+legobeat@users.noreply.github.com>
73 lines
1.8 KiB
TypeScript
73 lines
1.8 KiB
TypeScript
import React from 'react';
|
|
import classnames from 'classnames';
|
|
|
|
import {
|
|
AlignItems,
|
|
BackgroundColor,
|
|
BorderRadius,
|
|
DISPLAY,
|
|
IconColor,
|
|
JustifyContent,
|
|
} from '../../../helpers/constants/design-system';
|
|
|
|
import Box from '../../ui/box';
|
|
import { Icon, IconSize } from '../icon';
|
|
|
|
import { ButtonIconSize, ButtonIconProps } from './button-icon.types';
|
|
|
|
const buttonIconSizeToIconSize: Record<ButtonIconSize, IconSize> = {
|
|
[ButtonIconSize.Sm]: IconSize.Sm,
|
|
[ButtonIconSize.Lg]: IconSize.Lg,
|
|
};
|
|
|
|
export const ButtonIcon = React.forwardRef(
|
|
(
|
|
{
|
|
ariaLabel,
|
|
as = 'button',
|
|
className = '',
|
|
color = IconColor.iconDefault,
|
|
href,
|
|
size = ButtonIconSize.Lg,
|
|
iconName,
|
|
disabled,
|
|
iconProps,
|
|
...props
|
|
}: ButtonIconProps,
|
|
ref: React.Ref<HTMLElement>,
|
|
) => {
|
|
const Tag = href ? 'a' : as;
|
|
const isDisabled = disabled && Tag === 'button';
|
|
return (
|
|
<Box
|
|
aria-label={ariaLabel}
|
|
as={Tag}
|
|
className={classnames(
|
|
'mm-button-icon',
|
|
`mm-button-icon--size-${String(size)}`,
|
|
{
|
|
'mm-button-icon--disabled': Boolean(disabled),
|
|
},
|
|
className,
|
|
)}
|
|
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
|
|
display={DISPLAY.INLINE_FLEX}
|
|
justifyContent={JustifyContent.center}
|
|
alignItems={AlignItems.center}
|
|
borderRadius={BorderRadius.LG}
|
|
backgroundColor={BackgroundColor.transparent}
|
|
{...(href ? { href } : {})}
|
|
ref={ref}
|
|
{...props}
|
|
>
|
|
<Icon
|
|
name={iconName}
|
|
size={buttonIconSizeToIconSize[size]}
|
|
{...iconProps}
|
|
/>
|
|
</Box>
|
|
);
|
|
},
|
|
);
|