import * as React from 'react';
import { Link as ReactRouterLink } from 'react-router-dom';
import styled from 'styled-components';
import { ThemeInterface } from 'ts/@next/components/siteWrap';
import { colors } from 'ts/style/colors';
interface ButtonInterface {
bgColor?: string;
color?: string;
children?: React.ReactNode | string;
isTransparent?: boolean;
isNoBorder?: boolean;
isNoPadding?: boolean;
isWithArrow?: boolean;
isAccentColor?: boolean;
hasIcon?: boolean | string;
isInline?: boolean;
href?: string;
type?: string;
to?: string;
onClick?: () => any;
theme?: ThemeInterface;
}
export const Button = (props: ButtonInterface) => {
const {
children,
href,
isWithArrow,
to,
} = props;
let linkElem;
if (href) { linkElem = 'a'; }
if (to) { linkElem = ReactRouterLink; }
const Component = linkElem ? ButtonBase.withComponent(linkElem) : ButtonBase;
return (
{children}
{ isWithArrow &&
}
);
};
const ButtonBase = styled.button`
appearance: none;
border: 1px solid transparent;
display: inline-block;
background-color: ${props => props.bgColor || colors.brandLight};
background-color: ${props => (props.isTransparent || props.isWithArrow) && 'transparent'};
border-color: ${props => (props.isTransparent && !props.isWithArrow) && 'rgba(255, 255, 255, .4)'};
color: ${props => props.isAccentColor ? props.theme.linkColor : (props.color || props.theme.textColor)};
padding: ${props => (!props.isNoPadding && !props.isWithArrow) && '18px 30px'};
white-space: ${props => props.isWithArrow && 'nowrap'};
text-align: center;
font-size: ${props => props.isWithArrow ? '20px' : '18px'};
text-decoration: none;
cursor: pointer;
outline: none;
transition: background-color 0.35s, border-color 0.35s;
svg {
margin-left: 9px;
transition: transform 0.5s;
transform: translate3d(-2px, 2px, 0);
}
path {
fill: ${props => props.isAccentColor ? props.theme.linkColor : (props.color || props.theme.textColor)};
}
&:hover {
background-color: ${props => (!props.isTransparent && !props.isWithArrow) && '#04BEA8'};
border-color: ${props => (props.isTransparent && !props.isNoBorder && !props.isWithArrow) && '#00AE99'};
svg {
transform: translate3d(2px, -2px, 0);
}
}
`;