Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions code/01-starting-project/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"name": "react-complete-guide",
"version": "0.1.0",
"private": true,
"dependencies": {
"@testing-library/jest-dom": "^5.11.6",
"@testing-library/react": "^11.2.2",
"@testing-library/user-event": "^12.5.0",
"react": "^17.0.1",
"react-dom": "^17.0.1",
"react-router-dom": "^5.2.0",
"react-scripts": "4.0.1",
"web-vitals": "^0.2.4"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": [
"react-app",
"react-app/jest"
]
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
}
}
Binary file added code/01-starting-project/public/favicon.ico
Binary file not shown.
43 changes: 43 additions & 0 deletions code/01-starting-project/public/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="theme-color" content="#000000" />
<meta
name="description"
content="Web site created using create-react-app"
/>
<link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" />
<!--
manifest.json provides metadata used when your web app is installed on a
user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
-->
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
<!--
Notice the use of %PUBLIC_URL% in the tags above.
It will be replaced with the URL of the `public` folder during the build.
Only files inside the `public` folder can be referenced from the HTML.
Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
work correctly both with client-side routing and a non-root public URL.
Learn how to configure a non-root public URL by running `npm run build`.
-->
<title>React App</title>
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root"></div>
<!--
This HTML file is a template.
If you open it directly in the browser, you will see an empty page.
You can add webfonts, meta tags, or analytics to this file.
The build step will place the bundled scripts into the <body> tag.
To begin the development, run `npm start` or `yarn start`.
To create a production bundle, use `npm run build` or `yarn build`.
-->
</body>
</html>
Binary file added code/01-starting-project/public/logo192.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added code/01-starting-project/public/logo512.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
25 changes: 25 additions & 0 deletions code/01-starting-project/public/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"short_name": "React App",
"name": "Create React App Sample",
"icons": [
{
"src": "favicon.ico",
"sizes": "64x64 32x32 24x24 16x16",
"type": "image/x-icon"
},
{
"src": "logo192.png",
"type": "image/png",
"sizes": "192x192"
},
{
"src": "logo512.png",
"type": "image/png",
"sizes": "512x512"
}
],
"start_url": ".",
"display": "standalone",
"theme_color": "#000000",
"background_color": "#ffffff"
}
3 changes: 3 additions & 0 deletions code/01-starting-project/public/robots.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# https://www.robotstxt.org/robotstxt.html
User-agent: *
Disallow:
26 changes: 26 additions & 0 deletions code/01-starting-project/src/App.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { Switch, Route } from 'react-router-dom';

import Layout from './components/Layout/Layout';
import UserProfile from './components/Profile/UserProfile';
import AuthPage from './pages/AuthPage';
import HomePage from './pages/HomePage';

function App() {
return (
<Layout>
<Switch>
<Route path='/' exact>
<HomePage />
</Route>
<Route path='/auth'>
<AuthPage />
</Route>
<Route path='/profile'>
<UserProfile />
</Route>
</Switch>
</Layout>
);
}

export default App;
39 changes: 39 additions & 0 deletions code/01-starting-project/src/components/Auth/AuthForm.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { useState } from 'react';

import classes from './AuthForm.module.css';

const AuthForm = () => {
const [isLogin, setIsLogin] = useState(true);

const switchAuthModeHandler = () => {
setIsLogin((prevState) => !prevState);
};

return (
<section className={classes.auth}>
<h1>{isLogin ? 'Login' : 'Sign Up'}</h1>
<form>
<div className={classes.control}>
<label htmlFor='email'>Your Email</label>
<input type='email' id='email' required />
</div>
<div className={classes.control}>
<label htmlFor='password'>Your Password</label>
<input type='password' id='password' required />
</div>
<div className={classes.actions}>
<button>{isLogin ? 'Login' : 'Create Account'}</button>
<button
type='button'
className={classes.toggle}
onClick={switchAuthModeHandler}
>
{isLogin ? 'Create new account' : 'Login with existing account'}
</button>
</div>
</form>
</section>
);
};

