Skip to content

Commit 0d6807d

Browse files
committed
CSS Styling & Dynamic Styling
1 parent 4d2dc25 commit 0d6807d

File tree

2 files changed

+26
-6
lines changed

2 files changed

+26
-6
lines changed

src/App.jsx

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,30 @@ function App() {
4848
<section id="examples">
4949
<h2>Examples</h2>
5050
<menu>
51-
<TabButton onSelect={() => handleSelect('components')}>
51+
<TabButton
52+
isSelected={selectedTopic === 'components'}
53+
onSelect={() => handleSelect('components')}
54+
>
5255
Components
5356
</TabButton>
54-
<TabButton onSelect={() => handleSelect('jsx')}>JSX</TabButton>
55-
<TabButton onSelect={() => handleSelect('props')}>Props</TabButton>
56-
<TabButton onSelect={() => handleSelect('state')}>State</TabButton>
57+
<TabButton
58+
isSelected={selectedTopic === 'jsx'}
59+
onSelect={() => handleSelect('jsx')}
60+
>
61+
JSX
62+
</TabButton>
63+
<TabButton
64+
isSelected={selectedTopic === 'props'}
65+
onSelect={() => handleSelect('props')}
66+
>
67+
Props
68+
</TabButton>
69+
<TabButton
70+
isSelected={selectedTopic === 'state'}
71+
onSelect={() => handleSelect('state')}
72+
>
73+
State
74+
</TabButton>
5775
</menu>
5876
{tabContent}
5977
</section>

src/components/TabButton.jsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
export default function TabButton({ children, onSelect }) {
1+
export default function TabButton({ children, onSelect, isSelected }) {
22
return (
33
<li>
4-
<button onClick={onSelect}>{children}</button>
4+
<button className={isSelected ? 'active' : undefined} onClick={onSelect}>
5+
{children}
6+
</button>
57
</li>
68
);
79
}

0 commit comments

Comments
 (0)