Skip to content

Commit

Permalink
feat(#14.3) create IconButton component and render in Layout.jsx. Use…
Browse files Browse the repository at this point in the history
… Layout.jsx css.
  • Loading branch information
dterceroparker committed Sep 26, 2024
1 parent 8040f53 commit 919d09c
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 3 deletions.
8 changes: 6 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!DOCTYPE html>
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
Expand All @@ -12,8 +12,12 @@
/>
<link rel="icon" type="image/svg+xml" href="/src/favicon.ico" />
<meta name="color-scheme" content="dark light" />
<title>Smart Shopping List</title>
<title>CollabShop</title>
<script type="module" src="/src/index.jsx" async></script>
<script
src="https://kit.fontawesome.com/06840d40e8.js"
crossorigin="anonymous"
></script>
</head>
<body>
<div id="root"></div>
Expand Down
21 changes: 21 additions & 0 deletions src/components/IconButton.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { useState } from 'react';
import { useNavigate } from 'react-router-dom';
import '../views/Layout.css';

export function IconButton({ icon, label, link }) {
const navigate = useNavigate();
const [clicked, setClicked] = useState(false);

const handleClick = () => {
// e.preventDefault();
navigate(link);
setClicked(true);
};

return (
<button onClick={handleClick} className={clicked ? 'clicked-link' : ''}>
{icon && <i className={icon}></i>} <br />
{label && <span>{label}</span>}
</button>
);
}
6 changes: 6 additions & 0 deletions src/views/Layout.css
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,13 @@
text-underline-offset: 0.1em;
}

/* .Nav-link.active {
text-decoration-thickness: 0.22em;
text-underline-offset: 0.1em;
} */

.Nav-link.active {
text-decoration-thickness: 0.22em;
text-underline-offset: 0.1em;
background-color: green;
}
5 changes: 4 additions & 1 deletion src/views/Layout.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { NavLink, Outlet } from 'react-router-dom';

import { IconButton } from '../components/IconButton';
import './Layout.css';
import { auth } from '../api/config.js';
import { useAuth, SignInButton, SignOutButton } from '../api/useAuth.jsx';
Expand Down Expand Up @@ -33,6 +33,9 @@ export function Layout() {
</main>
<nav className="Nav">
<div className="Nav-container">
<NavLink to="/list" className="Nav-link" end>
<IconButton icon="fa-solid fa-right-to-bracket" label="Login" />
</NavLink>
<NavLink to="/" className="Nav-link" end>
Home
</NavLink>
Expand Down

0 comments on commit 919d09c

Please sign in to comment.