Skip to content

Commit

Permalink
Merge pull request #35 from the-collab-lab/nr-dtp-iconbutton
Browse files Browse the repository at this point in the history
Issue #14.3:  Create <IconButton> Component
  • Loading branch information
dterceroparker authored Sep 28, 2024
2 parents 8040f53 + ea081ad commit a3596ce
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 18 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
5 changes: 3 additions & 2 deletions src/api/useAuth.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ export const SignInButton = () => (
/**
* A button that signs the user out of the app using Firebase Auth.
*/
export const SignOutButton = () => (
<button type="button" onClick={() => auth.signOut()}>
export const SignOutButton = ({ className }) => (
<button className={className} type="button" onClick={() => auth.signOut()}>
<i className="fa-solid fa-right-from-bracket"></i> <br />
Sign Out
</button>
);
Expand Down
15 changes: 15 additions & 0 deletions src/components/IconButton.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import '../views/Layout.css';

export function IconButton({
as: Component = 'button',
icon,
label,
...props
}) {
return (
<Component {...props}>
{icon && <i className={icon}></i>} <br />
{label && <span>{label}</span>}
</Component>
);
}
4 changes: 3 additions & 1 deletion src/views/Layout.css
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@

.Nav-link {
--color-text: var(--color-accent);

background: none;
border: none;
color: var(--color-text);
font-size: 1.4em;
flex: 0 1 auto;
Expand All @@ -70,4 +71,5 @@
.Nav-link.active {
text-decoration-thickness: 0.22em;
text-underline-offset: 0.1em;
background-color: var(--color-border);
}
36 changes: 23 additions & 13 deletions 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 { Outlet, NavLink } 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 All @@ -21,8 +21,7 @@ export function Layout() {
<h1>Smart shopping list</h1>
{!!user ? (
<div>
<span>Signed in as {auth.currentUser.displayName}</span> (
<SignOutButton />)
<span>Signed in as {auth.currentUser.displayName}</span>
</div>
) : (
<SignInButton />
Expand All @@ -33,15 +32,26 @@ export function Layout() {
</main>
<nav className="Nav">
<div className="Nav-container">
<NavLink to="/" className="Nav-link" end>
Home
</NavLink>
<NavLink to="/list" className="Nav-link" end>
List
</NavLink>
<NavLink to="/manage-list" className="Nav-link" end>
Manage List
</NavLink>
<IconButton
as={NavLink}
className="Nav-link"
icon="fa-solid fa-list"
label="View Lists"
to="/"
/>
<IconButton
as={NavLink}
className="Nav-link"
icon="fa-solid fa-cart-plus"
label="Add Item"
to="/manage-list"
/>
<IconButton
as={SignOutButton}
className="Nav-link"
icon="fa-solid fa-right-from-bracket"
label="Sign Out"
/>
</div>
</nav>
</div>
Expand Down

0 comments on commit a3596ce

Please sign in to comment.