├── .gitignore
├── README.md
├── _config.yml
├── package.json
├── public
├── favicon.ico
├── index.html
└── manifest.json
└── src
├── App.js
├── App.test.js
├── components
├── Confirm.js
├── FormPersonalDetails.js
├── FormUserDetails.js
├── Success.js
└── UserForm.js
├── index.css
├── index.js
└── serviceWorker.js
/.gitignore:
--------------------------------------------------------------------------------
1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2 |
3 | # dependencies
4 | /node_modules
5 | /.pnp
6 | .pnp.js
7 |
8 | # testing
9 | /coverage
10 |
11 | # production
12 | /build
13 |
14 | # misc
15 | .DS_Store
16 | .env.local
17 | .env.development.local
18 | .env.test.local
19 | .env.production.local
20 |
21 | npm-debug.log*
22 | yarn-debug.log*
23 | yarn-error.log*
24 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # React Step Form
2 |
3 | > Form with multiple steps and confirmation. Frontend only, no API. Uses Material UI
4 |
5 | ## Quick Start
6 |
7 | ```bash
8 | # Install dependencies
9 | npm install
10 |
11 | # Serve on localhost:3000
12 | npm start
13 |
14 | # Build for production
15 | npm run build
16 | ```
17 |
18 | ## App Info
19 |
20 | ### Author
21 |
22 | Brad Traversy
23 | [Traversy Media](http://www.traversymedia.com)
24 |
25 | ### Version
26 |
27 | 1.0.0
28 |
29 | ### License
30 |
31 | This project is licensed under the MIT License
32 |
--------------------------------------------------------------------------------
/_config.yml:
--------------------------------------------------------------------------------
1 | theme: jekyll-theme-cayman
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "react_step_form",
3 | "version": "0.1.0",
4 | "private": true,
5 | "dependencies": {
6 | "@material-ui/core": "^4.9.13",
7 | "@material-ui/icons": "^4.9.1",
8 | "@material-ui/styles": "^4.9.13",
9 | "react": "^16.13.1",
10 | "react-dom": "^16.13.1",
11 | "react-scripts": "^3.4.1"
12 | },
13 | "scripts": {
14 | "start": "react-scripts start",
15 | "build": "react-scripts build",
16 | "test": "react-scripts test",
17 | "eject": "react-scripts eject"
18 | },
19 | "eslintConfig": {
20 | "extends": "react-app"
21 | },
22 | "browserslist": [
23 | ">0.2%",
24 | "not dead",
25 | "not ie <= 11",
26 | "not op_mini all"
27 | ]
28 | }
29 |
--------------------------------------------------------------------------------
/public/favicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bradtraversy/react_step_form/efa30afcba4ac4fd53db4053886059b6ede4d557/public/favicon.ico
--------------------------------------------------------------------------------
/public/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
12 |
13 |
22 | React App
23 |
24 |
25 |
28 |
29 |
39 |
40 |
41 |
--------------------------------------------------------------------------------
/public/manifest.json:
--------------------------------------------------------------------------------
1 | {
2 | "short_name": "React App",
3 | "name": "Create React App Sample",
4 | "icons": [
5 | {
6 | "src": "favicon.ico",
7 | "sizes": "64x64 32x32 24x24 16x16",
8 | "type": "image/x-icon"
9 | }
10 | ],
11 | "start_url": ".",
12 | "display": "standalone",
13 | "theme_color": "#000000",
14 | "background_color": "#ffffff"
15 | }
16 |
--------------------------------------------------------------------------------
/src/App.js:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import { UserForm } from './components/UserForm';
3 |
4 | const App = () => {
5 | return (
6 |
7 |
8 |
9 | );
10 | }
11 |
12 | export default App;
13 |
--------------------------------------------------------------------------------
/src/App.test.js:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import ReactDOM from 'react-dom';
3 | import App from './App';
4 |
5 | it('renders without crashing', () => {
6 | const div = document.createElement('div');
7 | ReactDOM.render(, div);
8 | ReactDOM.unmountComponentAtNode(div);
9 | });
10 |
--------------------------------------------------------------------------------
/src/components/Confirm.js:
--------------------------------------------------------------------------------
1 | import React, { Component } from 'react';
2 | import Dialog from '@material-ui/core/Dialog';
3 | import AppBar from '@material-ui/core/AppBar';
4 | import { ThemeProvider as MuiThemeProvider } from '@material-ui/core/styles';
5 | import { List, ListItem, ListItemText } from '@material-ui/core/';
6 | import Button from '@material-ui/core/Button';
7 |
8 | export class Confirm extends Component {
9 | continue = e => {
10 | e.preventDefault();
11 | // PROCESS FORM //
12 | this.props.nextStep();
13 | };
14 |
15 | back = e => {
16 | e.preventDefault();
17 | this.props.prevStep();
18 | };
19 |
20 | render() {
21 | const {
22 | values: { firstName, lastName, email, occupation, city, bio }
23 | } = this.props;
24 | return (
25 |
26 | <>
27 |
67 | >
68 |
69 | );
70 | }
71 | }
72 |
73 | export default Confirm;
74 |
--------------------------------------------------------------------------------
/src/components/FormPersonalDetails.js:
--------------------------------------------------------------------------------
1 | import React, { Component } from 'react';
2 | import Dialog from '@material-ui/core/Dialog';
3 | import AppBar from '@material-ui/core/AppBar';
4 | import { ThemeProvider as MuiThemeProvider } from '@material-ui/core/styles';
5 | import TextField from '@material-ui/core/TextField';
6 | import Button from '@material-ui/core/Button';
7 |
8 | export class FormPersonalDetails extends Component {
9 | continue = e => {
10 | e.preventDefault();
11 | this.props.nextStep();
12 | };
13 |
14 | back = e => {
15 | e.preventDefault();
16 | this.props.prevStep();
17 | };
18 |
19 | render() {
20 | const { values, handleChange } = this.props;
21 | return (
22 |
23 | <>
24 |
70 | >
71 |
72 | );
73 | }
74 | }
75 |
76 | export default FormPersonalDetails;
77 |
--------------------------------------------------------------------------------
/src/components/FormUserDetails.js:
--------------------------------------------------------------------------------
1 | import React, { Component } from 'react';
2 | import Dialog from '@material-ui/core/Dialog';
3 | import AppBar from '@material-ui/core/AppBar';
4 | import { ThemeProvider as MuiThemeProvider } from '@material-ui/core/styles';
5 | import TextField from '@material-ui/core/TextField';
6 | import Button from '@material-ui/core/Button';
7 |
8 | export class FormUserDetails extends Component {
9 | continue = e => {
10 | e.preventDefault();
11 | this.props.nextStep();
12 | };
13 |
14 | render() {
15 | const { values, handleChange } = this.props;
16 | return (
17 |
18 | <>
19 |
58 | >
59 |
60 | );
61 | }
62 | }
63 |
64 | export default FormUserDetails;
65 |
--------------------------------------------------------------------------------
/src/components/Success.js:
--------------------------------------------------------------------------------
1 | import React, { Component } from 'react';
2 | import Dialog from '@material-ui/core/Dialog';
3 | import AppBar from '@material-ui/core/AppBar';
4 | import { ThemeProvider as MuiThemeProvider } from '@material-ui/core/styles';
5 |
6 | export class Success extends Component {
7 | continue = e => {
8 | e.preventDefault();
9 | // PROCESS FORM //
10 | this.props.nextStep();
11 | };
12 |
13 | back = e => {
14 | e.preventDefault();
15 | this.props.prevStep();
16 | };
17 |
18 | render() {
19 | return (
20 |
21 | <>
22 |
31 | >
32 |
33 | );
34 | }
35 | }
36 |
37 | export default Success;
38 |
--------------------------------------------------------------------------------
/src/components/UserForm.js:
--------------------------------------------------------------------------------
1 | import React, { Component } from 'react';
2 | import FormUserDetails from './FormUserDetails';
3 | import FormPersonalDetails from './FormPersonalDetails';
4 | import Confirm from './Confirm';
5 | import Success from './Success';
6 |
7 | export class UserForm extends Component {
8 | state = {
9 | step: 1,
10 | firstName: '',
11 | lastName: '',
12 | email: '',
13 | occupation: '',
14 | city: '',
15 | bio: ''
16 | };
17 |
18 | // Proceed to next step
19 | nextStep = () => {
20 | const { step } = this.state;
21 | this.setState({
22 | step: step + 1
23 | });
24 | };
25 |
26 | // Go back to prev step
27 | prevStep = () => {
28 | const { step } = this.state;
29 | this.setState({
30 | step: step - 1
31 | });
32 | };
33 |
34 | // Handle fields change
35 | handleChange = input => e => {
36 | this.setState({ [input]: e.target.value });
37 | };
38 |
39 | render() {
40 | const { step } = this.state;
41 | const { firstName, lastName, email, occupation, city, bio } = this.state;
42 | const values = { firstName, lastName, email, occupation, city, bio };
43 |
44 | switch (step) {
45 | case 1:
46 | return (
47 |
52 | );
53 | case 2:
54 | return (
55 |
61 | );
62 | case 3:
63 | return (
64 |
69 | );
70 | case 4:
71 | return ;
72 | default:
73 | (console.log('This is a multi-step form built with React.'))
74 | }
75 | }
76 | }
77 |
78 | export default UserForm;
79 |
--------------------------------------------------------------------------------
/src/index.css:
--------------------------------------------------------------------------------
1 | body {
2 | margin: 0;
3 | padding: 0;
4 | font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto", "Oxygen",
5 | "Ubuntu", "Cantarell", "Fira Sans", "Droid Sans", "Helvetica Neue",
6 | sans-serif;
7 | -webkit-font-smoothing: antialiased;
8 | -moz-osx-font-smoothing: grayscale;
9 | }
10 |
11 | code {
12 | font-family: source-code-pro, Menlo, Monaco, Consolas, "Courier New",
13 | monospace;
14 | }
15 |
16 | .MuiDialog-paper {
17 | padding: 15px;
18 | }
19 |
20 | button.MuiButton-containedSecondary {
21 | margin-bottom: 10px;
22 | }
--------------------------------------------------------------------------------
/src/index.js:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import ReactDOM from 'react-dom';
3 | import './index.css';
4 | import App from './App';
5 | import * as serviceWorker from './serviceWorker';
6 |
7 | ReactDOM.render(, document.getElementById('root'));
8 |
9 | // If you want your app to work offline and load faster, you can change
10 | // unregister() to register() below. Note this comes with some pitfalls.
11 | // Learn more about service workers: http://bit.ly/CRA-PWA
12 | serviceWorker.unregister();
13 |
--------------------------------------------------------------------------------
/src/serviceWorker.js:
--------------------------------------------------------------------------------
1 | // This optional code is used to register a service worker.
2 | // register() is not called by default.
3 |
4 | // This lets the app load faster on subsequent visits in production, and gives
5 | // it offline capabilities. However, it also means that developers (and users)
6 | // will only see deployed updates on subsequent visits to a page, after all the
7 | // existing tabs open on the page have been closed, since previously cached
8 | // resources are updated in the background.
9 |
10 | // To learn more about the benefits of this model and instructions on how to
11 | // opt-in, read http://bit.ly/CRA-PWA
12 |
13 | const isLocalhost = Boolean(
14 | window.location.hostname === 'localhost' ||
15 | // [::1] is the IPv6 localhost address.
16 | window.location.hostname === '[::1]' ||
17 | // 127.0.0.1/8 is considered localhost for IPv4.
18 | window.location.hostname.match(
19 | /^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/
20 | )
21 | );
22 |
23 | export function register(config) {
24 | if (process.env.NODE_ENV === 'production' && 'serviceWorker' in navigator) {
25 | // The URL constructor is available in all browsers that support SW.
26 | const publicUrl = new URL(process.env.PUBLIC_URL, window.location.href);
27 | if (publicUrl.origin !== window.location.origin) {
28 | // Our service worker won't work if PUBLIC_URL is on a different origin
29 | // from what our page is served on. This might happen if a CDN is used to
30 | // serve assets; see https://github.com/facebook/create-react-app/issues/2374
31 | return;
32 | }
33 |
34 | window.addEventListener('load', () => {
35 | const swUrl = `${process.env.PUBLIC_URL}/service-worker.js`;
36 |
37 | if (isLocalhost) {
38 | // This is running on localhost. Let's check if a service worker still exists or not.
39 | checkValidServiceWorker(swUrl, config);
40 |
41 | // Add some additional logging to localhost, pointing developers to the
42 | // service worker/PWA documentation.
43 | navigator.serviceWorker.ready.then(() => {
44 | console.log(
45 | 'This web app is being served cache-first by a service ' +
46 | 'worker. To learn more, visit http://bit.ly/CRA-PWA'
47 | );
48 | });
49 | } else {
50 | // Is not localhost. Just register service worker
51 | registerValidSW(swUrl, config);
52 | }
53 | });
54 | }
55 | }
56 |
57 | function registerValidSW(swUrl, config) {
58 | navigator.serviceWorker
59 | .register(swUrl)
60 | .then(registration => {
61 | registration.onupdatefound = () => {
62 | const installingWorker = registration.installing;
63 | if (installingWorker == null) {
64 | return;
65 | }
66 | installingWorker.onstatechange = () => {
67 | if (installingWorker.state === 'installed') {
68 | if (navigator.serviceWorker.controller) {
69 | // At this point, the updated precached content has been fetched,
70 | // but the previous service worker will still serve the older
71 | // content until all client tabs are closed.
72 | console.log(
73 | 'New content is available and will be used when all ' +
74 | 'tabs for this page are closed. See http://bit.ly/CRA-PWA.'
75 | );
76 |
77 | // Execute callback
78 | if (config && config.onUpdate) {
79 | config.onUpdate(registration);
80 | }
81 | } else {
82 | // At this point, everything has been precached.
83 | // It's the perfect time to display a
84 | // "Content is cached for offline use." message.
85 | console.log('Content is cached for offline use.');
86 |
87 | // Execute callback
88 | if (config && config.onSuccess) {
89 | config.onSuccess(registration);
90 | }
91 | }
92 | }
93 | };
94 | };
95 | })
96 | .catch(error => {
97 | console.error('Error during service worker registration:', error);
98 | });
99 | }
100 |
101 | function checkValidServiceWorker(swUrl, config) {
102 | // Check if the service worker can be found. If it can't reload the page.
103 | fetch(swUrl)
104 | .then(response => {
105 | // Ensure service worker exists, and that we really are getting a JS file.
106 | const contentType = response.headers.get('content-type');
107 | if (
108 | response.status === 404 ||
109 | (contentType != null && contentType.indexOf('javascript') === -1)
110 | ) {
111 | // No service worker found. Probably a different app. Reload the page.
112 | navigator.serviceWorker.ready.then(registration => {
113 | registration.unregister().then(() => {
114 | window.location.reload();
115 | });
116 | });
117 | } else {
118 | // Service worker found. Proceed as normal.
119 | registerValidSW(swUrl, config);
120 | }
121 | })
122 | .catch(() => {
123 | console.log(
124 | 'No internet connection found. App is running in offline mode.'
125 | );
126 | });
127 | }
128 |
129 | export function unregister() {
130 | if ('serviceWorker' in navigator) {
131 | navigator.serviceWorker.ready.then(registration => {
132 | registration.unregister();
133 | });
134 | }
135 | }
136 |
--------------------------------------------------------------------------------