File size: 2,314 Bytes
1e92f2d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
// @flow
import React from 'react';
import {
A,
StyledLink,
StyledButton,
StyledWhiteIconButton,
StyledWhiteButton,
StyledPrimaryButton,
StyledWarnButton,
StyledOutlineButton,
StyledHoverWarnOutlineButton,
StyledPrimaryOutlineButton,
StyledWhiteOutlineButton,
StyledTextButton,
StyledFacebookButton,
StyledTwitterButton,
} from './style';
const handleLinkWrapping = (Component, props) => {
const { href, to, target, children, disabled, isLoading, ...rest } = props;
const button = (
<Component disabled={disabled || isLoading} {...rest}>
{children}
</Component>
);
if (href)
return (
<A
href={href}
target={target || '_blank'}
rel={!target ? 'noopener noreferrer' : undefined}
>
{button}
</A>
);
if (to) return <StyledLink to={to}>{button}</StyledLink>;
return button;
};
type To = {
pathname?: string,
search?: string,
state?: Object,
};
type Props = {
target?: string,
href?: string,
to?: string | To,
children: React$Node,
disabled?: boolean,
isLoading?: boolean,
size?: 'small',
};
export const Button = (props: Props) => handleLinkWrapping(StyledButton, props);
export const WhiteIconButton = (props: Props) =>
handleLinkWrapping(StyledWhiteIconButton, props);
export const WhiteButton = (props: Props) =>
handleLinkWrapping(StyledWhiteButton, props);
export const PrimaryButton = (props: Props) =>
handleLinkWrapping(StyledPrimaryButton, props);
export const WarnButton = (props: Props) =>
handleLinkWrapping(StyledWarnButton, props);
export const OutlineButton = (props: Props) =>
handleLinkWrapping(StyledOutlineButton, props);
export const PrimaryOutlineButton = (props: Props) =>
handleLinkWrapping(StyledPrimaryOutlineButton, props);
export const WhiteOutlineButton = (props: Props) =>
handleLinkWrapping(StyledWhiteOutlineButton, props);
export const HoverWarnOutlineButton = (props: Props) =>
handleLinkWrapping(StyledHoverWarnOutlineButton, props);
export const TextButton = (props: Props) =>
handleLinkWrapping(StyledTextButton, props);
export const FacebookButton = (props: Props) =>
handleLinkWrapping(StyledFacebookButton, props);
export const TwitterButton = (props: Props) =>
handleLinkWrapping(StyledTwitterButton, props);
|