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

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 26 additions & 22 deletions code/03 React Essentials/01-starting-project/src/App.jsx
Original file line number Diff line number Diff line change
@@ -1,31 +1,35 @@
import reactImg from "./assets/react-core-concepts.png";

const reactDescription = ["Fundamental", "Crucial", "Core"];

function genRandomInt(max) {
return Math.floor(Math.random() * (max + 1));
}

function Header() {
const description = reactDescription[genRandomInt(2)];
return (
<header>
<img src={reactImg} alt="Stylized atom" />
<h1>React Essentials</h1>
<p>
{description} React concepts you will need for almost any app you are
going to build!
</p>
</header>
);
}
import { CORE_CONCEPTS } from "./data.js";
import Header from "./components/Header/Header.jsx";
import CoreConcept from "./components/CoreConcept.jsx";
import TabButton from "./components/TabButton.jsx";

function App() {
return (
<div>
<Header />
<main>
<h2>Time to get started!</h2>
<section id="core-concepts">
<h2>Time to get started!</h2>
<ul>
<CoreConcept
title={CORE_CONCEPTS[0].title}
description={CORE_CONCEPTS[0].description}
image={CORE_CONCEPTS[0].image}
/>
<CoreConcept {...CORE_CONCEPTS[1]} />
<CoreConcept {...CORE_CONCEPTS[2]} />
<CoreConcept {...CORE_CONCEPTS[3]} />
</ul>
</section>
<section id="examples">
<h2>Examples</h2>
<menu>
<TabButton>Component</TabButton>
<TabButton>JSX</TabButton>
<TabButton>Props</TabButton>
<TabButton>State</TabButton>
</menu>
</section>
</main>
</div>
);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export default function CoreConcept(props) {
return (
<li>
<img src={props.image} alt={props.title} />
<h3>{props.title}</h3>
<p>{props.description}</p>
</li>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
header {
text-align: center;
margin: 3rem 0;
}

header img {
height: 5rem;
width: 10rem;
object-fit: cover;
}

header h1 {
margin: 0;
font-family: "Roboto Condensed", sans-serif;
font-size: 5rem;
background: linear-gradient(40deg, #ea00ff, #ea00ff, #03d5ff, #03d5ff);
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
filter: drop-shadow(0 2px 8px rgba(0, 0, 0, 0.5));
}

header p {
margin: 0;
font-size: 1.25rem;
color: #8964b0;
font-family: "Roboto Condensed", sans-serif;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import reactImg from "../../assets/react-core-concepts.png";
import "./Header.css";
const reactDescription = ["Fundamental", "Crucial", "Core"];

function genRandomInt(max) {
return Math.floor(Math.random() * (max + 1));
}

export default function Header() {
const description = reactDescription[genRandomInt(2)];
return (
<header>
<img src={reactImg} alt="Stylized atom" />
<h1>React Essentials</h1>
<p>
{description} React concepts you will need for almost any app you are
going to build!
</p>
</header>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export default function TabButton({ children }) {
function handleClick() {
console.log("Hello World!");
}
return (
<li>
<button onClick={handleClick}>{children}</button>
</li>
);
}
31 changes: 31 additions & 0 deletions code/03 React Essentials/01-starting-project/src/data.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import componentsImg from "./assets/components.png";
import propsImg from "./assets/config.png";
import jsxImg from "./assets/jsx-ui.png";
import stateImg from "./assets/state-mgmt.png";

export const CORE_CONCEPTS = [
{
image: componentsImg,
title: "Components",
description:
"The core UI building block - compose the user interface by combining multiple components.",
},
{
image: jsxImg,
title: "JSX",
description:
"Return (potentially dynamic) HTML(ish) code to define the actual markup that will be rendered.",
},
{
image: propsImg,
title: "Props",
description:
"Make components configurable (and therefore reusable) by passing input data to them.",
},
{
image: stateImg,
title: "State",
description:
"React-managed data which, when changed, causes the component to re-render & the UI to update.",
},
];
28 changes: 0 additions & 28 deletions code/03 React Essentials/01-starting-project/src/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -19,34 +19,6 @@ html {
min-height: 80rem;
}

header {
text-align: center;
margin: 3rem 0;
}

header img {
height: 5rem;
width: 10rem;
object-fit: cover;
}

header h1 {
margin: 0;
font-family: "Roboto Condensed", sans-serif;
font-size: 5rem;
background: linear-gradient(40deg, #ea00ff, #ea00ff, #03d5ff, #03d5ff);
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
filter: drop-shadow(0 2px 8px rgba(0, 0, 0, 0.5));
}

header p {
margin: 0;
font-size: 1.25rem;
color: #8964b0;
font-family: "Roboto Condensed", sans-serif;
}

main {
width: 90%;
max-width: 50rem;
Expand Down
24 changes: 24 additions & 0 deletions vite-project/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*

node_modules
dist
dist-ssr
*.local

# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
.DS_Store
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
8 changes: 8 additions & 0 deletions vite-project/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# React + Vite

This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules.

Currently, two official plugins are available:

- [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react/README.md) uses [Babel](https://babeljs.io/) for Fast Refresh
- [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react-swc) uses [SWC](https://swc.rs/) for Fast Refresh
38 changes: 38 additions & 0 deletions vite-project/eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import js from '@eslint/js'
import globals from 'globals'
import react from 'eslint-plugin-react'
import reactHooks from 'eslint-plugin-react-hooks'
import reactRefresh from 'eslint-plugin-react-refresh'

export default [
{ ignores: ['dist'] },
{
files: ['**/*.{js,jsx}'],
languageOptions: {
ecmaVersion: 2020,
globals: globals.browser,
parserOptions: {
ecmaVersion: 'latest',
ecmaFeatures: { jsx: true },
sourceType: 'module',
},
},
settings: { react: { version: '18.3' } },
plugins: {
react,
'react-hooks': reactHooks,
'react-refresh': reactRefresh,
},
rules: {
...js.configs.recommended.rules,
...react.configs.recommended.rules,
...react.configs['jsx-runtime'].rules,
...reactHooks.configs.recommended.rules,
'react/jsx-no-target-blank': 'off',
'react-refresh/only-export-components': [
'warn',
{ allowConstantExport: true },
],
},
},
]
13 changes: 13 additions & 0 deletions vite-project/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Vite + React</title>
</head>
<body>
<div id="root"></div>
<script type="module" src="/src/main.jsx"></script>
</body>
</html>
28 changes: 28 additions & 0 deletions vite-project/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"name": "vite-project",
"private": true,
"version": "0.0.0",
"type": "module",
"scripts": {
"dev": "vite",
"build": "vite build",
"lint": "eslint .",
"preview": "vite preview"
},
"dependencies": {
"react": "^18.3.1",
"react-dom": "^18.3.1"
},
"devDependencies": {
"@eslint/js": "^9.9.0",
"@types/react": "^18.3.3",
"@types/react-dom": "^18.3.0",
"@vitejs/plugin-react": "^4.3.1",
"eslint": "^9.9.0",
"eslint-plugin-react": "^7.35.0",
"eslint-plugin-react-hooks": "^5.1.0-rc.0",
"eslint-plugin-react-refresh": "^0.4.9",
"globals": "^15.9.0",
"vite": "^5.4.1"
}
}
1 change: 1 addition & 0 deletions vite-project/public/vite.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
42 changes: 42 additions & 0 deletions vite-project/src/App.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#root {
max-width: 1280px;
margin: 0 auto;
padding: 2rem;
text-align: center;
}

.logo {
height: 6em;
padding: 1.5em;
will-change: filter;
transition: filter 300ms;
}
.logo:hover {
filter: drop-shadow(0 0 2em #646cffaa);
}
.logo.react:hover {
filter: drop-shadow(0 0 2em #61dafbaa);
}

@keyframes logo-spin {
from {
transform: rotate(0deg);
}
to {
transform: rotate(360deg);
}
}

@media (prefers-reduced-motion: no-preference) {
a:nth-of-type(2) .logo {
animation: logo-spin infinite 20s linear;
}
}

.card {
padding: 2em;
}

.read-the-docs {
color: #888;
}
35 changes: 35 additions & 0 deletions vite-project/src/App.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { useState } from 'react'
import reactLogo from './assets/react.svg'
import viteLogo from '/vite.svg'
import './App.css'

function App() {
const [count, setCount] = useState(0)

return (
<>
<div>
<a href="https://vitejs.dev" target="_blank">
<img src={viteLogo} className="logo" alt="Vite logo" />
</a>
<a href="https://react.dev" target="_blank">
<img src={reactLogo} className="logo react" alt="React logo" />
</a>
</div>
<h1>Vite + React</h1>
<div className="card">
<button onClick={() => setCount((count) => count + 1)}>
count is {count}
</button>
<p>
Edit <code>src/App.jsx</code> and save to test HMR
</p>
</div>
<p className="read-the-docs">
Click on the Vite and React logos to learn more
</p>
</>
)
}

export default App
1 change: 1 addition & 0 deletions vite-project/src/assets/react.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading