aboutsummaryrefslogtreecommitdiffstats
path: root/packages/ui/src/infobox/index.tsx
diff options
context:
space:
mode:
Diffstat (limited to 'packages/ui/src/infobox/index.tsx')
-rw-r--r--packages/ui/src/infobox/index.tsx192
1 files changed, 192 insertions, 0 deletions
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 @@
1import { Theme } from '@meetfranz/theme';
2import classnames from 'classnames';
3import React, { Component } from 'react';
4import injectStyle from 'react-jss';
5
6import { Icon } from '../';
7import { IWithStyle } from '../typings/generic';
8
9interface 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
20interface IState {
21 isDismissing: boolean;
22 dismissed: boolean;
23}
24
25const 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
44const 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
96class 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
192export const Infobox = injectStyle(styles)(InfoboxComponent);