feat(pixel-perfecting): add icon prop on button

This commit is contained in:
eliabejr 2019-01-17 17:24:00 -03:00
parent 4428b6e47f
commit 069913ebf6
1 changed files with 23 additions and 3 deletions

View File

@ -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;