Skip to content

Commit

Permalink
Style Shop page
Browse files Browse the repository at this point in the history
  • Loading branch information
thatblindgeye committed Jul 23, 2021
1 parent b93a5f9 commit 1ae7972
Show file tree
Hide file tree
Showing 19 changed files with 277 additions and 120 deletions.
71 changes: 38 additions & 33 deletions src/App.js
Original file line number Diff line number Diff line change
@@ -1,47 +1,52 @@
import React, { useState, useEffect } from 'react';
import React, { useState, useEffect, useRef } from 'react';
import { CartDataContextProvider } from './context/CartDataContext';
import Accessibility from './components/Accessibility/Accessibility';
import HeaderNavbar from './components/Navbar/HeaderNavbar';
import Router from './components/Router/Router';
import Footer from './components/Footer/Footer';

export default function App() {
const [theme, setTheme] = useState('dark');
const [theme, setTheme] = useState('dark');
const topOfPage = useRef(null);

// Initialize theme from local storage or set theme in local storage
// when App mounts
useEffect(() => {
let savedTheme = localStorage.getItem('theme');
// Initialize theme from local storage or set theme in local storage
// when App mounts
useEffect(() => {
let savedTheme = localStorage.getItem('theme');

if (!localStorage.getItem('theme')) {
savedTheme = 'dark';
localStorage.setItem('theme', savedTheme);
}
setTheme(savedTheme);
}, []);
if (!localStorage.getItem('theme')) {
savedTheme = 'dark';
localStorage.setItem('theme', savedTheme);
}
setTheme(savedTheme);
}, []);

useEffect(() => {
document.documentElement.className = theme;
}, [theme]);
useEffect(() => {
document.documentElement.className = theme;
}, [theme]);

const handleThemeToggle = (e) => {
if (e.type === 'click' || e.key === ' ' || e.key === 'Enter') {
e.preventDefault();
const newTheme = theme === 'dark' ? 'light' : 'dark';
const handleThemeToggle = (e) => {
if (e.type === 'click' || e.key === ' ' || e.key === 'Enter') {
e.preventDefault();
const newTheme = theme === 'dark' ? 'light' : 'dark';

setTheme(newTheme);
localStorage.setItem('theme', newTheme);
}
};
setTheme(newTheme);
localStorage.setItem('theme', newTheme);
}
};

return (
<CartDataContextProvider>
<header>
<Accessibility siteTheme={theme} toggleEvent={handleThemeToggle} />
<HeaderNavbar />
</header>
<Router />
<Footer siteTheme={theme} />
</CartDataContextProvider>
);
return (
<CartDataContextProvider>
<header>
<Accessibility
siteTheme={theme}
toggleEvent={handleThemeToggle}
topRef={topOfPage}
/>
<HeaderNavbar />
</header>
<Router />
<Footer siteTheme={theme} topRef={topOfPage} />
</CartDataContextProvider>
);
}
4 changes: 2 additions & 2 deletions src/components/Accessibility/Accessibility.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ import React from 'react';
import { ReactComponent as LightThemeIcon } from '../../assets/images/icons/light_theme.svg';
import { ReactComponent as DarkThemeIcon } from '../../assets/images/icons/dark_theme.svg';

