UNPKG

1.05 kBJavaScriptView Raw
1import { h } from 'preact'
2
3const filledClasses = 'bg-green b--black-10 dim white '
4const emptyClasses = 'bg-white b--black-30 dim black-80 '
5const disabledClasses = 'bg-moon-gray b--black-10 dim white '
6export const buttonClasses = filledClasses
7
8const sizeClasses = {
9 large: 'f3 pv3 ph4 ',
10 medium: 'f5 pv2 ph3 ',
11 small: 'f6 pv1 ph2 '
12}
13
14export default (props) => {
15 const Tag = props.tagName || 'button'
16 let classes = 'button-reset ba pointer dim br2 nowrap '
17 if (props.disabled) {
18 classes += disabledClasses
19 } else if (!props.empty && props.red) {
20 classes += 'bg-red white b--black-20 '
21 } else {
22 classes += props.empty ? emptyClasses : filledClasses
23 }
24 classes += sizeClasses[props.size || 'medium']
25 classes += props.extraClasses || ''
26
27 const mainThing = h(Tag, Object.assign({
28 className: classes
29 }, props))
30
31 if (props.href) {
32 const aTagProps = {href: props.href}
33 if (props.target) {
34 aTagProps.target = props.target
35 }
36
37 return h('a', aTagProps, [mainThing])
38 }
39
40 return mainThing
41}