diff options
Diffstat (limited to 'packages/ui')
-rw-r--r-- | packages/ui/.gitignore | 2 | ||||
-rw-r--r-- | packages/ui/package-lock.json | 207 | ||||
-rw-r--r-- | packages/ui/package.json | 38 | ||||
-rw-r--r-- | packages/ui/src/badge/index.tsx | 76 | ||||
-rw-r--r-- | packages/ui/src/headline/index.tsx | 71 | ||||
-rw-r--r-- | packages/ui/src/icon/index.tsx | 55 | ||||
-rw-r--r-- | packages/ui/src/index.ts | 5 | ||||
-rw-r--r-- | packages/ui/src/infobox/index.tsx | 192 | ||||
-rw-r--r-- | packages/ui/src/loader/index.tsx | 48 | ||||
-rw-r--r-- | packages/ui/src/typings/generic.ts | 10 | ||||
-rw-r--r-- | packages/ui/tsconfig.json | 12 | ||||
-rw-r--r-- | packages/ui/tslint.json | 3 |
12 files changed, 719 insertions, 0 deletions
diff --git a/packages/ui/.gitignore b/packages/ui/.gitignore new file mode 100644 index 000000000..d01826a6b --- /dev/null +++ b/packages/ui/.gitignore | |||
@@ -0,0 +1,2 @@ | |||
1 | node_modules/ | ||
2 | lib | ||
diff --git a/packages/ui/package-lock.json b/packages/ui/package-lock.json new file mode 100644 index 000000000..8fa68a29b --- /dev/null +++ b/packages/ui/package-lock.json | |||
@@ -0,0 +1,207 @@ | |||
1 | { | ||
2 | "name": "@meetfranz/ui", | ||
3 | "version": "0.0.0", | ||
4 | "lockfileVersion": 1, | ||
5 | "requires": true, | ||
6 | "dependencies": { | ||
7 | "@mdi/js": { | ||
8 | "version": "3.3.92", | ||
9 | "resolved": "https://registry.npmjs.org/@mdi/js/-/js-3.3.92.tgz", | ||
10 | "integrity": "sha512-l+12IwTycHlijWMiRWBAssm0RSgkQiwMthIy/EcBAdSqtnsHnFjHq+aI2MBZ8/AYX0QBxNUv4+EN0SXZgNkWDg==" | ||
11 | }, | ||
12 | "@mdi/react": { | ||
13 | "version": "1.1.0", | ||
14 | "resolved": "https://registry.npmjs.org/@mdi/react/-/react-1.1.0.tgz", | ||
15 | "integrity": "sha512-c0+avMYEZ6i7Pg1ULLFs+p7k8bDPiie9rrgGYs8VWQhw2tUUYz7r0lIPVzD3bzMghWfyhfkArj88K5Of0WTMNw==" | ||
16 | }, | ||
17 | "@meetfranz/theme": { | ||
18 | "version": "file:../theme", | ||
19 | "requires": { | ||
20 | "color": "^3.1.0" | ||
21 | }, | ||
22 | "dependencies": { | ||
23 | "color": { | ||
24 | "version": "3.1.0", | ||
25 | "bundled": true, | ||
26 | "requires": { | ||
27 | "color-convert": "^1.9.1", | ||
28 | "color-string": "^1.5.2" | ||
29 | } | ||
30 | }, | ||
31 | "color-convert": { | ||
32 | "version": "1.9.3", | ||
33 | "bundled": true, | ||
34 | "requires": { | ||
35 | "color-name": "1.1.3" | ||
36 | } | ||
37 | }, | ||
38 | "color-name": { | ||
39 | "version": "1.1.3", | ||
40 | "bundled": true | ||
41 | }, | ||
42 | "color-string": { | ||
43 | "version": "1.5.3", | ||
44 | "bundled": true, | ||
45 | "requires": { | ||
46 | "color-name": "^1.0.0", | ||
47 | "simple-swizzle": "^0.2.2" | ||
48 | } | ||
49 | }, | ||
50 | "is-arrayish": { | ||
51 | "version": "0.3.2", | ||
52 | "bundled": true | ||
53 | }, | ||
54 | "simple-swizzle": { | ||
55 | "version": "0.2.2", | ||
56 | "bundled": true, | ||
57 | "requires": { | ||
58 | "is-arrayish": "^0.3.1" | ||
59 | } | ||
60 | } | ||
61 | } | ||
62 | }, | ||
63 | "asap": { | ||
64 | "version": "2.0.6", | ||
65 | "resolved": "https://registry.npmjs.org/asap/-/asap-2.0.6.tgz", | ||
66 | "integrity": "sha1-5QNHYR1+aQlDIIu9r+vLwvuGbUY=" | ||
67 | }, | ||
68 | "core-js": { | ||
69 | "version": "1.2.7", | ||
70 | "resolved": "https://registry.npmjs.org/core-js/-/core-js-1.2.7.tgz", | ||
71 | "integrity": "sha1-ZSKUwUZR2yj6k70tX/KYOk8IxjY=" | ||
72 | }, | ||
73 | "create-react-class": { | ||
74 | "version": "15.6.3", | ||
75 | "resolved": "https://registry.npmjs.org/create-react-class/-/create-react-class-15.6.3.tgz", | ||
76 | "integrity": "sha512-M+/3Q6E6DLO6Yx3OwrWjwHBnvfXXYA7W+dFjt/ZDBemHO1DDZhsalX/NUtnTYclN6GfnBDRh4qRHjcDHmlJBJg==", | ||
77 | "requires": { | ||
78 | "fbjs": "^0.8.9", | ||
79 | "loose-envify": "^1.3.1", | ||
80 | "object-assign": "^4.1.1" | ||
81 | } | ||
82 | }, | ||
83 | "encoding": { | ||
84 | "version": "0.1.12", | ||
85 | "resolved": "https://registry.npmjs.org/encoding/-/encoding-0.1.12.tgz", | ||
86 | "integrity": "sha1-U4tm8+5izRq1HsMjgp0flIDHS+s=", | ||
87 | "requires": { | ||
88 | "iconv-lite": "~0.4.13" | ||
89 | } | ||
90 | }, | ||
91 | "fbjs": { | ||
92 | "version": "0.8.17", | ||
93 | "resolved": "https://registry.npmjs.org/fbjs/-/fbjs-0.8.17.tgz", | ||
94 | "integrity": "sha1-xNWY6taUkRJlPWWIsBpc3Nn5D90=", | ||
95 | "requires": { | ||
96 | "core-js": "^1.0.0", | ||
97 | "isomorphic-fetch": "^2.1.1", | ||
98 | "loose-envify": "^1.0.0", | ||
99 | "object-assign": "^4.1.0", | ||
100 | "promise": "^7.1.1", | ||
101 | "setimmediate": "^1.0.5", | ||
102 | "ua-parser-js": "^0.7.18" | ||
103 | } | ||
104 | }, | ||
105 | "iconv-lite": { | ||
106 | "version": "0.4.24", | ||
107 | "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.24.tgz", | ||
108 | "integrity": "sha512-v3MXnZAcvnywkTUEZomIActle7RXXeedOR31wwl7VlyoXO4Qi9arvSenNQWne1TcRwhCL1HwLI21bEqdpj8/rA==", | ||
109 | "requires": { | ||
110 | "safer-buffer": ">= 2.1.2 < 3" | ||
111 | } | ||
112 | }, | ||
113 | "is-stream": { | ||
114 | "version": "1.1.0", | ||
115 | "resolved": "https://registry.npmjs.org/is-stream/-/is-stream-1.1.0.tgz", | ||
116 | "integrity": "sha1-EtSj3U5o4Lec6428hBc66A2RykQ=" | ||
117 | }, | ||
118 | "isomorphic-fetch": { | ||
119 | "version": "2.2.1", | ||
120 | "resolved": "https://registry.npmjs.org/isomorphic-fetch/-/isomorphic-fetch-2.2.1.tgz", | ||
121 | "integrity": "sha1-YRrhrPFPXoH3KVB0coGf6XM1WKk=", | ||
122 | "requires": { | ||
123 | "node-fetch": "^1.0.1", | ||
124 | "whatwg-fetch": ">=0.10.0" | ||
125 | } | ||
126 | }, | ||
127 | "js-tokens": { | ||
128 | "version": "4.0.0", | ||
129 | "resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-4.0.0.tgz", | ||
130 | "integrity": "sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ==" | ||
131 | }, | ||
132 | "loose-envify": { | ||
133 | "version": "1.4.0", | ||
134 | "resolved": "https://registry.npmjs.org/loose-envify/-/loose-envify-1.4.0.tgz", | ||
135 | "integrity": "sha512-lyuxPGr/Wfhrlem2CL/UcnUc1zcqKAImBDzukY7Y5F/yQiNdko6+fRLevlw1HgMySw7f611UIY408EtxRSoK3Q==", | ||
136 | "requires": { | ||
137 | "js-tokens": "^3.0.0 || ^4.0.0" | ||
138 | } | ||
139 | }, | ||
140 | "node-fetch": { | ||
141 | "version": "1.7.3", | ||
142 | "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-1.7.3.tgz", | ||
143 | "integrity": "sha512-NhZ4CsKx7cYm2vSrBAr2PvFOe6sWDf0UYLRqA6svUYg7+/TSfVAu49jYC4BvQ4Sms9SZgdqGBgroqfDhJdTyKQ==", | ||
144 | "requires": { | ||
145 | "encoding": "^0.1.11", | ||
146 | "is-stream": "^1.0.1" | ||
147 | } | ||
148 | }, | ||
149 | "object-assign": { | ||
150 | "version": "4.1.1", | ||
151 | "resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz", | ||
152 | "integrity": "sha1-IQmtx5ZYh8/AXLvUQsrIv7s2CGM=" | ||
153 | }, | ||
154 | "promise": { | ||
155 | "version": "7.3.1", | ||
156 | "resolved": "https://registry.npmjs.org/promise/-/promise-7.3.1.tgz", | ||
157 | "integrity": "sha512-nolQXZ/4L+bP/UGlkfaIujX9BKxGwmQ9OT4mOt5yvy8iK1h3wqTEJCijzGANTCCl9nWjY41juyAn2K3Q1hLLTg==", | ||
158 | "requires": { | ||
159 | "asap": "~2.0.3" | ||
160 | } | ||
161 | }, | ||
162 | "prop-types": { | ||
163 | "version": "15.6.2", | ||
164 | "resolved": "https://registry.npmjs.org/prop-types/-/prop-types-15.6.2.tgz", | ||
165 | "integrity": "sha512-3pboPvLiWD7dkI3qf3KbUe6hKFKa52w+AE0VCqECtf+QHAKgOL37tTaNCnuX1nAAQ4ZhyP+kYVKf8rLmJ/feDQ==", | ||
166 | "requires": { | ||
167 | "loose-envify": "^1.3.1", | ||
168 | "object-assign": "^4.1.1" | ||
169 | } | ||
170 | }, | ||
171 | "react-loader": { | ||
172 | "version": "2.4.5", | ||
173 | "resolved": "https://registry.npmjs.org/react-loader/-/react-loader-2.4.5.tgz", | ||
174 | "integrity": "sha1-zT5VHGzQc4wcDxPwc2VPk4KL5ak=", | ||
175 | "requires": { | ||
176 | "create-react-class": "^15.5.2", | ||
177 | "prop-types": "^15.5.8", | ||
178 | "spin.js": "2.x" | ||
179 | } | ||
180 | }, | ||
181 | "safer-buffer": { | ||
182 | "version": "2.1.2", | ||
183 | "resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz", | ||
184 | "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==" | ||
185 | }, | ||
186 | "setimmediate": { | ||
187 | "version": "1.0.5", | ||
188 | "resolved": "https://registry.npmjs.org/setimmediate/-/setimmediate-1.0.5.tgz", | ||
189 | "integrity": "sha1-KQy7Iy4waULX1+qbg3Mqt4VvgoU=" | ||
190 | }, | ||
191 | "spin.js": { | ||
192 | "version": "2.3.2", | ||
193 | "resolved": "https://registry.npmjs.org/spin.js/-/spin.js-2.3.2.tgz", | ||
194 | "integrity": "sha1-bKpW1SBnNFD9XPvGlx5tB3LDeho=" | ||
195 | }, | ||
196 | "ua-parser-js": { | ||
197 | "version": "0.7.19", | ||
198 | "resolved": "https://registry.npmjs.org/ua-parser-js/-/ua-parser-js-0.7.19.tgz", | ||
199 | "integrity": "sha512-T3PVJ6uz8i0HzPxOF9SWzWAlfN/DavlpQqepn22xgve/5QecC+XMCAtmUNnY7C9StehaV6exjUCI801lOI7QlQ==" | ||
200 | }, | ||
201 | "whatwg-fetch": { | ||
202 | "version": "3.0.0", | ||
203 | "resolved": "https://registry.npmjs.org/whatwg-fetch/-/whatwg-fetch-3.0.0.tgz", | ||
204 | "integrity": "sha512-9GSJUgz1D4MfyKU7KRqwOjXCXTqWdFNvEr7eUBYchQiVc744mqK/MzXPNR2WsPkmkOa4ywfg8C2n8h+13Bey1Q==" | ||
205 | } | ||
206 | } | ||
207 | } | ||
diff --git a/packages/ui/package.json b/packages/ui/package.json new file mode 100644 index 000000000..62a1e5a6e --- /dev/null +++ b/packages/ui/package.json | |||
@@ -0,0 +1,38 @@ | |||
1 | { | ||
2 | "name": "@meetfranz/ui", | ||
3 | "version": "0.0.4", | ||
4 | "description": "React UI components for Franz", | ||
5 | "main": "lib/index.js", | ||
6 | "scripts": { | ||
7 | "dev": "tsc -w", | ||
8 | "prepare": "tsc" | ||
9 | }, | ||
10 | "publishConfig": { | ||
11 | "access": "public" | ||
12 | }, | ||
13 | "repository": { | ||
14 | "type": "git", | ||
15 | "url": "git+https://github.com/meetfranz/franz.git" | ||
16 | }, | ||
17 | "keywords": [ | ||
18 | "Franz", | ||
19 | "Forms", | ||
20 | "React", | ||
21 | "UI" | ||
22 | ], | ||
23 | "author": "Stefan Malzner <stefan@adlk.io>", | ||
24 | "license": "Apache-2.0", | ||
25 | "dependencies": { | ||
26 | "@mdi/js": "^3.3.92", | ||
27 | "@mdi/react": "^1.1.0", | ||
28 | "@meetfranz/theme": "^1.0.7", | ||
29 | "react-loader": "^2.4.5" | ||
30 | }, | ||
31 | "peerDependencies": { | ||
32 | "classnames": "^2.2.6", | ||
33 | "react": "^16.7.0", | ||
34 | "react-dom": "16.7.0", | ||
35 | "react-jss": "^8.6.1" | ||
36 | }, | ||
37 | "gitHead": "14b151cad6a5a849bb476aaa3fc53bf1eead7f4b" | ||
38 | } | ||
diff --git a/packages/ui/src/badge/index.tsx b/packages/ui/src/badge/index.tsx new file mode 100644 index 000000000..fc52ecc73 --- /dev/null +++ b/packages/ui/src/badge/index.tsx | |||
@@ -0,0 +1,76 @@ | |||
1 | import { Theme } from '@meetfranz/theme'; | ||
2 | import classnames from 'classnames'; | ||
3 | import React, { Component } from 'react'; | ||
4 | import injectStyle from 'react-jss'; | ||
5 | |||
6 | import { IWithStyle } from '../typings/generic'; | ||
7 | |||
8 | interface IProps extends IWithStyle { | ||
9 | type: string; | ||
10 | className?: string; | ||
11 | children: React.ReactNode; | ||
12 | } | ||
13 | |||
14 | const badgeStyles = (theme: Theme) => { | ||
15 | const styles = {}; | ||
16 | Object.keys(theme.styleTypes).map((style) => { | ||
17 | Object.assign(styles, { | ||
18 | [style]: { | ||
19 | background: theme.styleTypes[style].accent, | ||
20 | color: theme.styleTypes[style].contrast, | ||
21 | border: theme.styleTypes[style].border, | ||
22 | }, | ||
23 | }); | ||
24 | }); | ||
25 | |||
26 | return styles; | ||
27 | }; | ||
28 | |||
29 | const styles = (theme: Theme) => ({ | ||
30 | badge: { | ||
31 | display: 'inline-block', | ||
32 | padding: [3, 8, 4], | ||
33 | fontSize: theme.badgeFontSize, | ||
34 | borderRadius: theme.badgeBorderRadius, | ||
35 | margin: [0, 4], | ||
36 | |||
37 | '&:first-child': { | ||
38 | marginLeft: 0, | ||
39 | }, | ||
40 | |||
41 | '&:last-child': { | ||
42 | marginRight: 0, | ||
43 | }, | ||
44 | }, | ||
45 | ...badgeStyles(theme), | ||
46 | }); | ||
47 | |||
48 | class BadgeComponent extends Component<IProps> { | ||
49 | public static defaultProps = { | ||
50 | type: 'primary', | ||
51 | }; | ||
52 | |||
53 | render() { | ||
54 | const { | ||
55 | classes, | ||
56 | children, | ||
57 | type, | ||
58 | className, | ||
59 | } = this.props; | ||
60 | |||
61 | return ( | ||
62 | <div | ||
63 | className={classnames({ | ||
64 | [classes.badge]: true, | ||
65 | [classes[type]]: true, | ||
66 | [`${className}`]: className, | ||
67 | })} | ||
68 | data-type="franz-badge" | ||
69 | > | ||
70 | {children} | ||
71 | </div> | ||
72 | ); | ||
73 | } | ||
74 | } | ||
75 | |||
76 | export const Badge = injectStyle(styles)(BadgeComponent); | ||
diff --git a/packages/ui/src/headline/index.tsx b/packages/ui/src/headline/index.tsx new file mode 100644 index 000000000..7eabfcf80 --- /dev/null +++ b/packages/ui/src/headline/index.tsx | |||
@@ -0,0 +1,71 @@ | |||
1 | import { Theme } from '@meetfranz/theme'; | ||
2 | import classnames from 'classnames'; | ||
3 | import React, { Component } from 'react'; | ||
4 | import injectStyle from 'react-jss'; | ||
5 | |||
6 | import { IWithStyle, Omit } from '../typings/generic'; | ||
7 | |||
8 | interface IProps extends IWithStyle { | ||
9 | level?: number; | ||
10 | className?: string; | ||
11 | children: string | React.ReactNode; | ||
12 | id?: string; | ||
13 | } | ||
14 | |||
15 | const styles = (theme: Theme) => ({ | ||
16 | headline: { | ||
17 | fontWeight: 'lighter', | ||
18 | color: theme.colorText, | ||
19 | marginTop: 0, | ||
20 | marginBottom: 10, | ||
21 | textAlign: 'left', | ||
22 | }, | ||
23 | h1: { | ||
24 | fontSize: 30, | ||
25 | marginTop: 0, | ||
26 | }, | ||
27 | h2: { | ||
28 | fontSize: 20, | ||
29 | }, | ||
30 | h3: { | ||
31 | fontSize: 18, | ||
32 | }, | ||
33 | h4: { | ||
34 | fontSize: theme.uiFontSize, | ||
35 | }, | ||
36 | }); | ||
37 | |||
38 | class HeadlineComponent extends Component<IProps> { | ||
39 | render() { | ||
40 | const { | ||
41 | classes, | ||
42 | level, | ||
43 | className, | ||
44 | children, | ||
45 | id, | ||
46 | } = this.props; | ||
47 | |||
48 | return React.createElement( | ||
49 | `h${level}`, | ||
50 | { | ||
51 | id, | ||
52 | className: classnames({ | ||
53 | [classes.headline]: true, | ||
54 | [classes[level ? `h${level}` : 'h1']]: true, | ||
55 | [`${className}`]: className, | ||
56 | }), | ||
57 | 'data-type': 'franz-headline', | ||
58 | }, | ||
59 | children, | ||
60 | ); | ||
61 | } | ||
62 | } | ||
63 | |||
64 | const Headline = injectStyle(styles)(HeadlineComponent); | ||
65 | |||
66 | const createH = (level: number) => (props: Omit<IProps, 'classes' | 'theme'>) => <Headline level={level} {...props}>{props.children}</Headline>; | ||
67 | |||
68 | export const H1 = createH(1); | ||
69 | export const H2 = createH(2); | ||
70 | export const H3 = createH(3); | ||
71 | export const H4 = createH(4); | ||
diff --git a/packages/ui/src/icon/index.tsx b/packages/ui/src/icon/index.tsx new file mode 100644 index 000000000..e30d3396d --- /dev/null +++ b/packages/ui/src/icon/index.tsx | |||
@@ -0,0 +1,55 @@ | |||
1 | import * as mdiIcons from '@mdi/js'; | ||
2 | import MdiIcon from '@mdi/react'; | ||
3 | import { Theme } from '@meetfranz/theme'; | ||
4 | import classnames from 'classnames'; | ||
5 | import React, { Component } from 'react'; | ||
6 | import injectStyle from 'react-jss'; | ||
7 | |||
8 | import { IWithStyle } from '../typings/generic'; | ||
9 | |||
10 | interface IProps extends IWithStyle { | ||
11 | icon: keyof typeof mdiIcons; | ||
12 | size?: number; | ||
13 | className?: string; | ||
14 | } | ||
15 | |||
16 | const styles = (theme: Theme) => ({ | ||
17 | icon: { | ||
18 | fill: theme.colorText, | ||
19 | }, | ||
20 | }); | ||
21 | |||
22 | class IconComponent extends Component<IProps> { | ||
23 | public static defaultProps = { | ||
24 | size: 1, | ||
25 | }; | ||
26 | |||
27 | render() { | ||
28 | const { | ||
29 | classes, | ||
30 | icon: iconName, | ||
31 | size, | ||
32 | className, | ||
33 | } = this.props; | ||
34 | |||
35 | let icon = ''; | ||
36 | if (iconName && mdiIcons[iconName]) { | ||
37 | icon = mdiIcons[iconName]; | ||
38 | } else if (iconName && !mdiIcons[iconName]) { | ||
39 | console.warn(`Icon '${iconName}' was not found`); | ||
40 | } | ||
41 | |||
42 | return ( | ||
43 | <MdiIcon | ||
44 | path={icon} | ||
45 | size={size} | ||
46 | className={classnames({ | ||
47 | [classes.icon]: true, | ||
48 | [`${className}`]: className, | ||
49 | })} | ||
50 | /> | ||
51 | ); | ||
52 | } | ||
53 | } | ||
54 | |||
55 | export const Icon = injectStyle(styles)(IconComponent); | ||
diff --git a/packages/ui/src/index.ts b/packages/ui/src/index.ts new file mode 100644 index 000000000..1eeec5144 --- /dev/null +++ b/packages/ui/src/index.ts | |||
@@ -0,0 +1,5 @@ | |||
1 | export { Icon } from './icon'; | ||
2 | export { Infobox } from './infobox'; | ||
3 | export * from './headline'; | ||
4 | export { Loader } from './loader'; | ||
5 | export { Badge } from './badge'; | ||
diff --git a/packages/ui/src/infobox/index.tsx b/packages/ui/src/infobox/index.tsx new file mode 100644 index 000000000..53ed16341 --- /dev/null +++ b/packages/ui/src/infobox/index.tsx | |||
@@ -0,0 +1,192 @@ | |||
1 | import { Theme } from '@meetfranz/theme'; | ||
2 | import classnames from 'classnames'; | ||
3 | import React, { Component } from 'react'; | ||
4 | import injectStyle from 'react-jss'; | ||
5 | |||
6 | import { Icon } from '../'; | ||
7 | import { IWithStyle } from '../typings/generic'; | ||
8 | |||
9 | interface IProps extends IWithStyle { | ||
10 | icon?: string; | ||
11 | type?: string; | ||
12 | dismissable?: boolean; | ||
13 | onDismiss?: () => void; | ||
14 | ctaOnClick?: () => void; | ||
15 | ctaLabel?: string; | ||
16 | ctaLoading?: boolean; | ||
17 | children: React.ReactNode; | ||
18 | } | ||
19 | |||
20 | interface IState { | ||
21 | isDismissing: boolean; | ||
22 | dismissed: boolean; | ||
23 | } | ||
24 | |||
25 | const buttonStyles = (theme: Theme) => { | ||
26 | const styles = {}; | ||
27 | Object.keys(theme.styleTypes).map((style) => { | ||
28 | Object.assign(styles, { | ||
29 | [style]: { | ||
30 | background: theme.styleTypes[style].accent, | ||
31 | color: theme.styleTypes[style].contrast, | ||
32 | border: theme.styleTypes[style].border, | ||
33 | |||
34 | '& svg': { | ||
35 | fill: theme.styleTypes[style].contrast, | ||
36 | }, | ||
37 | }, | ||
38 | }); | ||
39 | }); | ||
40 | |||
41 | return styles; | ||
42 | }; | ||
43 | |||
44 | const styles = (theme: Theme) => ({ | ||
45 | wrapper: { | ||
46 | position: 'relative', | ||
47 | overflow: 'hidden', | ||
48 | }, | ||
49 | infobox: { | ||
50 | alignItems: 'center', | ||
51 | borderRadius: theme.borderRadiusSmall, | ||
52 | display: 'flex', | ||
53 | height: 'auto', | ||
54 | marginBottom: 30, | ||
55 | padding: '15px 20px', | ||
56 | top: 0, | ||
57 | transition: 'all 0.5s', | ||
58 | opacity: 1, | ||
59 | }, | ||
60 | dismissing: { | ||
61 | // position: 'absolute', | ||
62 | marginTop: -100, | ||
63 | opacity: 0, | ||
64 | }, | ||
65 | content: { | ||
66 | flex: 1, | ||
67 | }, | ||
68 | icon: { | ||
69 | marginRight: 10, | ||
70 | }, | ||
71 | close: { | ||
72 | color: (props: IProps) => theme.styleTypes[props.type ? props.type : 'primary'].contrast, | ||
73 | marginRight: -5, | ||
74 | border: 0, | ||
75 | background: 'none', | ||
76 | }, | ||
77 | cta: { | ||
78 | borderColor: (props: IProps) => theme.styleTypes[props.type ? props.type : 'primary'].contrast, | ||
79 | borderRadius: theme.borderRadiusSmall, | ||
80 | borderStyle: 'solid', | ||
81 | borderWidth: 1, | ||
82 | background: 'none', | ||
83 | color: (props: IProps) => theme.styleTypes[props.type ? props.type : 'primary'].contrast, | ||
84 | marginLeft: 15, | ||
85 | padding: [4, 10], | ||
86 | fontSize: theme.uiFontSize, | ||
87 | transition: 'opacity 0.3s', | ||
88 | |||
89 | '&:hover': { | ||
90 | opacity: 0.6, | ||
91 | }, | ||
92 | }, | ||
93 | ...buttonStyles(theme), | ||
94 | }); | ||
95 | |||
96 | class InfoboxComponent extends Component<IProps, IState> { | ||
97 | public static defaultProps = { | ||
98 | type: 'primary', | ||
99 | dismissable: false, | ||
100 | ctaOnClick: () => {}, | ||
101 | onDismiss: () => {}, | ||
102 | ctaLabel: '', | ||
103 | ctaLoading: false, | ||
104 | }; | ||
105 | |||
106 | state = { | ||
107 | isDismissing: false, | ||
108 | dismissed: false, | ||
109 | }; | ||
110 | |||
111 | dismiss() { | ||
112 | const { | ||
113 | onDismiss, | ||
114 | } = this.props; | ||
115 | |||
116 | this.setState({ | ||
117 | isDismissing: true, | ||
118 | }); | ||
119 | |||
120 | if (onDismiss) { | ||
121 | onDismiss(); | ||
122 | } | ||
123 | |||
124 | setTimeout(() => { | ||
125 | this.setState({ | ||
126 | dismissed: true, | ||
127 | }); | ||
128 | }, 3000); | ||
129 | } | ||
130 | |||
131 | render() { | ||
132 | const { | ||
133 | classes, | ||
134 | children, | ||
135 | icon, | ||
136 | type, | ||
137 | ctaLabel, | ||
138 | ctaLoading, | ||
139 | ctaOnClick, | ||
140 | dismissable, | ||
141 | } = this.props; | ||
142 | |||
143 | const { | ||
144 | isDismissing, | ||
145 | dismissed, | ||
146 | } = this.state; | ||
147 | |||
148 | if (dismissed) { | ||
149 | return null; | ||
150 | } | ||
151 | |||
152 | return ( | ||
153 | <div className={classes.wrapper}> | ||
154 | <div | ||
155 | className={classnames({ | ||
156 | [classes.infobox]: true, | ||
157 | [classes[`${type}`]]: type, | ||
158 | [classes.dismissing]: isDismissing, | ||
159 | })} | ||
160 | data-type="franz-infobox" | ||
161 | > | ||
162 | {icon && ( | ||
163 | <Icon icon={icon} className={classes.icon} /> | ||
164 | )} | ||
165 | <div className={classes.content}> | ||
166 | {children} | ||
167 | </div> | ||
168 | {ctaLabel && ( | ||
169 | <button | ||
170 | className={classes.cta} | ||
171 | onClick={ctaOnClick} | ||
172 | type="button" | ||
173 | > | ||
174 | {ctaLabel} | ||
175 | </button> | ||
176 | )} | ||
177 | {dismissable && ( | ||
178 | <button | ||
179 | type="button" | ||
180 | onClick={this.dismiss.bind(this)} | ||
181 | className={classes.close} | ||
182 | > | ||
183 | <Icon icon="mdiClose" /> | ||
184 | </button> | ||
185 | )} | ||
186 | </div> | ||
187 | </div> | ||
188 | ); | ||
189 | } | ||
190 | } | ||
191 | |||
192 | export const Infobox = injectStyle(styles)(InfoboxComponent); | ||
diff --git a/packages/ui/src/loader/index.tsx b/packages/ui/src/loader/index.tsx new file mode 100644 index 000000000..46545c786 --- /dev/null +++ b/packages/ui/src/loader/index.tsx | |||
@@ -0,0 +1,48 @@ | |||
1 | import { Theme } from '@meetfranz/theme'; | ||
2 | import classnames from 'classnames'; | ||
3 | import React, { Component } from 'react'; | ||
4 | import injectStyle, { withTheme } from 'react-jss'; | ||
5 | import ReactLoader from 'react-loader'; | ||
6 | |||
7 | import { IWithStyle } from '../typings/generic'; | ||
8 | |||
9 | interface IProps extends IWithStyle { | ||
10 | className?: string; | ||
11 | } | ||
12 | |||
13 | const styles = (theme: Theme) => ({ | ||
14 | container: { | ||
15 | position: 'relative', | ||
16 | height: 60, | ||
17 | }, | ||
18 | }); | ||
19 | |||
20 | class LoaderComponent extends Component<IProps> { | ||
21 | render() { | ||
22 | const { | ||
23 | classes, | ||
24 | className, | ||
25 | theme, | ||
26 | } = this.props; | ||
27 | |||
28 | return ( | ||
29 | <div | ||
30 | className={classnames({ | ||
31 | [classes.container]: true, | ||
32 | [`${className}`]: className, | ||
33 | })} | ||
34 | data-type="franz-loader" | ||
35 | > | ||
36 | <ReactLoader | ||
37 | loaded={false} | ||
38 | width={4} | ||
39 | scale={0.75} | ||
40 | color={theme.colorText} | ||
41 | parentClassName={classes.loader} | ||
42 | /> | ||
43 | </div> | ||
44 | ); | ||
45 | } | ||
46 | } | ||
47 | |||
48 | export const Loader = injectStyle(styles)(withTheme(LoaderComponent)); | ||
diff --git a/packages/ui/src/typings/generic.ts b/packages/ui/src/typings/generic.ts new file mode 100644 index 000000000..d5f953b9f --- /dev/null +++ b/packages/ui/src/typings/generic.ts | |||
@@ -0,0 +1,10 @@ | |||
1 | import { Theme } from '@meetfranz/theme/lib'; | ||
2 | import { Classes } from 'jss'; | ||
3 | |||
4 | export interface IWithStyle { | ||
5 | classes: Classes; | ||
6 | theme: Theme; | ||
7 | } | ||
8 | |||
9 | export type Merge<M, N> = Omit<M, Extract<keyof M, keyof N>> & N; | ||
10 | export type Omit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>; | ||
diff --git a/packages/ui/tsconfig.json b/packages/ui/tsconfig.json new file mode 100644 index 000000000..8b9507eac --- /dev/null +++ b/packages/ui/tsconfig.json | |||
@@ -0,0 +1,12 @@ | |||
1 | { | ||
2 | "extends": "../../tsconfig.settings.json", | ||
3 | "compilerOptions": { | ||
4 | "outDir": "lib", | ||
5 | "rootDir": "src" | ||
6 | }, | ||
7 | "references": [ | ||
8 | { | ||
9 | "path": "../theme" | ||
10 | } | ||
11 | ] | ||
12 | } | ||
diff --git a/packages/ui/tslint.json b/packages/ui/tslint.json new file mode 100644 index 000000000..0946f2096 --- /dev/null +++ b/packages/ui/tslint.json | |||
@@ -0,0 +1,3 @@ | |||
1 | { | ||
2 | "extends": "../../tslint.json" | ||
3 | } | ||