export default function Accessibility({ siteTheme, toggleEvent }) {
export default function Accessibility({ siteTheme, toggleEvent, topRef }) {
const iconClasses = 'theme-icon';

return (
<div className='accessibility-container'>
<a href='#main' className='skip-link'>
<a href='#main' className='skip-link' ref={topRef}>
Skip to Content
</a>
<div
Expand Down
46 changes: 33 additions & 13 deletions src/components/Cards/ItemCard.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,48 @@
import React from 'react';
import { Link } from 'react-router-dom';
import ItemICardmage from './ItemICardmage';

const StockWarning = ({ children }) => {
return <div id='stock-warning'>{children}</div>;
const StockWarning = ({ stock, id }) => {
return (
<div id={`stock-warning-${id}`} className='item-stock-warning'>
{stock === 0
? 'Sold Out'
: stock < 20
? `Only ${stock} left`
: null}
</div>
);
};

export default function ItemCard({ item }) {
const { id, name, stock } = item;
const { id, name, image, price, stock } = item;
return (
<div>
<h2>
<div className='item-card'>
<div className='primary-preview-container'>
<Link
to={`/shop/${id}`}
className='preview-image-link'
aria-hidden='true'
tabIndex='-1'
>
<ItemICardmage image={image} />
</Link>
</div>
<div className='secondary-preview-container'>
<Link
to={`/shop/${id}`}
className='link'
aria-describedby={stock < 10 ? 'stock-warning' : null}
className='item-link'
aria-describedby={`price-${id} ${
stock < 10 ? `stock-warning-${id}` : null
}`}
>
{name}
</Link>
</h2>
{!stock ? (
<StockWarning>Sold Out</StockWarning>
) : stock < 10 ? (
<StockWarning>Only {stock} left!</StockWarning>
) : null}
<div id={`price-${id}`} className='item-price'>
${price}
</div>
{stock < 10 ? <StockWarning stock={stock} id={id} /> : null}
</div>
</div>
);
}
19 changes: 19 additions & 0 deletions src/components/Cards/ItemICardmage.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import React from 'react';

function ImageUnavailable() {
return (
<div className='image-unavailable elevation-04dp'>
Image
<br />
Unavailable
</div>
);
}

export default function ItemImage({ image }) {
return (
<div className='preview-image'>
{image ? <img src={image} alt='' /> : <ImageUnavailable />}
</div>
);
}
12 changes: 8 additions & 4 deletions src/components/Footer/Footer.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,21 @@ import React from 'react';
import githubDark from '../../assets/images/logos/GitHub-White-Mark-32px.png';
import githubLight from '../../assets/images/logos/GitHub-Black-Mark-32px.png';

export default function Footer({ siteTheme }) {
export default function Footer({ siteTheme, topRef }) {
const githubLogo = siteTheme === 'light' ? githubLight : githubDark;

const handleClick = () => {
window.scrollTo(0, 0);
const handleScrollToTop = () => {
window.scrollTo({
top: 0,
});

topRef.current.focus();
};

return (
<footer>
<div className='upper-footer-nav'>
<button className='button-text' onClick={handleClick}>
<button className='button-text' onClick={handleScrollToTop}>
Back to Top
</button>
</div>
Expand Down
29 changes: 17 additions & 12 deletions src/components/Navbar/HeaderNavbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,23 @@ export default function HeaderNavbar() {
<Link to='/' className='logo-link'>
Enbious
</Link>
<Link to='/shop' className='nav-link shop-link'>
Shop
</Link>

<Link
to='/cart'
className='nav-link cart-link'
aria-label='Shopping cart'
>
<CartIcon className='cart-icon' />
<span className='current-cart-amount'>{totalCartItems}</span>
</Link>
<div className='header-nav-right'>
<Link to='/shop' className='nav-link shop-link'>
Shop
</Link>
<div className='cart-button-container'>
<Link
to='/cart'
className='nav-link cart-link'
aria-label='Shopping cart'
>
<CartIcon className='cart-icon' />
<span className='current-cart-amount'>
{totalCartItems}
</span>
</Link>
</div>
</div>
</nav>
);
}
2 changes: 1 addition & 1 deletion src/components/Pages/Shop.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export default function Shop() {
}, []);

return (
<div>
<div className='items-container'>
{items.map((item) => (
<ItemCard key={item.id} item={item} />
))}
Expand Down
68 changes: 42 additions & 26 deletions src/inventory.json
Original file line number Diff line number Diff line change
@@ -1,28 +1,44 @@
{
"clothing": [
{
"id": 0,
"name": "T-Shirt",
"description": "Short sleeve.",
"image": null,
"price": 19.99,
"stock": 7
},
{
"id": 1,
"name": "Sweater",
"description": "Comfy.",
"image": null,
"price": 19.99,
"stock": 2
},
{
"id": 2,
"name": "Pants",
"description": "Denim.",
"image": null,
"price": 19.99,
"stock": 100
}
]
"clothing": [
{
"id": 0,
"name": "T-Shirt",
"description": "Short sleeve.",
"image": null,
"price": 19.99,
"stock": 7
},
{
"id": 1,
"name": "Sweater",
"description": "Comfy.",
"image": null,
"price": 19.99,
"stock": 0
},
{
"id": 2,
"name": "Pants",
"description": "Denim.",
"image": null,
"price": 19.99,
"stock": 100
},
{
"id": 3,
"name": "Shoes",
"description": "For walking.",
"image": null,
"price": 19.99,
"stock": 100
},
{
"id": 4,
"name": "Socks",
"description": "Well that socks.",
"image": null,
"price": 19.99,
"stock": 100
}
]
}
8 changes: 6 additions & 2 deletions src/styles/base/_base.scss
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ body {

main {
min-height: 100vh;
padding: 25px;
padding: 50px 25px;

@include breakpoint-at-least(large) {
padding: 25px 10vw;
padding: 50px 10vw;
}
}

Expand All @@ -43,6 +43,10 @@ h6 {
margin: 0;
}

a {
text-decoration: none;
}

%clickable {
&:hover {
cursor: pointer;
Expand Down
26 changes: 18 additions & 8 deletions src/styles/base/_typography.scss
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,11 @@ body {

.logo-link {
font-family: $brand-fonts;
font-size: 3rem;

@include breakpoint-at-least(medium) {
font-size: 5rem;
}
font-size: clamp(1rem, 10vw, 5rem);
}

.nav-link {
@include breakpoint-at-least(medium) {
font-size: 1.5rem;
}
font-size: clamp(1rem, 2vw, 1.5rem);
}

.image-card-text {
Expand All @@ -28,3 +22,19 @@ body {
font-size: 4rem;
}
}

.image-unavailable {
font-size: clamp(0.75rem, 5vw, 1.125rem);
text-align: center;
}

.item-link {
@include breakpoint-at-least(x-large) {
font-size: 1.5rem;
}
}

.item-stock-warning {
color: var(--color-text-item-warning);
font-size: 0.9rem;
}
4 changes: 4 additions & 0 deletions src/styles/components/_header.scss
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ header {
width: var(--base-size);

@include breakpoint-at-least(medium) {
--base-size: 1.5rem;
}

@include breakpoint-at-least(large) {
--base-size: 2rem;
}
}
Loading

0 comments on commit 1ae7972

Please sign in to comment.