Skip to content

Commit

Permalink
initial demo commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Susie Douang authored and Susie Douang committed Nov 16, 2023
1 parent 45a0119 commit 0e67198
Show file tree
Hide file tree
Showing 16 changed files with 348 additions and 86 deletions.
15 changes: 15 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "chrome",
"request": "launch",
"name": "Launch Chrome against localhost",
"url": "http://localhost:3000",
"webRoot": "${workspaceFolder}"
}
]
}
4 changes: 4 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,7 @@
"last 1 firefox version",
"last 1 safari version"
]
},
"devDependencies": {
}
}
40 changes: 5 additions & 35 deletions public/index.html
Original file line number Diff line number Diff line change
@@ -1,43 +1,13 @@
<!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>
<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>React Essentials</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`.
-->
<!-- <script type="module" src="/src/index.jsx"></script> -->
</body>
</html>
25 changes: 0 additions & 25 deletions src/App.js

This file was deleted.

85 changes: 85 additions & 0 deletions src/App.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
import { useState } from 'react';
import reactAtom from './assets/react-core-concepts.png';
import './index.css';
import { CORE_CONCEPTS, EXAMPLES } from './data';

const reactDescriptions = ['Fundamental', 'Crucial', 'Core'];

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

function Header() {
return (
<header>
<img src={reactAtom} alt='Stylized atom' />
<h1>React Essentials</h1>
<p>
{reactDescriptions[genRandomInt(2)]} React concepts you will need for
almost any app you are going to build!
</p>
</header>
);
}

let CoreConcepts = ({image, title, description}) => {
return (
<li key={title}>
<img src={image} alt={title}/>
<h3>{title}</h3>
<p>{description}</p>
</li>
)
}

let tabContent = <p>Please select a topic.</p>

let TabButton = ({children, onSelect, isSelected}) => {
return <li key={children.title}>
<button className={isSelected ? 'active' : ''} onClick={onSelect}>{children}</button>
</li>
}

function App() {
const [selectedTopic, setSelectedTopic] = useState();

let handleButtonClick = (selectedButton) => {
setSelectedTopic(selectedButton);
console.log(selectedTopic)
}

return (
<div>
<Header />
<main>
<div style={{display: "flex"}}>
{CORE_CONCEPTS.map((c) =>
<section id="core-concepts">
<ul key={c.title}>
<CoreConcepts {...c}/>
</ul>
</section>)}
</div>
<section id="examples">
<h2>Examples</h2>
<menu>
<TabButton isSelected={selectedTopic === 'components'} onSelect={() => handleButtonClick('components')} children="Components"/>
<TabButton isSelected={selectedTopic === 'jsx'} onSelect={() => handleButtonClick('jsx')} children="JSX"/>
<TabButton isSelected={selectedTopic === 'props'} onSelect={() => handleButtonClick('props')} children="Props"/>
<TabButton isSelected={selectedTopic === 'state'} onSelect={() => handleButtonClick('state')} children="State"/>
</menu>
{!selectedTopic ? <div>{tabContent}</div> :
<div className="tab">
<h3>{EXAMPLES[selectedTopic].title}</h3>
<p>{EXAMPLES[selectedTopic].description}</p>
<pre>
<code>{EXAMPLES[selectedTopic].code}</code>
</pre>
</div>}
</section>
</main>
</div>
);
}

export default App;
2 changes: 1 addition & 1 deletion src/App.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { render, screen } from '@testing-library/react';
import App from './App';
import App from '../App';

test('renders learn react link', () => {
render(<App />);
Expand Down
Binary file added src/assets/components.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 src/assets/config.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 src/assets/jsx-ui.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 src/assets/react-core-concepts.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 src/assets/state-mgmt.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
82 changes: 82 additions & 0 deletions src/data.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
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.',
},
];

export const EXAMPLES = {
components: {
title: 'Components',
description:
'Components are the building blocks of React applications. A component is a self-contained module (HTML + optional CSS + JS) that renders some output.',
code: `
function Welcome() {
return <h1>Hello, World!</h1>;
}`,
},
jsx: {
title: 'JSX',
description:
'JSX is a syntax extension to JavaScript. It is similar to a template language, but it has full power of JavaScript (e.g., it may output dynamic content).',
code: `
<div>
<h1>Welcome {userName}</h1>
<p>Time to learn React!</p>
</div>`,
},
props: {
title: 'Props',
description:
'Components accept arbitrary inputs called props. They are like function arguments.',
code: `
function Welcome(props) {
return <h1>Hello, {props.name}</h1>;
}`,
},
state: {
title: 'State',
description:
'State allows React components to change their output over time in response to user actions, network responses, and anything else.',
code: `
function Counter() {
const [isVisible, setIsVisible] = useState(false);
function handleClick() {
setIsVisible(true);
}
return (
<div>
<button onClick={handleClick}>Show Details</button>
{isVisible && <p>Amazing details!</p>}
</div>
);
}`,
},
};
Loading

0 comments on commit 0e67198

Please sign in to comment.