1 |
|
2 | import { h } from 'preact';
|
3 | import getComponent from './utils/get-styled-component';
|
4 | import { Icon } from './icon';
|
5 |
|
6 | const preventDefault = e => {
|
7 | e.preventDefault();
|
8 | };
|
9 |
|
10 | export const Button = getComponent({
|
11 | tagName: 'button',
|
12 | baseClasses: 'br2 ba',
|
13 | options: {
|
14 | size: ['tiny', 'large'],
|
15 | pressed: ['pressed'],
|
16 | variant: ['primary', 'stop', 'disabled']
|
17 | },
|
18 | defaultProps: {
|
19 | onContextMenu: preventDefault
|
20 | },
|
21 | fn: ({ tiny, large, disabled, pressed, primary, stop }) => {
|
22 | let classes = ['bn'];
|
23 |
|
24 | if (tiny) {
|
25 | classes.push('pa1');
|
26 | } else if (large) {
|
27 | classes.push('pa3 fw6');
|
28 | } else {
|
29 | classes.push('pa2');
|
30 | }
|
31 |
|
32 |
|
33 | if (disabled) {
|
34 | classes.push('mid-gray bg-light-gray not-allowed');
|
35 | return classes.join(' ');
|
36 | }
|
37 |
|
38 |
|
39 | classes.push('pointer');
|
40 |
|
41 | if (pressed) {
|
42 | classes.push('shadow-3');
|
43 | } else {
|
44 | classes.push('shadow-2');
|
45 | }
|
46 |
|
47 | if (stop) {
|
48 | classes.push('white bg-red');
|
49 | }
|
50 | if (primary) {
|
51 | classes.push('dark-blue bg-light-blue');
|
52 | }
|
53 | if (!stop && !primary) {
|
54 | classes.push('dark-blue');
|
55 | if (pressed) {
|
56 | classes.push('bg-lightest-blue');
|
57 | } else {
|
58 | classes.push('bg-white');
|
59 | }
|
60 | }
|
61 |
|
62 | return classes.join(' ');
|
63 | }
|
64 | });
|
65 |
|
66 | export const TapIconButton = getComponent({
|
67 | baseClasses: 'button-reset pointer pa0 ma0 bn bg-transparent flex items-center justify-center',
|
68 | style: {
|
69 | width: '40px',
|
70 | height: '40px'
|
71 | },
|
72 | options: {
|
73 | icon: ['icon'],
|
74 | color: ['color']
|
75 | },
|
76 | renderChildren: ({ icon, color }) => [h(Icon, { icon: icon, color: color, size: '28' })]
|
77 | }); |
\ | No newline at end of file |