diff options
author | Stefan Malzner <stefan@adlk.io> | 2019-01-28 11:35:25 +0100 |
---|---|---|
committer | Stefan Malzner <stefan@adlk.io> | 2019-01-28 11:35:25 +0100 |
commit | 9a5b313ea12bdb9dc3e3873ca3a2639bd7483e46 (patch) | |
tree | 038dc5e0a209d06e1c15c1e3c4740d5bdda96f8a /packages/ui/src | |
parent | Add href and type to button component (diff) | |
download | ferdium-app-9a5b313ea12bdb9dc3e3873ca3a2639bd7483e46.tar.gz ferdium-app-9a5b313ea12bdb9dc3e3873ca3a2639bd7483e46.tar.zst ferdium-app-9a5b313ea12bdb9dc3e3873ca3a2639bd7483e46.zip |
Update packages
Diffstat (limited to 'packages/ui/src')
-rw-r--r-- | packages/ui/src/badge/index.tsx | 75 | ||||
-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 | 194 | ||||
-rw-r--r-- | packages/ui/src/loader/index.tsx | 45 | ||||
-rw-r--r-- | packages/ui/src/typings/generic.ts | 10 |
7 files changed, 455 insertions, 0 deletions
diff --git a/packages/ui/src/badge/index.tsx b/packages/ui/src/badge/index.tsx new file mode 100644 index 000000000..241e778e7 --- /dev/null +++ b/packages/ui/src/badge/index.tsx | |||
@@ -0,0 +1,75 @@ | |||
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 | > | ||
69 | {children} | ||
70 | </div> | ||
71 | ); | ||
72 | } | ||
73 | } | ||
74 | |||
75 | 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..3458a40ad --- /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 { uiFontSize } from '@meetfranz/theme/lib/themes/default'; | ||
7 | import { IWithStyle, Omit } from '../typings/generic'; | ||
8 | |||
9 | interface IProps extends IWithStyle { | ||
10 | level?: number; | ||
11 | className?: string; | ||
12 | children: string | React.ReactNode; | ||
13 | id?: string; | ||
14 | } | ||
15 | |||
16 | const styles = (theme: Theme) => ({ | ||
17 | headline: { | ||
18 | fontWeight: 'lighter', | ||
19 | color: theme.colorText, | ||
20 | marginTop: 0, | ||
21 | marginBottom: 10, | ||
22 | textAlign: 'left', | ||
23 | }, | ||
24 | h1: { | ||
25 | fontSize: 30, | ||
26 | marginTop: 0, | ||
27 | }, | ||
28 | h2: { | ||
29 | fontSize: 20, | ||
30 | }, | ||
31 | h3: { | ||
32 | fontSize: 18, | ||
33 | }, | ||
34 | h4: { | ||
35 | fontSize: theme.uiFontSize, | ||
36 | }, | ||
37 | }); | ||
38 | |||
39 | class HeadlineComponent extends Component<IProps> { | ||
40 | render() { | ||
41 | const { | ||
42 | classes, | ||
43 | level, | ||
44 | className, | ||
45 | children, | ||
46 | id, | ||
47 | } = this.props; | ||
48 | |||
49 | return React.createElement( | ||
50 | `h${level}`, | ||
51 | { | ||
52 | id, | ||
53 | className: classnames({ | ||
54 | [classes.headline]: true, | ||
55 | [classes[level ? `h${level}` : 'h1']]: true, | ||
56 | [`${className}`]: className, | ||
57 | }), | ||
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..bf985ea9c --- /dev/null +++ b/packages/ui/src/infobox/index.tsx | |||
@@ -0,0 +1,194 @@ | |||
1 | import { Theme } from '@meetfranz/theme'; | ||
2 | import classnames from 'classnames'; | ||
3 | import { observer } from 'mobx-react'; | ||
4 | import React, { Component } from 'react'; | ||
5 | import injectStyle from 'react-jss'; | ||
6 | // import Loader from 'react-loader'; | ||
7 | |||
8 | import { Icon } from '../'; | ||
9 | import { IWithStyle } from '../typings/generic'; | ||
10 | |||
11 | interface IProps extends IWithStyle { | ||
12 | icon?: string; | ||
13 | type?: string; | ||
14 | dismissable?: boolean; | ||
15 | onDismiss?: () => void; | ||
16 | ctaOnClick?: () => void; | ||
17 | ctaLabel?: string; | ||
18 | ctaLoading?: boolean; | ||
19 | children: React.ReactNode; | ||
20 | } | ||
21 | |||
22 | interface IState { | ||
23 | isDismissing: boolean; | ||
24 | dismissed: boolean; | ||
25 | } | ||
26 | |||
27 | const buttonStyles = (theme: Theme) => { | ||
28 | const styles = {}; | ||
29 | Object.keys(theme.styleTypes).map((style) => { | ||
30 | Object.assign(styles, { | ||
31 | [style]: { | ||
32 | background: theme.styleTypes[style].accent, | ||
33 | color: theme.styleTypes[style].contrast, | ||
34 | border: theme.styleTypes[style].border, | ||
35 | |||
36 | '& svg': { | ||
37 | fill: theme.styleTypes[style].contrast, | ||
38 | }, | ||
39 | }, | ||
40 | }); | ||
41 | }); | ||
42 | |||
43 | return styles; | ||
44 | }; | ||
45 | |||
46 | const styles = (theme: Theme) => ({ | ||
47 | wrapper: { | ||
48 | position: 'relative', | ||
49 | overflow: 'hidden', | ||
50 | }, | ||
51 | infobox: { | ||
52 | alignItems: 'center', | ||
53 | borderRadius: theme.borderRadiusSmall, | ||
54 | display: 'flex', | ||
55 | height: 'auto', | ||
56 | marginBottom: 30, | ||
57 | padding: '15px 20px', | ||
58 | top: 0, | ||
59 | transition: 'all 0.5s', | ||
60 | opacity: 1, | ||
61 | }, | ||
62 | dismissing: { | ||
63 | // position: 'absolute', | ||
64 | marginTop: -100, | ||
65 | opacity: 0, | ||
66 | }, | ||
67 | content: { | ||
68 | flex: 1, | ||
69 | }, | ||
70 | icon: { | ||
71 | marginRight: 10, | ||
72 | }, | ||
73 | close: { | ||
74 | color: (props: IProps) => theme.styleTypes[props.type ? props.type : 'primary'].contrast, | ||
75 | marginRight: -5, | ||
76 | border: 0, | ||
77 | background: 'none', | ||
78 | }, | ||
79 | cta: { | ||
80 | borderColor: (props: IProps) => theme.styleTypes[props.type ? props.type : 'primary'].contrast, | ||
81 | borderRadius: theme.borderRadiusSmall, | ||
82 | borderStyle: 'solid', | ||
83 | borderWidth: 1, | ||
84 | background: 'none', | ||
85 | color: (props: IProps) => theme.styleTypes[props.type ? props.type : 'primary'].contrast, | ||
86 | marginLeft: 15, | ||
87 | padding: [4, 10], | ||
88 | fontSize: theme.uiFontSize, | ||
89 | transition: 'opacity 0.3s', | ||
90 | |||
91 | '&:hover': { | ||
92 | opacity: 0.6, | ||
93 | }, | ||
94 | }, | ||
95 | ...buttonStyles(theme), | ||
96 | }); | ||
97 | |||
98 | @observer | ||
99 | class InfoboxComponent extends Component<IProps, IState> { | ||
100 | public static defaultProps = { | ||
101 | type: 'primary', | ||
102 | dismissable: false, | ||
103 | ctaOnClick: () => {}, | ||
104 | onDismiss: () => {}, | ||
105 | ctaLabel: '', | ||
106 | ctaLoading: false, | ||
107 | }; | ||
108 | |||
109 | state = { | ||
110 | isDismissing: false, | ||
111 | dismissed: false, | ||
112 | }; | ||
113 | |||
114 | dismiss() { | ||
115 | const { | ||
116 | onDismiss, | ||
117 | } = this.props; | ||
118 | |||
119 | this.setState({ | ||
120 | isDismissing: true, | ||
121 | }); | ||
122 | |||
123 | if (onDismiss) { | ||
124 | onDismiss(); | ||
125 | } | ||
126 | |||
127 | setTimeout(() => { | ||
128 | this.setState({ | ||
129 | dismissed: true, | ||
130 | }); | ||
131 | }, 3000); | ||
132 | } | ||
133 | |||
134 | render() { | ||
135 | const { | ||
136 | classes, | ||
137 | children, | ||
138 | icon, | ||
139 | type, | ||
140 | ctaLabel, | ||
141 | ctaLoading, | ||
142 | ctaOnClick, | ||
143 | dismissable, | ||
144 | } = this.props; | ||
145 | |||
146 | const { | ||
147 | isDismissing, | ||
148 | dismissed, | ||
149 | } = this.state; | ||
150 | |||
151 | if (dismissed) { | ||
152 | return null; | ||
153 | } | ||
154 | |||
155 | return ( | ||
156 | <div className={classes.wrapper}> | ||
157 | <div | ||
158 | className={classnames({ | ||
159 | [classes.infobox]: true, | ||
160 | [classes[`${type}`]]: type, | ||
161 | [classes.dismissing]: isDismissing, | ||
162 | })} | ||
163 | > | ||
164 | {icon && ( | ||
165 | <Icon icon={icon} className={classes.icon} /> | ||
166 | )} | ||
167 | <div className={classes.content}> | ||
168 | {children} | ||
169 | </div> | ||
170 | {ctaLabel && ( | ||
171 | <button | ||
172 | className={classes.cta} | ||
173 | onClick={ctaOnClick} | ||
174 | type="button" | ||
175 | > | ||
176 | {ctaLabel} | ||
177 | </button> | ||
178 | )} | ||
179 | {dismissable && ( | ||
180 | <button | ||
181 | type="button" | ||
182 | onClick={this.dismiss.bind(this)} | ||
183 | className={classes.close} | ||
184 | > | ||
185 | <Icon icon="mdiClose" /> | ||
186 | </button> | ||
187 | )} | ||
188 | </div> | ||
189 | </div> | ||
190 | ); | ||
191 | } | ||
192 | } | ||
193 | |||
194 | 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..799caf195 --- /dev/null +++ b/packages/ui/src/loader/index.tsx | |||
@@ -0,0 +1,45 @@ | |||
1 | import { Theme } from '@meetfranz/theme'; | ||
2 | import classnames from 'classnames'; | ||
3 | import React, { Component } from 'react'; | ||
4 | import injectStyle 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 className={classnames({ | ||
30 | [classes.container]: true, | ||
31 | [`${className}`]: className, | ||
32 | })}> | ||
33 | <ReactLoader | ||
34 | loaded={false} | ||
35 | width={4} | ||
36 | scale={0.75} | ||
37 | color={theme.colorText} | ||
38 | parentClassName={classes.loader} | ||
39 | /> | ||
40 | </div> | ||
41 | ); | ||
42 | } | ||
43 | } | ||
44 | |||
45 | export const Loader = injectStyle(styles)(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>>; | ||