1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 | import * as React from 'react';
|
15 |
|
16 | import { objectLessAttributes } from '@aws-amplify/core';
|
17 |
|
18 | import AmplifyTheme from './AmplifyTheme';
|
19 |
|
20 | export const Container = props => {
|
21 | const theme = props.theme || AmplifyTheme;
|
22 | const style = propStyle(props, theme.container);
|
23 | const p = objectLessAttributes(props, 'theme');
|
24 | return beforeAfter(
|
25 | <div {...p} className="amplify-container" style={style}>
|
26 | {props.children}
|
27 | </div>
|
28 | );
|
29 | };
|
30 |
|
31 | export const FormContainer = props => {
|
32 | const theme = props.theme || AmplifyTheme;
|
33 | const style = propStyle(props, theme.formContainer);
|
34 | return beforeAfter(
|
35 | <div className="amplify-form-container" style={style}>
|
36 | {props.children}
|
37 | </div>
|
38 | );
|
39 | };
|
40 |
|
41 | export const FormSection = props => {
|
42 | const theme = props.theme || AmplifyTheme;
|
43 | const style = propStyle(props, theme.formSection);
|
44 | return (
|
45 | <FormContainer theme={theme}>
|
46 | {beforeAfter(
|
47 | <div className="amplify-form-section" style={style}>
|
48 | {props.children}
|
49 | </div>
|
50 | )}
|
51 | </FormContainer>
|
52 | );
|
53 | };
|
54 |
|
55 | export const ErrorSection = props => {
|
56 | const theme = props.theme || AmplifyTheme;
|
57 | const style = propStyle(props, theme.errorSection);
|
58 | const p = objectLessAttributes(props, 'theme');
|
59 | return beforeAfter(
|
60 | <div {...p} className="amplify-error-section" style={style}>
|
61 | <ErrorSectionContent>{props.children}</ErrorSectionContent>
|
62 | </div>
|
63 | );
|
64 | };
|
65 |
|
66 | export const ErrorSectionContent = props => {
|
67 | const theme = props.theme || AmplifyTheme;
|
68 | const style = propStyle(props, theme.errorSectionContent);
|
69 | return beforeAfter(
|
70 | <span className="amplify-error-section-content" style={style}>
|
71 | {props.children}
|
72 | </span>
|
73 | );
|
74 | };
|
75 |
|
76 | export const SectionHeader = props => {
|
77 | const theme = props.theme || AmplifyTheme;
|
78 | const style = propStyle(props, theme.sectionHeader);
|
79 | const p = objectLessAttributes(props, 'theme');
|
80 | return beforeAfter(
|
81 | <div {...p} className="amplify-section-header" style={style}>
|
82 | <SectionHeaderContent theme={theme}>
|
83 | {props.children}
|
84 | </SectionHeaderContent>
|
85 | </div>
|
86 | );
|
87 | };
|
88 |
|
89 | export const SectionHeaderContent = props => {
|
90 | const theme = props.theme || AmplifyTheme;
|
91 | const style = propStyle(props, theme.sectionHeaderContent);
|
92 | return beforeAfter(
|
93 | <span className="amplify-section-header-content" style={style}>
|
94 | {props.children}
|
95 | </span>
|
96 | );
|
97 | };
|
98 |
|
99 | export const SectionFooter = props => {
|
100 | const theme = props.theme || AmplifyTheme;
|
101 | const style = propStyle(props, theme.sectionFooter);
|
102 | const p = objectLessAttributes(props, 'theme');
|
103 | return beforeAfter(
|
104 | <div {...p} className="amplify-section-footer" style={style}>
|
105 | <SectionFooterContent theme={theme}>{props.children}</SectionFooterContent>
|
106 | </div>
|
107 | );
|
108 | };
|
109 |
|
110 | export const SectionFooterContent = props => {
|
111 | const theme = props.theme || AmplifyTheme;
|
112 | const style = propStyle(props, theme.sectionFooterContent);
|
113 | return beforeAfter(
|
114 | <span className="amplify-section-footer-content" style={style}>
|
115 | {props.children}
|
116 | </span>
|
117 | );
|
118 | };
|
119 |
|
120 | export const SectionBody = props => {
|
121 | const theme = props.theme || AmplifyTheme;
|
122 | const style = propStyle(props, theme.sectionBody);
|
123 | const p = objectLessAttributes(props, 'theme');
|
124 | return beforeAfter(
|
125 | <div {...p} className="amplify-section-body" style={style}>
|
126 | {props.children}
|
127 | </div>
|
128 | );
|
129 | };
|
130 |
|
131 | export const ActionRow = props => {
|
132 | const theme = props.theme || AmplifyTheme;
|
133 | const style = propStyle(props, theme.actionRow);
|
134 | const p = objectLessAttributes(props, 'theme');
|
135 | return beforeAfter(
|
136 | <div {...p} className="amplify-action-row" style={style}>
|
137 | {props.children}
|
138 | </div>
|
139 | );
|
140 | };
|
141 |
|
142 | export const FormRow = props => {
|
143 | const theme = props.theme || AmplifyTheme;
|
144 | const style = propStyle(props, theme.formRow);
|
145 | const p = objectLessAttributes(props, 'theme');
|
146 | return beforeAfter(
|
147 | <div {...p} className="amplify-form-row" style={style}>
|
148 | {props.children}
|
149 | </div>
|
150 | );
|
151 | };
|
152 |
|
153 | export const InputRow = props => {
|
154 | const theme = props.theme || AmplifyTheme;
|
155 | const style = propStyle(props, theme.input);
|
156 | const p = objectLessAttributes(props, 'theme');
|
157 | return (
|
158 | <FormRow theme={theme}>
|
159 | {beforeAfter(<input {...p} className="amplify-input" style={style} />)}
|
160 | </FormRow>
|
161 | );
|
162 | };
|
163 |
|
164 | export const RadioRow = props => {
|
165 | const id = props.id || '_' + props.value;
|
166 | const theme = props.theme || AmplifyTheme;
|
167 | return (
|
168 | <FormRow theme={theme}>
|
169 | <Radio {...props} id={id} />
|
170 | <Label htmlFor={id} theme={theme}>
|
171 | {props.placeholder}
|
172 | </Label>
|
173 | </FormRow>
|
174 | );
|
175 | };
|
176 |
|
177 | export const Radio = props => {
|
178 | const theme = props.theme || AmplifyTheme;
|
179 | const style = propStyle(props, theme.radio);
|
180 | const p = objectLessAttributes(props, 'theme');
|
181 | return beforeAfter(
|
182 | <input {...p} type="radio" className="amplify-radio" style={style} />
|
183 | );
|
184 | };
|
185 |
|
186 | export const CheckboxRow = props => {
|
187 | const id = props.id || '_' + props.name;
|
188 | const theme = props.theme || AmplifyTheme;
|
189 | return (
|
190 | <FormRow theme={theme}>
|
191 | <Checkbox {...props} id={id} />
|
192 | <Label htmlFor={id} theme={theme}>
|
193 | {props.placeholder}
|
194 | </Label>
|
195 | </FormRow>
|
196 | );
|
197 | };
|
198 |
|
199 | export const Checkbox = props => {
|
200 | const theme = props.theme || AmplifyTheme;
|
201 | const style = propStyle(props, theme.checkbox);
|
202 | const p = objectLessAttributes(props, 'theme');
|
203 | return beforeAfter(
|
204 | <input {...p} type="checkbox" className="amplify-checkbox" style={style} />
|
205 | );
|
206 | };
|
207 |
|
208 | export const MessageRow = props => {
|
209 | const theme = props.theme || AmplifyTheme;
|
210 | return (
|
211 | <FormRow theme={theme}>
|
212 | <MessageContent theme={theme}>{props.children}</MessageContent>
|
213 | </FormRow>
|
214 | );
|
215 | };
|
216 |
|
217 | export const MessageContent = props => {
|
218 | const theme = props.theme || AmplifyTheme;
|
219 | return beforeAfter(
|
220 | <span className="amplify-message-content" style={theme.messageContent}>
|
221 | {props.children}
|
222 | </span>
|
223 | );
|
224 | };
|
225 |
|
226 | export const ButtonRow = props => {
|
227 | const theme = props.theme || AmplifyTheme;
|
228 | return beforeAfter(
|
229 | <div className="amplify-action-row" style={theme.actionRow}>
|
230 | <Button {...props} />
|
231 | </div>
|
232 | );
|
233 | };
|
234 |
|
235 | export const Button = props => {
|
236 | const theme = props.theme || AmplifyTheme;
|
237 | const style = propStyle(props, theme.button);
|
238 | const p = objectLessAttributes(props, 'theme');
|
239 | return beforeAfter(
|
240 | <button {...p} className="amplify-button" style={style}>
|
241 | <ButtonContent theme={theme}>{props.children}</ButtonContent>
|
242 | </button>
|
243 | );
|
244 | };
|
245 |
|
246 | export const ButtonContent = props => {
|
247 | const theme = props.theme || AmplifyTheme;
|
248 | return beforeAfter(
|
249 | <span className="amplify-button-content" style={theme.buttonContent}>
|
250 | {props.children}
|
251 | </span>
|
252 | );
|
253 | };
|
254 |
|
255 | export const SignInButton = props => {
|
256 | const theme = props.theme || AmplifyTheme;
|
257 | const style = propStyle(props, theme.signInButton);
|
258 | const p = objectLessAttributes(props, 'theme');
|
259 |
|
260 | return beforeAfter(
|
261 | <button {...p} className="amplify-signin-button" style={style}>
|
262 | {props.children}
|
263 | </button>
|
264 | );
|
265 | };
|
266 |
|
267 | export const Link = props => {
|
268 | const theme = props.theme || AmplifyTheme;
|
269 | const style = propStyle(props, theme.a);
|
270 | const p = objectLessAttributes(props, 'theme');
|
271 | return beforeAfter(
|
272 | <a {...p} className="amplify-a" style={style}>
|
273 | {props.children}
|
274 | </a>
|
275 | );
|
276 | };
|
277 |
|
278 | export const Label = props => {
|
279 | const theme = props.theme || AmplifyTheme;
|
280 | const style = propStyle(props, theme.label);
|
281 | const p = objectLessAttributes(props, 'theme');
|
282 | return beforeAfter(
|
283 | <label {...p} className="amplify-label" style={style}>
|
284 | {props.children}
|
285 | </label>
|
286 | );
|
287 | };
|
288 |
|
289 | export const Space = props => {
|
290 | const theme = props.theme || AmplifyTheme;
|
291 | const style = propStyle(props, theme.space);
|
292 | const p = objectLessAttributes(props, 'theme');
|
293 | return beforeAfter(
|
294 | <span {...p} className="amplify-space" style={style}>
|
295 | {props.children}
|
296 | </span>
|
297 | );
|
298 | };
|
299 |
|
300 | export const NavBar = props => {
|
301 | const theme = props.theme || AmplifyTheme;
|
302 | const style = propStyle(props, theme.navBar);
|
303 | const p = objectLessAttributes(props, 'theme');
|
304 | return beforeAfter(
|
305 | <div {...p} className="amplify-nav-bar" style={style}>
|
306 | {props.children}
|
307 | </div>
|
308 | );
|
309 | };
|
310 |
|
311 | export const Nav = props => {
|
312 | const theme = props.theme || AmplifyTheme;
|
313 | const style = propStyle(props, theme.nav);
|
314 | const p = objectLessAttributes(props, 'theme');
|
315 | return beforeAfter(
|
316 | <div {...p} className="amplify-nav" style={style}>
|
317 | {props.children}
|
318 | </div>
|
319 | );
|
320 | };
|
321 |
|
322 | export const NavRight = props => {
|
323 | const theme = props.theme || AmplifyTheme;
|
324 | const style = propStyle(props, theme.navRight);
|
325 | const p = objectLessAttributes(props, 'theme');
|
326 | return beforeAfter(
|
327 | <div {...p} className="amplify-nav-right" style={style}>
|
328 | {props.children}
|
329 | </div>
|
330 | );
|
331 | };
|
332 |
|
333 | export const NavItem = props => {
|
334 | const theme = props.theme || AmplifyTheme;
|
335 | const style = propStyle(props, theme.navItem);
|
336 | const p = objectLessAttributes(props, 'theme');
|
337 | return beforeAfter(
|
338 | <div {...p} className="amplify-nav-item" style={style}>
|
339 | {props.children}
|
340 | </div>
|
341 | );
|
342 | };
|
343 |
|
344 | export const NavButton = props => {
|
345 | const theme = props.theme || AmplifyTheme;
|
346 | const style = propStyle(props, theme.navButton);
|
347 | const p = objectLessAttributes(props, 'theme');
|
348 | return beforeAfter(
|
349 | <button {...p} className="amplify-nav-button" style={style}>
|
350 | {beforeAfter(
|
351 | <span style={theme.navButtonContent}>{props.children}</span>
|
352 | )}
|
353 | </button>
|
354 | );
|
355 | };
|
356 |
|
357 | export const beforeAfter = el => {
|
358 | const style = el.props.style || {};
|
359 | const { before, after } = style;
|
360 | if (!before && !after) {
|
361 | return el;
|
362 | }
|
363 |
|
364 | return (
|
365 | <span style={{ position: 'relative' }}>
|
366 | {before ? <span style={before}>{before.content}</span> : null}
|
367 | {el}
|
368 | {after ? <span style={after}>{after.content}</span> : null}
|
369 | </span>
|
370 | );
|
371 | };
|
372 |
|
373 | export const propStyle = (props, themeStyle) => {
|
374 | const { id, style } = props;
|
375 | const styl = Object.assign({}, style, themeStyle);
|
376 | if (!id) {
|
377 | return styl;
|
378 | }
|
379 |
|
380 | const selector = '#' + id;
|
381 | Object.assign(styl, styl[selector]);
|
382 | return styl;
|
383 | };
|
384 |
|
385 | export const transparent1X1 =
|
386 | 'data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==';
|
387 |
|
388 | export const white1X1 =
|
389 | 'data:image/gif;base64,R0lGODlhAQABAIAAAP7//wAAACH5BAAAAAAALAAAAAABAAEAAAICRAEAOw==';
|