feat(pixel-perfecting): add icon prop on button
This commit is contained in:
parent
4428b6e47f
commit
069913ebf6
|
@ -57,12 +57,19 @@ const Secondary = styled(DefaultButton)`
|
|||
}
|
||||
`;
|
||||
|
||||
const Icon = styled.img`
|
||||
height: 9px;
|
||||
width: 12px;
|
||||
margin-right: 10px;
|
||||
`;
|
||||
|
||||
type Props = {
|
||||
label: string,
|
||||
onClick?: () => void,
|
||||
to?: string,
|
||||
variant?: 'primary' | 'secondary',
|
||||
disabled?: boolean,
|
||||
icon?: string,
|
||||
className?: string,
|
||||
isLoading?: boolean,
|
||||
};
|
||||
|
@ -73,18 +80,31 @@ export const Button = ({
|
|||
to,
|
||||
variant,
|
||||
disabled,
|
||||
icon,
|
||||
className,
|
||||
isLoading,
|
||||
}: Props) => {
|
||||
if (to && onClick) throw new Error('Should define either "to" or "onClick"');
|
||||
|
||||
const props = { onClick, disabled: disabled || isLoading, className };
|
||||
const props = { onClick, disabled: disabled || isLoading, icon: null, className };
|
||||
const buttonLabel = isLoading ? 'Loading...' : label;
|
||||
|
||||
const component = variant === 'primary' ? (
|
||||
<Primary {...props}>{buttonLabel}</Primary>
|
||||
<Primary {...props}>
|
||||
{icon ?
|
||||
<Icon src={icon} />
|
||||
: null
|
||||
}
|
||||
{buttonLabel}
|
||||
</Primary>
|
||||
) : (
|
||||
<Secondary {...props}>{buttonLabel}</Secondary>
|
||||
<Secondary {...props}>
|
||||
{icon ?
|
||||
<Icon src={icon} />
|
||||
: null
|
||||
}
|
||||
{buttonLabel}
|
||||
</Secondary>
|
||||
);
|
||||
|
||||
return to ? <Link to={String(to)}>{component}</Link> : component;
|
||||
|
|
Loading…
Reference in New Issue