File size: 3,962 Bytes
84c1942 | 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 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 | import React, { ComponentProps } from 'react';
import { Link } from 'react-router-dom';
import { Button as ReakitButtonBase } from 'reakit/Button';
import styled, { css } from 'styled-components';
import theme from '../../theme';
import { withoutProps } from '../../utils';
import { Button } from '.';
export type OptionProps = {
theme: any;
disabled?: boolean;
red?: boolean;
secondary?: boolean;
danger?: boolean;
};
const getBackgroundColor = ({
theme: internalTheme,
disabled,
red,
secondary,
danger,
}: OptionProps) => {
if (disabled)
return `background-color: ${
internalTheme.light
? 'rgba(0, 0, 0, 0.4)'
: theme.background2.darken(0.3)()
}`;
if (danger) return `background-color: ${theme.dangerBackground()}`;
if (secondary) return `background-color: transparent`;
if (red) return `background-color: ${theme.red.darken(0.2)()}`;
if (internalTheme && internalTheme['button.background']) {
return `background-color: ${internalTheme['button.background']}`;
}
return `background-color: #40A9F3;`;
};
const getBackgroundHoverColor = ({
theme: internalTheme,
disabled,
red,
secondary,
danger,
}: OptionProps) => {
if (disabled)
return `background-color: ${
internalTheme.light
? 'rgba(0, 0, 0, 0.4)'
: theme.background2.darken(0.3)()
}`;
if (danger) return `background-color: #E25D6A`;
if (red) return `background-color: #F27777`;
if (internalTheme && internalTheme['button.hoverBackground']) {
return `background-color: ${internalTheme['button.hoverBackground']}`;
}
if (secondary) return `background-color: #66b9f4`;
return `background-color: #66b9f4;`;
};
const getColor = ({
disabled,
secondary,
theme: internalTheme,
}: OptionProps) => {
if (disabled) return theme.background2.lighten(1.5)();
if (secondary)
return internalTheme.light
? 'rgba(0, 0, 0, 0.75)'
: 'rgba(255, 255, 255, 0.75)';
return 'white';
};
const getHoverColor = ({ secondary, disabled }: OptionProps) => {
if (disabled) return '';
if (secondary) return 'color: white';
return '';
};
const getBorder = ({
theme: internalTheme,
secondary,
danger,
red,
disabled,
}: OptionProps) => {
if (disabled)
return internalTheme.light
? '2px solid rgba(0, 0, 0, 0.3)'
: '2px solid #161A1C';
if (red) return '2px solid #F27777';
if (danger) return '2px solid #E25D6A';
if (internalTheme && internalTheme['button.hoverBackground']) {
return `2px solid ${internalTheme['button.hoverBackground']}`;
}
if (secondary) return `2px solid #66B9F4`;
return '2px solid #66B9F4';
};
export const styles = css<ComponentProps<typeof Button> | any>`
transition: 0.3s ease all;
font-family: Poppins, Roboto, sans-serif;
border: none;
outline: none;
${props => getBackgroundColor(props)};
background-size: 720%;
border: ${props => getBorder(props)};
border-radius: 4px;
box-sizing: border-box;
font-size: 1.125em;
text-align: center;
color: ${props => getColor(props)};
font-weight: 600;
width: ${props => (props.block ? '100%' : 'inherit')};
user-select: none;
text-decoration: none;
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
${props =>
props.small
? css`
padding: 0.5em 0.7em;
font-size: 0.875em;
`
: css`
padding: 0.65em 2.25em;
`};
${props =>
!props.disabled &&
css`
cursor: pointer;
`};
&:hover,
&:focus {
${props => getBackgroundHoverColor(props)};
${props => getHoverColor(props)};
outline: 0 !important;
}
`;
// @ts-ignore
export const LinkButton = styled(withoutProps(`small`)(Link))`
${styles};
`;
// eslint-disable-next-line
export const AButton = styled(withoutProps(`small`)(props => <a {...props} />))`
${styles};
`;
export const ReakitButton = styled(withoutProps(`small`)(ReakitButtonBase))`
${styles}
`;
|