1 | var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
|
2 |
|
3 | import { h } from 'preact';
|
4 | import cn from 'classnames';
|
5 | import { LogoLight } from './logo';
|
6 | import getComponent from './utils/get-styled-component';
|
7 | import { transitionIn } from './transition-in';
|
8 | import omit from './utils/omit';
|
9 | import { Icon } from './icon';
|
10 |
|
11 | export const LogoCrate = () => h(
|
12 | 'div',
|
13 | { className: 'mw6 mv3 ph3 pt2 pb3 center br2' },
|
14 | h(
|
15 | 'div',
|
16 | { className: 'w-60' },
|
17 | h(
|
18 | 'a',
|
19 | { href: '/' },
|
20 | h(LogoLight, null)
|
21 | )
|
22 | )
|
23 | );
|
24 |
|
25 | export const Page = transitionIn(getComponent({
|
26 | baseClasses: 'transition',
|
27 | options: { transitions: ['firstRender'] },
|
28 | fn: ({ firstRender }) => firstRender ? 'o-0 translate-y' : 'o-100'
|
29 | }));
|
30 |
|
31 | export const PageCrateHeading = getComponent({
|
32 | baseClasses: 'mt1 mb3',
|
33 | tagName: 'h3'
|
34 | });
|
35 |
|
36 | export const PageCrate = getComponent({
|
37 | baseClasses: 'no-print-padding mv3 pa3 center br2',
|
38 | options: {
|
39 | title: '',
|
40 | backgroundColor: 'white',
|
41 | width: ['wide'],
|
42 | shadowExists: ['noShadow']
|
43 | },
|
44 | fn: ({ wide, backgroundColor, noShadow }) => cn(wide ? 'mw7' : 'mw6', `bg-${backgroundColor}`, {
|
45 | 'shadow-1': !noShadow
|
46 | }),
|
47 | renderChildren: ({ title, children }) => {
|
48 | const res = [children];
|
49 | if (title) {
|
50 | res.unshift(h(
|
51 | PageCrateHeading,
|
52 | null,
|
53 | title
|
54 | ));
|
55 | }
|
56 | return res;
|
57 | }
|
58 | });
|
59 |
|
60 | export const MessagePageCrate = props => {
|
61 | const { loading, error, warning, success, children } = props;
|
62 | const rest = omit(props, ['loading', 'error', 'warning', 'success', 'children']);
|
63 | let icon = null;
|
64 | let iconClasses = null;
|
65 | let backgroundColor = 'white';
|
66 | let colorClasses = null;
|
67 | if (loading) {
|
68 | icon = 'autorenew';
|
69 | iconClasses = 'spin-animation';
|
70 | }
|
71 | if (error) {
|
72 | icon = 'error';
|
73 | backgroundColor = 'red';
|
74 | colorClasses = 'black';
|
75 | }
|
76 | if (warning) {
|
77 | icon = 'warning';
|
78 | backgroundColor = 'orange';
|
79 | colorClasses = 'black';
|
80 | }
|
81 | if (success) {
|
82 | icon = 'check';
|
83 | backgroundColor = 'light-blue';
|
84 | colorClasses = 'black';
|
85 | }
|
86 | const iconComp = (loading || error || warning || success) && h(Icon, { className: cn('f3 mr3', iconClasses), size: '40', icon: icon });
|
87 |
|
88 | return h(
|
89 | PageCrate,
|
90 | _extends({ backgroundColor: backgroundColor }, rest),
|
91 | h(
|
92 | 'div',
|
93 | { className: cn('flex items-center min-h3 f4', colorClasses) },
|
94 | iconComp,
|
95 | children
|
96 | )
|
97 | );
|
98 | }; |
\ | No newline at end of file |