Skip to content

Commit

Permalink
Finished React Essentials page.
Browse files Browse the repository at this point in the history
  • Loading branch information
carla-ng committed May 30, 2024
1 parent 4b049dc commit 80d99d7
Show file tree
Hide file tree
Showing 13 changed files with 286 additions and 206 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
182 changes: 182 additions & 0 deletions react-practice/main-project/dist/assets/index-CzZrerdo.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions react-practice/main-project/dist/assets/index-DMJ6CBjR.css

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion react-practice/main-project/dist/assets/index-MSsnV_1a.css

This file was deleted.

158 changes: 0 additions & 158 deletions react-practice/main-project/dist/assets/index-twLWV84w.js

This file was deleted.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions react-practice/main-project/dist/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>React Practice</title>
<script type="module" crossorigin src="/assets/index-twLWV84w.js"></script>
<link rel="stylesheet" crossorigin href="/assets/index-MSsnV_1a.css">
<script type="module" crossorigin src="/assets/index-CzZrerdo.js"></script>
<link rel="stylesheet" crossorigin href="/assets/index-DMJ6CBjR.css">
</head>
<body>
<div id="root"></div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@

const ReactEssentialsTabButton = ({ children, onSelect }) => {
const ReactEssentialsTabButton = ({ children, onSelect, isSelected }) => {

return (
<li>
<button onClick={onSelect}>{children}</button>
<button className={ isSelected ? 'active' : undefined } onClick={onSelect}>{children}</button>
</li>
)
}
Expand Down
101 changes: 76 additions & 25 deletions react-practice/main-project/src/ReactEssentials/data/data.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,79 @@ 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.',
},
];
{
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>
);
}`,
},
};
Original file line number Diff line number Diff line change
@@ -1,18 +1,29 @@
import '../css/ReactEssentials.css'
import { CORE_CONCEPTS } from '../data/data.js'
import { CORE_CONCEPTS, EXAMPLES } from '../data/data.js'

/*import { useState } from 'react' */
import { useState } from 'react'

import ReactEssentialsHeader from '../components/ReactEssentialsHeader.jsx'
import ReactEssentialsCoreConcept from '../components/ReactEssentialsCoreConcept.jsx'
import ReactEssentialsTabButton from '../components/ReactEssentialsTabButton.jsx'

function ReactEssentialsPage() {
let currentTabContent = ''
const [selectedTopic, setSelectedTopic] = useState()

const handleSelect = ( selectedButton ) => {
console.log(selectedButton)
currentTabContent = selectedButton
setSelectedTopic(selectedButton)
}

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

if ( selectedTopic ) {
tabContent = (
<div id="tab-content">
<h3>{ EXAMPLES[selectedTopic].title }</h3>
<p>{ EXAMPLES[selectedTopic].description }</p>
<code>{ EXAMPLES[selectedTopic].code }</code>
</div>
)
}

return (
Expand All @@ -22,26 +33,20 @@ function ReactEssentialsPage() {
<section id="core-concepts">
<h2>Core Concepts</h2>
<ul>
<ReactEssentialsCoreConcept
title={CORE_CONCEPTS[0].title}
description={CORE_CONCEPTS[0].description}
image={CORE_CONCEPTS[0].image}
/>
<ReactEssentialsCoreConcept { ...CORE_CONCEPTS[1] } />
<ReactEssentialsCoreConcept { ...CORE_CONCEPTS[2] } />
<ReactEssentialsCoreConcept { ...CORE_CONCEPTS[3] } />
{CORE_CONCEPTS.map(concept => <ReactEssentialsCoreConcept key={concept.title} { ...concept } />)}
</ul>
</section>

<section id="examples">
<h2>Examples</h2>
<menu>
<ReactEssentialsTabButton onSelect={() => handleSelect('components')}>Components</ReactEssentialsTabButton>
<ReactEssentialsTabButton onSelect={() => handleSelect('jsx')}>JSX</ReactEssentialsTabButton>
<ReactEssentialsTabButton onSelect={() => handleSelect('props')}>Props</ReactEssentialsTabButton>
<ReactEssentialsTabButton onSelect={() => handleSelect('state')}>State</ReactEssentialsTabButton>
<ReactEssentialsTabButton isSelected={selectedTopic === 'components'} onSelect={() => handleSelect('components')}>Components</ReactEssentialsTabButton>
<ReactEssentialsTabButton isSelected={selectedTopic === 'jsx'} onSelect={() => handleSelect('jsx')}>JSX</ReactEssentialsTabButton>
<ReactEssentialsTabButton isSelected={selectedTopic === 'props'} onSelect={() => handleSelect('props')}>Props</ReactEssentialsTabButton>
<ReactEssentialsTabButton isSelected={selectedTopic === 'state'} onSelect={() => handleSelect('state')}>State</ReactEssentialsTabButton>
</menu>
{ currentTabContent }

{ tabContent }
</section>
</main>
</div>
Expand Down

0 comments on commit 80d99d7

Please sign in to comment.