From 3456bf254fd941e96c7190c6e2e9e6da89d6fecf Mon Sep 17 00:00:00 2001 From: andr-ew Date: Fri, 21 Jul 2023 21:28:49 -0500 Subject: [PATCH] home: style product grid items --- app/(home)/styles.module.scss | 1 + components/home/index.js | 17 ++++---- components/home/styles.module.scss | 10 +++++ components/{price.js => price/index.js} | 55 +++++++++++++------------ components/product/purchase-input.js | 2 +- styles/_typography.scss | 2 + 6 files changed, 52 insertions(+), 35 deletions(-) rename components/{price.js => price/index.js} (90%) diff --git a/app/(home)/styles.module.scss b/app/(home)/styles.module.scss index 6326b3347..ad95522f8 100644 --- a/app/(home)/styles.module.scss +++ b/app/(home)/styles.module.scss @@ -1,3 +1,4 @@ .main { padding: 0 60px; + padding-bottom: 364px; } diff --git a/components/home/index.js b/components/home/index.js index 2e4801ba1..a5cad7c39 100644 --- a/components/home/index.js +++ b/components/home/index.js @@ -5,8 +5,8 @@ import Image from 'next/image'; import { getCollectionProducts, getMenu } from 'lib/shopify'; -import { PriceRanges } from '/components/price.js'; import styles from './styles.module.scss'; +import { PriceRanges } from '/components/price'; export async function HomeProduct({ product }) { const typesMenu = await getMenu('types-nav'); @@ -17,23 +17,26 @@ export async function HomeProduct({ product }) { ?.map(col => col?.title) ?.filter(col => types?.includes(col?.toLowerCase())); - console.log({ collections }); - return ( + {/* TODO: optimize srcset (adjusting based on featured status) */} {featuredImage?.altText} -

{product?.title}

- {collections && collections.length > 0 && ( -

{`(${collections.join(', ')})`}

- )} +
+

{product?.title}

+ {collections && collections.length > 0 && ( +

{`(${collections.join( + ', ' + )})`}

+ )} +
); diff --git a/components/home/styles.module.scss b/components/home/styles.module.scss index 4069c28b7..bef4daaa5 100644 --- a/components/home/styles.module.scss +++ b/components/home/styles.module.scss @@ -56,4 +56,14 @@ } .homeProduct { + text-decoration-line: none; + + display: flex; + flex-direction: column; + gap: 10px; + + .title, + .collections { + @include typography.subheader; + } } diff --git a/components/price.js b/components/price/index.js similarity index 90% rename from components/price.js rename to components/price/index.js index 152ac68b9..10ec2739a 100644 --- a/components/price.js +++ b/components/price/index.js @@ -1,23 +1,5 @@ -export const formatPrice = ({ amount, currencyCode }) => { - const USDollar = new Intl.NumberFormat('en-US', { - style: 'currency', - currency: currencyCode, - }); +import styles from './styles.module.scss'; - return USDollar.format(amount); -}; - -export const formatPriceRange = ({ maxVariantPrice, minVariantPrice }) => { - if (maxVariantPrice.amount == minVariantPrice.amount) { - return `${formatPrice(maxVariantPrice)}`; - } else { - return `${formatPrice(minVariantPrice)} - ${formatPrice( - maxVariantPrice - )}`; - } -}; - -//TODO: might be safer not to destructure keys from `product`, use nullish coalescing instead export const productAvailableForSale = product => product?.availableForSale ?? false; export const productOnSale = product => @@ -29,6 +11,28 @@ export const productIsForSale = product => (product?.priceRange?.maxVariantPrice?.amount ?? 0) > 0; export const productHasOptions = product => product?.options?.[0]?.values?.length > 1 ?? false; +export const variantAvailableForSale = variant => + variant?.availableForSale ?? false; +export const variantOnSale = variant => + (variant?.compareAtPrice?.amount ?? 0) > (variant?.price?.amount ?? 0); + +export const formatPrice = ({ amount, currencyCode }) => { + const USDollar = new Intl.NumberFormat('en-US', { + style: 'currency', + currency: currencyCode, + }); + + return USDollar.format(amount); +}; +export const formatPriceRange = ({ maxVariantPrice, minVariantPrice }) => { + if (maxVariantPrice.amount == minVariantPrice.amount) { + return `${formatPrice(maxVariantPrice)}`; + } else { + return `${formatPrice(minVariantPrice)} - ${formatPrice( + maxVariantPrice + )}`; + } +}; export const PriceRanges = ({ product }) => { const availableForSale = productAvailableForSale(product); @@ -36,20 +40,22 @@ export const PriceRanges = ({ product }) => { const isForSale = productIsForSale(product); return ( -

+

{availableForSale ? ( isForSale && ( <> <> {onSale && ( - + {formatPriceRange( product?.compareAtPriceRange )}{' '} )} - {formatPriceRange(product?.priceRange)} + {`${formatPriceRange(product?.priceRange)} ${ + product?.priceRange?.maxVariantPrice?.currencyCode + }`} ) ) : ( @@ -59,11 +65,6 @@ export const PriceRanges = ({ product }) => { ); }; -export const variantAvailableForSale = variant => - variant?.availableForSale ?? false; -export const variantOnSale = variant => - (variant?.compareAtPrice?.amount ?? 0) > (variant?.price?.amount ?? 0); - export const VariantPrice = ({ variant, quantity }) => { const availableForSale = variantAvailableForSale(variant); const onSale = variantOnSale(variant); diff --git a/components/product/purchase-input.js b/components/product/purchase-input.js index 1d007ce83..8eddb518d 100644 --- a/components/product/purchase-input.js +++ b/components/product/purchase-input.js @@ -9,7 +9,7 @@ import { productHasOptions, productIsForSale, VariantPrice, -} from '/components/price.js'; +} from '/components/price'; export const productVariant = ({ product, selectedOptions }) => { const hasOptions = productHasOptions(product); diff --git a/styles/_typography.scss b/styles/_typography.scss index 5d626ffa3..cfcb5a16c 100644 --- a/styles/_typography.scss +++ b/styles/_typography.scss @@ -26,6 +26,8 @@ font-weight: 400; line-height: 20px; /* 100% */ text-transform: uppercase; + font-variant-numeric: lining-nums tabular-nums slashed-zero; + font-feature-settings: 'case' on; } @mixin body {