-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathButton.tsx
More file actions
142 lines (131 loc) · 3.44 KB
/
Copy pathButton.tsx
File metadata and controls
142 lines (131 loc) · 3.44 KB
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
import React, {ButtonHTMLAttributes} from 'react'
import styled from 'styled-components'
import {useTheme} from '../../hooks/useTheme'
import {ThemeType} from '../../theme/theme'
import Flex from './Flex'
type Props = {
className?: string
variant?: Variant
uppercase?: boolean
bold?: boolean
disabled?: boolean
size?: Size
iconBefore?: React.ReactNode
noWrap?: boolean
disableHoverTransform?: boolean
} & ButtonHTMLAttributes<HTMLButtonElement>
type Variant = 'accent' | 'default' | 'outline' | 'danger'
export type Size = 'small' | 'default' | 'large' | 'very-large'
const variantStyleValues = () => ({
accent: {
color: 'white', // this is by design so it doesn't change when themes switch
backgroundColor: 'var(--color-accent)',
border: `2px solid var(--color-accent)`,
},
default: {
color: 'var(--color-secondary)',
backgroundColor: 'var(--color-primary)',
border: `2px solid var(--color-secondary)`,
},
outline: {
color: 'var(--color-secondary)',
backgroundColor: 'var(--color-primary)',
border: `2px solid var(--color-accent)`,
},
danger: {
color: 'var(--color-primary)',
backgroundColor: 'var(--color-danger)',
border: `2px solid var(--color-danger)`,
},
})
const sizeStyleValues = {
small: {
fontSize: '12px',
},
default: {
fontSize: '16px',
},
large: {
fontSize: '20px',
},
'very-large': {
fontSize: '24px',
},
}
const Button = ({
children,
className,
variant,
uppercase,
bold,
disabled,
size,
iconBefore,
noWrap,
disableHoverTransform = false,
...props
}: Props) => {
const {theme} = useTheme()
return (
<StyledButton
className={className}
theme={theme}
variant={variant || 'default'}
uppercase={uppercase}
bold={bold}
disabled={disabled}
size={size || 'default'}
noWrap={noWrap}
disableHoverTransform={disableHoverTransform}
{...props}
>
<Flex gap="12px" justifyContent="center">
{iconBefore}
{children}
</Flex>
</StyledButton>
)
}
const StyledButton = styled.button<{
theme: ThemeType
variant: Variant
uppercase?: boolean
bold?: boolean
disabled?: boolean
size: Size
noWrap?: boolean
disableHoverTransform?: boolean
}>`
background-color: ${(props) =>
variantStyleValues()[props.variant].backgroundColor};
color: ${(props) => variantStyleValues()[props.variant].color};
border: ${(props) => variantStyleValues()[props.variant].border};
padding: 0.5em 1.25em;
border-radius: 10px;
font-size: ${(props) => sizeStyleValues[props.size].fontSize};
font-weight: ${(props) => (props.bold ? 'bold' : 'normal')};
opacity: ${(props) => props.disabled && 0.5};
text-transform: ${(props) => (props.uppercase ? 'uppercase' : 'unset')};
white-space: ${(props) => (props.noWrap ? 'nowrap' : 'unset')};
transition: ${(props) =>
!props.disabled &&
!props.disableHoverTransform &&
'transform 0.2s ease-in-out'};
&:hover {
cursor: ${(props) => !props.disabled && 'pointer'};
transform: ${(props) =>
!props.disabled && !props.disableHoverTransform && 'scale(1.05)'};
transition: ${(props) =>
!props.disabled &&
!props.disableHoverTransform &&
'transform 0.2s ease-in-out'};
opacity: ${(props) => !props.disabled && '0.9'};
box-shadow: ${(props) =>
!props.disabled && `0 0 10px 0 var(--color-shadow)`};
}
svg {
width: 22px;
height: 22px;
}
`
export default Button