1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-23 09:52:26 +01:00
metamask-extension/ui/components/component-library/button-link/button-link.tsx
Garrett Bear 70a13296c9
Feat/18889/update buttonlink ts (#20372)
* fix buttonlink alignment

* ButtonLink TS migration

* fix lint

* remove ButtonBase loading error feat

* move padding 0 to ButtonBase

* fix color issue

* fix test file

* fix snapshot

* Update ui/components/component-library/button-link/README.mdx

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

* readme fix

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

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

---------

Co-authored-by: George Marshall <george.marshall@consensys.net>
2023-08-04 14:00:05 -07:00

60 lines
1.9 KiB
TypeScript

import React from 'react';
import classnames from 'classnames';
import { ButtonBase, IconSize } from '..';
import {
BackgroundColor,
Color,
} from '../../../helpers/constants/design-system';
import type { PolymorphicRef } from '../box';
import type { ButtonBaseProps } from '../button-base';
import type { ButtonLinkProps } from './button-link.types';
import { ButtonLinkSize, ButtonLinkComponent } from './button-link.types';
export const ButtonLink: ButtonLinkComponent = React.forwardRef(
<C extends React.ElementType = 'button' | 'a'>(
{
className,
color,
danger,
disabled,
loading,
size = ButtonLinkSize.Auto,
...props
}: ButtonLinkProps<C>,
ref?: PolymorphicRef<C>,
) => {
return (
<ButtonBase
className={classnames(className, 'mm-button-link', {
'mm-button-link--type-danger': danger,
'mm-button-link--disabled': disabled,
'mm-button-link--loading': loading,
'mm-button-link--size-inherit': size === ButtonLinkSize.Inherit,
'mm-button-link--size-auto': size === ButtonLinkSize.Auto,
})}
paddingLeft={0}
paddingRight={0}
size={size === ButtonLinkSize.Inherit ? null : size}
backgroundColor={BackgroundColor.transparent}
color={color || (danger ? Color.errorDefault : Color.primaryDefault)}
borderRadius={null}
startIconProps={{
size:
size === ButtonLinkSize.Inherit ? IconSize.Inherit : IconSize.Sm,
}}
endIconProps={{
size:
size === ButtonLinkSize.Inherit ? IconSize.Inherit : IconSize.Sm,
}}
iconLoadingProps={{
size:
size === ButtonLinkSize.Inherit ? IconSize.Inherit : IconSize.Md,
color: color || (danger ? Color.errorDefault : Color.primaryDefault),
}}
ref={ref}
{...{ disabled, loading, ...(props as ButtonBaseProps<C>) }}
/>
);
},
);