1 |
|
2 | import getComponent from './utils/get-styled-component';
|
3 | import { h } from 'preact';
|
4 | import { Icon } from './icon';
|
5 | import cn from 'classnames';
|
6 |
|
7 | const cardStyles = {
|
8 | backfaceVisibility: 'hidden',
|
9 | webkitBackfaceVisibility: 'hidden',
|
10 | top: '0',
|
11 | left: '0'
|
12 | };
|
13 |
|
14 | export const FlipContainer = ({
|
15 | front,
|
16 | back,
|
17 | flipped,
|
18 | height,
|
19 | width,
|
20 | className,
|
21 | style,
|
22 | direction = 'vertical',
|
23 | perspective = '100px'
|
24 | }) => {
|
25 | const axis = direction === 'vertical' ? 'X' : 'Y';
|
26 | const rotateZero = `rotate${axis}(0deg)`;
|
27 | const rotateFlipped = `rotate${axis}(180deg)`;
|
28 | return h(
|
29 | 'div',
|
30 | {
|
31 | className: className,
|
32 | style: Object.assign({
|
33 | position: 'relative',
|
34 | perspective,
|
35 | width,
|
36 | height
|
37 | }, style)
|
38 | },
|
39 | h(
|
40 | 'div',
|
41 | {
|
42 | style: {
|
43 | transition: '0.6s',
|
44 | transformStyle: 'preserve-3d',
|
45 | webkitTransformStyle: 'preserve-3d',
|
46 | position: 'relative',
|
47 | transformOrigin: 'center',
|
48 | webkitTransformOrigin: 'center',
|
49 | width: '100%',
|
50 | height: '100%',
|
51 | transform: !flipped ? rotateFlipped : '',
|
52 | webkitTransform: !flipped ? rotateFlipped : ''
|
53 | }
|
54 | },
|
55 | h(
|
56 | 'div',
|
57 | {
|
58 | style: Object.assign({}, cardStyles, {
|
59 | transform: rotateFlipped,
|
60 | webkitTransform: rotateFlipped,
|
61 | width: '100%',
|
62 | height: '100%',
|
63 | position: 'relative'
|
64 | })
|
65 | },
|
66 | front
|
67 | ),
|
68 | h(
|
69 | 'div',
|
70 | {
|
71 | style: Object.assign({}, cardStyles, {
|
72 | zIndex: 2,
|
73 | transform: rotateZero,
|
74 | webkitTransform: rotateZero,
|
75 | width: '100%',
|
76 | height: '100%',
|
77 | position: 'absolute'
|
78 | })
|
79 | },
|
80 | back
|
81 | )
|
82 | )
|
83 | );
|
84 | };
|
85 |
|
86 | export const FlipIcon = getComponent({
|
87 | options: {
|
88 | complete: ['complete'],
|
89 | icon: ['icon']
|
90 | },
|
91 | renderChildren: ({ icon, complete }) => {
|
92 | return [h(FlipContainer, {
|
93 | width: '20px',
|
94 | height: '20px',
|
95 | flipped: complete,
|
96 | front: h(Icon, { size: '20', icon: icon }),
|
97 | back: h(Icon, { className: 'light-blue', size: '20', icon: 'check_circle' })
|
98 | })];
|
99 | }
|
100 | });
|
101 |
|
102 | export const DrawerLink = getComponent({
|
103 | tagName: 'a',
|
104 | baseClasses: 'link pv1 mt1 f5 fw3 flex items-center',
|
105 | options: {
|
106 | active: ['active'],
|
107 | disabled: ['disabled'],
|
108 | completeness: ['complete']
|
109 | },
|
110 | fn: ({ active, disabled }) => cn({
|
111 | 'light-blue': active,
|
112 | 'mid-gray not-allowed': disabled,
|
113 | 'white hover-moon-gray': !active && !disabled
|
114 | }),
|
115 | renderChildren: ({ icon, title, complete }) => [h(FlipIcon, { icon: icon, complete: complete }), h(
|
116 | 'span',
|
117 | { 'data-e2e': `${title}Nav`, className: icon ? 'pl2' : null },
|
118 | title
|
119 | )]
|
120 | });
|
121 |
|
122 | export const DrawerLinkContainer = getComponent({
|
123 | baseClasses: 'link db pt2 pl3 f4',
|
124 | options: {
|
125 | completeness: ['complete'],
|
126 | title: ['title']
|
127 | },
|
128 | renderChildren: ({ complete, title, children }) => [h(
|
129 | 'div',
|
130 | { className: 'flex items-center' },
|
131 | h(Icon, {
|
132 | className: cn('light-blue pr2', {
|
133 | hidden: !complete
|
134 | }),
|
135 | size: '20',
|
136 | icon: 'check_circle'
|
137 | }),
|
138 | h(
|
139 | 'h3',
|
140 | { className: 'fw3 f6 ma0 ttu mid-gray bb b--mid-gray pb2 pt1 relative flex-grow-1' },
|
141 | title
|
142 | )
|
143 | ), h(
|
144 | 'div',
|
145 | null,
|
146 | children
|
147 | )]
|
148 | });
|
149 |
|
150 | export const Drawer = getComponent({
|
151 | baseClasses: 'bg-dark-blue white fixed top-0 vh-100 overflow-x-hidden'
|
152 | }); |
\ | No newline at end of file |