-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathbuttons.js
143 lines (131 loc) · 2.68 KB
/
buttons.js
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
import React from 'react'
import styled, { css } from 'styled-components'
import PropTypes from 'prop-types'
import {
colorList,
black as colorBlack,
white,
gray85,
gray30,
gray
} from './colors'
import { bold as fontBold } from './fonts'
import Link from 'next/link'
const display = props => {
switch (props.display) {
case 'inline-block': {
return css`
display: inline-block;
`
}
case 'block': {
return css`
display: block;
`
}
default: {
break
}
}
}
const color = ({ color, theme }) => {
switch (color) {
case 'transparent':
case 'white': {
return css`
color: ${colorBlack};
background-color: ${theme.color[color]};
`
}
default: {
return css`
color: ${white};
background-color: ${theme.color[color]};
`
}
}
}
const round = ({ round }) => {
if (round) {
return css`
height: 50px;
width: 50px;
border-radius: 50px;
display: flex;
justify-content: center;
align-items: center;
padding: 0;
`
}
}
const roundSize = ({ size }) => {
if (round && size) {
return css`
height: ${size};
width: ${size};
border-radius: ${size};
`
}
}
const buttonBaseStyles = css`
border: none;
background-color: ${colorBlack};
padding: .75em;
${fontBold}
font-size: 0.8rem;
cursor: pointer;
vertical-align: middle;
transition: all .4s ease-in-out;
margin-right: .5em;
color: ${white};
text-transform: uppercase;
text-decoration: none;
&:hover {
opacity: 0.75;
}
&:disabled {
opacity: 0.5;
cursor: not-allowed;
}
${display}
${color}
${round}
${roundSize}
`
const buttonBaseProps = {
/** Boolean makes the button an a tag */
a: PropTypes.bool,
/** 'block', 'inline-block' */
display: PropTypes.oneOf(['block', 'inline-block', '']),
/** 'dark', 'light', 'super-light' */
color: PropTypes.oneOf(['', ...colorList]),
/** Boolean makes the button round */
round: PropTypes.bool
}
const buttonBaseDefaultProps = {
marginTopSmall: false,
display: 'inline-block',
border: '',
color: 'black'
}
const StyledButton = styled.button`
${buttonBaseStyles};
`
const AButton = StyledButton.withComponent('a')
export const Button = props => {
if (props.a) {
return <AButton {...props} />
} else {
return <StyledButton {...props} />
}
}
Button.displayName = 'Button'
Button.propTypes = buttonBaseProps
Button.defaultProps = buttonBaseDefaultProps
export const NavButton = props => (
<Link href={props.href} as={props.as} passHref>
<Button a round size={props.size} {...props}>
{props.children}
</Button>
</Link>
)