UNPKG

10.5 kBTypeScriptView Raw
1/*
2 * Copyright 2017-2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
5 * the License. A copy of the License is located at
6 *
7 * http://aws.amazon.com/apache2.0/
8 *
9 * or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
10 * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
11 * and limitations under the License.
12 */
13
14import * as React from 'react';
15
16import { objectLessAttributes } from '@aws-amplify/core';
17
18import AmplifyTheme from './AmplifyTheme';
19
20export 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
31export 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
41export 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
55export 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
66export 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
76export 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
89export 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
99export 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
110export 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
120export 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
131export 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
142export 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
153export 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
164export 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
177export 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
186export 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
199export 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
208export 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
217export 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
226export 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
235export 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
246export 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
255export 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
267export 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
278export 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
289export 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
300export 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
311export 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
322export 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
333export 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
344export 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
357export 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
373export 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
385export const transparent1X1 =
386 'data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==';
387
388export const white1X1 =
389 'data:image/gif;base64,R0lGODlhAQABAIAAAP7//wAAACH5BAAAAAAALAAAAAABAAEAAAICRAEAOw==';