export default AuthForm;
72 changes: 72 additions & 0 deletions code/01-starting-project/src/components/Auth/AuthForm.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
.auth {
margin: 3rem auto;
width: 95%;
max-width: 25rem;
border-radius: 6px;
background-color: #38015c;
box-shadow: 0 1px 4px rgba(0, 0, 0, 0.2);
padding: 1rem;
text-align: center;
}

.auth h1 {
text-align: center;
color: white;
}

.control {
margin-bottom: 0.5rem;
}

.control label {
display: block;
color: white;
font-weight: bold;
margin-bottom: 0.5rem;
}

.control input {
font: inherit;
background-color: #f1e1fc;
color: #38015c;
border-radius: 4px;
border: 1px solid white;
width: 100%;
text-align: left;
padding: 0.25rem;
}

.actions {
margin-top: 1.5rem;
display: flex;
flex-direction: column;
align-items: center;
}

.actions button {
cursor: pointer;
font: inherit;
color: white;
background-color: #9f5ccc;
border: 1px solid #9f5ccc;
border-radius: 4px;
padding: 0.5rem 2.5rem;
}

.actions button:hover {
background-color: #873abb;
border-color: #873abb;
}

.actions .toggle {
margin-top: 1rem;
background-color: transparent;
color: #9f5ccc;
border: none;
padding: 0.15rem 1.5rem;
}

.actions .toggle:hover {
background-color: transparent;
color: #ae82cc;
}
14 changes: 14 additions & 0 deletions code/01-starting-project/src/components/Layout/Layout.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { Fragment } from 'react';

import MainNavigation from './MainNavigation';

const Layout = (props) => {
return (
<Fragment>
<MainNavigation />
<main>{props.children}</main>
</Fragment>
);
};

export default Layout;
28 changes: 28 additions & 0 deletions code/01-starting-project/src/components/Layout/MainNavigation.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { Link } from 'react-router-dom';

import classes from './MainNavigation.module.css';

const MainNavigation = () => {
return (
<header className={classes.header}>
<Link to='/'>
<div className={classes.logo}>React Auth</div>
</Link>
<nav>
<ul>
<li>
<Link to='/auth'>Login</Link>
</li>
<li>
<Link to='/profile'>Profile</Link>
</li>
<li>
<button>Logout</button>
</li>
</ul>
</nav>
</header>
);
};

export default MainNavigation;
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
.header {
width: 100%;
height: 5rem;
background-color: #38015c;
box-shadow: 0 1px 4px rgba(0, 0, 0, 0.2);
display: flex;
justify-content: space-between;
align-items: center;
padding: 0 10%;
}

.logo {
font-family: 'Lato', sans-serif;
font-size: 2rem;
color: white;
margin: 0;
}

.header ul {
list-style: none;
margin: 0;
padding: 0;
display: flex;
align-items: baseline;
}

.header li {
margin: 0 1rem;
}

.header a {
text-decoration: none;
color: white;
font-weight: bold;
}

.header button {
font: inherit;
background-color: transparent;
border: 1px solid white;
color: white;
font-weight: bold;
padding: 0.5rem 1.5rem;
border-radius: 6px;
cursor: pointer;
}

.header a:hover {
color: #c291e2;
}

.header button:hover {
background-color: #c291e2;
color: #38015c;
}
17 changes: 17 additions & 0 deletions code/01-starting-project/src/components/Profile/ProfileForm.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import classes from './ProfileForm.module.css';

const ProfileForm = () => {
return (
<form className={classes.form}>
<div className={classes.control}>
<label htmlFor='new-password'>New Password</label>
<input type='password' id='new-password' />
</div>
<div className={classes.action}>
<button>Change Password</button>
</div>
</form>
);
}

export default ProfileForm;
Loading