Skip to content
This repository was archived by the owner on Apr 11, 2019. It is now read-only.

Commit 5abe87a

Browse files
committed
Feat: add an example with modal and redux form
1 parent ff565a5 commit 5abe87a

File tree

17 files changed

+321
-26
lines changed

17 files changed

+321
-26
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
## Divider Component
2+
A component that acts as a section divider.
3+
4+
### Example
5+
6+
```js
7+
<Divider />
8+
```
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import React from 'react';
2+
import styles from './index.module.scss';
3+
import cssModules from 'react-css-modules';
4+
5+
const Divider = () => (
6+
<span className={styles.divider} />
7+
);
8+
9+
10+
export default cssModules(Divider, styles);
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
.divider {
2+
background-color: #7d97ad;
3+
width: 150px;
4+
height: 3px;
5+
display: block;
6+
margin: 35px 0;
7+
margin-right: auto;
8+
margin-left: auto;
9+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import Divider from '../index';
2+
import { shallow } from 'enzyme';
3+
import { shallowToJson } from 'enzyme-to-json';
4+
import React from 'react';
5+
6+
describe('<Divider />', () => {
7+
it('should render with default props', () => {
8+
const wrapper = shallow(
9+
<Divider />
10+
);
11+
expect(shallowToJson(wrapper)).toMatchSnapshot();
12+
});
13+
});
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
## WelcomeModal Component
2+
A component that ...
3+
4+
### Example
5+
6+
```js
7+
<WelcomeModal />
8+
```
9+
10+
### Props
11+
12+
| Prop | Type | Default | Possible Values
13+
| ------------- | -------- | ----------- | ---------------------------------------------
14+
| **myProp** | String | | Any string value
15+
16+
17+
### Other Information
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
import React, { PropTypes } from 'react';
2+
import Layer from 'grommet-udacity/components/Layer';
3+
import Form from 'grommet-udacity/components/Form';
4+
import FormFields from 'grommet-udacity/components/FormFields';
5+
import FormField from 'grommet-udacity/components/FormField';
6+
import Box from 'grommet-udacity/components/Box';
7+
import Heading from 'grommet-udacity/components/Heading';
8+
import Button from 'grommet-udacity/components/Button';
9+
import Footer from 'grommet-udacity/components/Footer';
10+
import { Divider } from 'components';
11+
import error from './utils/error';
12+
13+
const WelcomeModal = ({
14+
onClose,
15+
isVisible,
16+
nameInput,
17+
onSubmit,
18+
}) => (
19+
<Layer
20+
align="center"
21+
closer
22+
hidden={!isVisible}
23+
onClose={onClose}
24+
>
25+
<Box align="center" justify="center" pad="large">
26+
<Heading align="center">
27+
What should we call you?
28+
</Heading>
29+
<Divider />
30+
<Form>
31+
<FormFields>
32+
<FormField
33+
help="What should we call you?"
34+
error={error(nameInput)}
35+
label="Enter your name"
36+
htmlFor="nameInput"
37+
>
38+
<input
39+
{...nameInput}
40+
required
41+
autoFocus
42+
placeholder="Ryan Collins"
43+
id="nameInput"
44+
autoComplete="on"
45+
name="name"
46+
type="text"
47+
aria-invalid={nameInput.error}
48+
aria-required
49+
className="input"
50+
/>
51+
</FormField>
52+
</FormFields>
53+
</Form>
54+
<Footer align="center" justify="center" pad="large">
55+
<Button primary label="Submit" onClick={onSubmit} />
56+
</Footer>
57+
</Box>
58+
</Layer>
59+
);
60+
61+
WelcomeModal.propTypes = {
62+
onClose: PropTypes.func.isRequired,
63+
nameInput: PropTypes.object.isRequired,
64+
isVisible: PropTypes.bool.isRequired,
65+
onSubmit: PropTypes.func.isRequired,
66+
};
67+
68+
export default WelcomeModal;
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import WelcomeModal from '../index';
2+
import { shallow } from 'enzyme';
3+
import { shallowToJson } from 'enzyme-to-json';
4+
import React from 'react';
5+
6+
describe('<WelcomeModal />', () => {
7+
it('should render with default props', () => {
8+
const wrapper = shallow(
9+
<WelcomeModal />
10+
);
11+
expect(shallowToJson(wrapper)).toMatchSnapshot();
12+
});
13+
});
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
const error = (input) =>
2+
input.dirty || input.touched && input.error ? input.error : null;
3+
4+
export default error;

app/src/components/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
/* Assemble all components for export */
2+
export WelcomeModal from './WelcomeModal';
3+
export Divider from './Divider';
24
export AppFooter from './AppFooter';
35
export LoadingIndicator from './LoadingIndicator';
46
export Navbar from './Navbar';
Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
## LandingContainer
2-
A container that does ...
2+
The main container for the demo site.
33

44
### Example Usage
55

66
```js
77
<LandingContainer />
88
```
9-
10-
11-
### Other Information

0 commit comments

Comments
 (0)