Product Grid 2
Quick-add storefront grid: each product stands on its own lit studio stage (second photo on hover, colour swatches,
Use it in a prompt
Use offer/product-grid-2 from the FunnelDNA library. Follow the skill and theme contract. Ask me for the copy, images, and brand details you need; do not invent proof.
Paste into Claude or ChatGPT with FunnelDNA connected (MCP setup), or alongside the skill.
Use it in code
- Save
component.tsx(Code tab) ascomponents/funneldna/offer/product-grid-2.tsx. - Import it and pass your copy and images (Props tab):
import { ProductGrid2 } from "@/components/funneldna/offer/product-grid-2"
It restyles from the theme tokens on any wrapper (Theme tab). The specimen source is a complete working example.
pieces/offer/product-grid-2/component.tsx 737 lines
// layout: product-stage
// Quick-add storefront grid: each product stands on its own lit studio stage (second photo on hover, colour swatches,
// a hang-tag price), and Quick add drops an inline size row under its row so the visitor picks a size and adds to cart.
import * as React from 'react'
import { AnimatePresence, motion, useReducedMotion } from 'motion/react'
import { AlertCircle, ChevronUp, Loader2, Plus, ShieldCheck, ShoppingCart, Star, X } from 'lucide-react'
export type ProductGrid2Swatch = {
id: string
label: string // colour name shown and read out, e.g. Moss
color: string // CSS colour of the chip (product data, not a theme colour)
image?: string // photo of this colour; replaces the product photo while picked
imagePosition?: string
hoverImage?: string
hoverImagePosition?: string
}
export type ProductGrid2Size = {
label: string
soldOut?: boolean // struck through and disabled in the size row
}
export type ProductGrid2Product = {
id: string // stable key
name: string
note?: React.ReactNode // one short feature note under the name
image?: string // product photo (slot item-n), shown at 3:4
imageAlt?: string
imagePosition?: string // object-position focal point for the photo
hoverImage?: string // second photo shown on hover and keyboard focus
hoverImageAlt?: string
hoverImagePosition?: string
price: string
compareAt?: string // regular price, struck on the tag; only when supplied
swatches?: ProductGrid2Swatch[]
sizes?: ProductGrid2Size[] // omit for products with no size choice
rating?: number // supplied average out of 5; omit when not supplied
reviewCount?: number | string
flag?: string // short true flag on the photo, e.g. New colour
href?: string // product page for the name and photo
soldOut?: boolean // disables Quick add
}
export type ProductGrid2Selection = {
product: ProductGrid2Product
size?: string
swatch?: ProductGrid2Swatch
}
export type ProductGrid2Copy = {
quickAdd: string
quickAddFor: string // {name}
close: string
closeFor: string // {name}
pickerLabel: string // {name}
sizeLegend: string
colourLabel: string
swatchGroup: string // {name}
sizeError: string
addError: string
addLabel: string
adding: string
soldOut: string
soldOutSize: string
priceLabel: string
wasLabel: string
nowLabel: string
ratingLabel: string // {rating}, {count}
ratingOnlyLabel: string // {rating}
reviews: string // {count}
save: string // {amount}: shown only when compareAt and price are both plain amounts in one currency
}
export type ProductGrid2Props = {
headline?: string
emphasis?: string // phrase inside the headline set in the accent colour
punch?: React.ReactNode[] // one-sentence lines beside the headline
punchWord?: React.ReactNode // the single-word line that lands the point
products?: ProductGrid2Product[]
note?: React.ReactNode // reassurance under the grid (the supplied guarantee)
copy?: Partial<ProductGrid2Copy>
onAdd?: (selection: ProductGrid2Selection) => void | Promise<unknown> // a returned promise shows loading; a rejection shows the inline error
onAction?: (selection: ProductGrid2Selection) => void | Promise<unknown> // alias, used only when onAdd is not set
state?: 'default' | 'hover' | 'active' | 'disabled' | 'error'
className?: string
}
const DEFAULT_COPY: ProductGrid2Copy = {
quickAdd: 'Quick add',
quickAddFor: 'Quick add {name}',
close: 'Close',
closeFor: 'Close size picker for {name}',
pickerLabel: 'Choose a size for {name}',
sizeLegend: 'Pick your size',
colourLabel: 'Colour',
swatchGroup: 'Colours for {name}',
sizeError: 'Pick your size first, then add it to your cart.',
addError: 'We couldn’t add this to your cart. Please try again.',
addLabel: 'Add to cart',
adding: 'Adding…',
soldOut: 'Sold out',
soldOutSize: 'sold out',
priceLabel: 'Price',
wasLabel: 'Regular price',
nowLabel: 'now',
ratingLabel: 'Rated {rating} out of 5 from {count} reviews',
ratingOnlyLabel: 'Rated {rating} out of 5',
reviews: '({count})',
save: 'Save {amount}',
}
const EASE = [0.2, 0.7, 0.2, 1] as const
const useIsoLayoutEffect = typeof window === 'undefined' ? React.useEffect : React.useLayoutEffect
export function ProductGrid2(props: ProductGrid2Props) {
const {
headline = 'Gear up for the trail in two taps',
emphasis = 'two taps',
punch = ['Pick your size right on the card.', 'Add it to your cart.'],
punchWord = 'Done.',
products = [],
note,
copy: copyProp,
onAdd,
onAction,
state = 'default',
className,
} = props
const copy: ProductGrid2Copy = { ...DEFAULT_COPY, ...copyProp }
const reduce = useReducedMotion() ?? false
const uid = React.useId()
const headId = uid + '-title'
const drawerId = uid + '-picker'
const errId = uid + '-error'
const demo: ProductGrid2Product | undefined = products[Math.min(1, products.length - 1)]
const demoId = demo ? demo.id : ''
const init = initialFor(state, demo)
const [openId, setOpenId] = React.useState<string | null>(init.open)
const [anchorId, setAnchorId] = React.useState<string | null>(init.open)
const [sizes, setSizes] = React.useState<Record<string, string>>(init.sizes)
const [picks, setPicks] = React.useState<Record<string, string>>({})
const [error, setError] = React.useState<'size' | 'add' | null>(init.error)
const [busy, setBusy] = React.useState(false)
const [caretX, setCaretX] = React.useState<number | null>(null)
const gridRef = React.useRef<HTMLUListElement | null>(null)
const panelRef = React.useRef<HTMLDivElement | null>(null)
const sizeRef = React.useRef<HTMLFieldSetElement | null>(null)
const cardRefs = React.useRef<Record<string, HTMLLIElement | null>>({})
const triggerRefs = React.useRef<Record<string, HTMLButtonElement | null>>({})
React.useEffect(() => {
const next = initialFor(state, demo)
setOpenId(next.open)
if (next.open) setAnchorId(next.open)
setSizes(next.sizes)
setError(next.error)
setBusy(false)
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [state, demoId])
const measure = React.useCallback(() => {
const card = openId ? cardRefs.current[openId] : null
const panel = panelRef.current
if (!card || !panel) return
const c = card.getBoundingClientRect()
const d = panel.getBoundingClientRect()
const x = c.left + c.width / 2 - d.left
setCaretX(Math.round(Math.min(Math.max(x, 28), d.width - 28)))
}, [openId])
useIsoLayoutEffect(() => {
measure()
}, [measure, products.length])
React.useEffect(() => {
if (!openId) return undefined
const grid = gridRef.current
if (grid && typeof ResizeObserver !== 'undefined') {
const ro = new ResizeObserver(() => measure())
ro.observe(grid)
return () => ro.disconnect()
}
window.addEventListener('resize', measure)
return () => window.removeEventListener('resize', measure)
}, [openId, measure])
function toggle(p: ProductGrid2Product) {
setError(null)
if (openId === p.id) {
setOpenId(null)
return
}
setOpenId(p.id)
setAnchorId(p.id)
}
function close() {
const id = openId
setOpenId(null)
setError(null)
if (id) triggerRefs.current[id]?.focus()
}
function pickSize(p: ProductGrid2Product, label: string) {
setSizes((s) => ({ ...s, [p.id]: label }))
if (error === 'size') setError(null)
}
function add(p: ProductGrid2Product) {
if (busy) return
const size = sizes[p.id]
if ((p.sizes?.length ?? 0) > 0 && !size) {
setError('size')
sizeRef.current?.querySelector<HTMLInputElement>('input:not(:disabled)')?.focus()
return
}
setError(null)
const handler = onAdd ?? onAction
if (!handler) return
const done = () => {
setOpenId(null)
triggerRefs.current[p.id]?.focus()
}
let result: void | Promise<unknown>
try {
result = handler({ product: p, size, swatch: currentSwatch(p, picks) })
} catch {
setError('add')
return
}
if (isThenable(result)) {
setBusy(true)
result.then(
() => {
setBusy(false)
done()
},
() => {
setBusy(false)
setError('add')
},
)
} else done()
}
function renderPanel(p: ProductGrid2Product) {
const sw = currentSwatch(p, picks)
const thumb = sw?.image ?? p.image
const thumbPos = sw?.image ? sw.imagePosition : p.imagePosition
const list = p.sizes ?? []
const picked = sizes[p.id]
const locked = list.length > 0 && !picked
return (
<motion.li
key='panel'
className='pq-slot'
initial={{ height: 0 }}
animate={{ height: 'auto' }}
exit={{ height: 0 }}
transition={{ duration: reduce ? 0 : 0.34, ease: EASE }}
>
<div className='pq-room'>
<div
ref={panelRef}
id={drawerId}
className='pq-drawer'
role='region'
aria-label={fill(copy.pickerLabel, { name: p.name })}
style={{ ['--caret-x' as string]: caretX === null ? '50%' : caretX + 'px' } as React.CSSProperties}
onKeyDown={(e) => {
if (e.key === 'Escape') close()
}}
>
<span className='pq-caret' aria-hidden='true' />
<div className='pq-sum'>
{thumb ? (
<img
className='pq-thumb'
src={thumb}
alt=''
width={64}
height={85}
style={thumbPos ? { objectPosition: thumbPos } : undefined}
/>
) : null}
<div className='pq-sum-text'>
<p className='pq-sum-name'>{p.name}</p>
{sw ? (
<p className='pq-sum-meta'>
{copy.colourLabel}: {sw.label}
</p>
) : null}
<p className='pq-sum-price'>
<span className='pq-sum-now'>{p.price}</span>
{p.compareAt ? (
<s className='pq-sum-was'>
<span className='pq-sr'>{copy.wasLabel} </span>
{p.compareAt}
</s>
) : null}
</p>
</div>
</div>
{list.length > 0 ? (
<fieldset
ref={sizeRef}
className={cls('pq-sizes', error === 'size' && 'is-error')}
aria-describedby={error === 'size' ? errId : undefined}
>
<legend className='pq-legend'>
{copy.sizeLegend}
{picked ? <span className='pq-legend-pick'> · {picked}</span> : null}
</legend>
<div className='pq-size-row'>
{list.map((s) => (
<label key={s.label} className='pq-size'>
<input
type='radio'
name={drawerId + '-size'}
value={s.label}
checked={picked === s.label}
disabled={s.soldOut}
onChange={() => pickSize(p, s.label)}
/>
<span className='pq-size-face'>
{s.label}
{s.soldOut ? <span className='pq-sr'>, {copy.soldOutSize}</span> : null}
</span>
</label>
))}
</div>
</fieldset>
) : null}
<button
type='button'
className='pq-add'
aria-disabled={locked || undefined}
aria-busy={busy || undefined}
aria-describedby={error ? errId : undefined}
onClick={() => add(p)}
>
{busy ? (
<Loader2 className='pq-spin' size={20} strokeWidth={2.5} aria-hidden='true' />
) : (
<ShoppingCart size={20} strokeWidth={2.5} aria-hidden='true' />
)}
<span>{busy ? copy.adding : copy.addLabel + ' · ' + p.price}</span>
</button>
{error ? (
<p id={errId} className='pq-err' role='alert'>
<AlertCircle size={18} strokeWidth={2.5} aria-hidden='true' />
{error === 'size' ? copy.sizeError : copy.addError}
</p>
) : null}
<button
type='button'
className='pq-close'
aria-label={fill(copy.closeFor, { name: p.name })}
onClick={close}
>
<X size={20} strokeWidth={2.5} aria-hidden='true' />
</button>
</div>
</div>
</motion.li>
)
}
const items: React.ReactNode[] = []
products.forEach((p, i) => {
const sw = currentSwatch(p, picks)
const photo = sw?.image ?? p.image
const photoPos = sw?.image ? sw.imagePosition : p.imagePosition
const second = sw?.image ? sw.hoverImage : p.hoverImage
const secondPos = sw?.image ? sw.hoverImagePosition : p.hoverImagePosition
const out = isSoldOut(p)
const open = openId === p.id
const flag = out ? copy.soldOut : p.flag
const save = p.compareAt ? savings(p.compareAt, p.price) : null
const media = (
<>
{photo ? (
<img
className='pq-photo pq-photo-1'
src={photo}
alt={p.imageAlt ?? p.name}
width={600}
height={800}
loading='lazy'
decoding='async'
style={photoPos ? { objectPosition: photoPos } : undefined}
/>
) : null}
{second ? (
<img
className='pq-photo pq-photo-2'
src={second}
alt={p.hoverImageAlt ?? ''}
width={600}
height={800}
loading='lazy'
decoding='async'
style={secondPos ? { objectPosition: secondPos } : undefined}
/>
) : null}
{flag ? <span className={cls('pq-flag', out && 'is-out')}>{flag}</span> : null}
</>
)
items.push(
<li
key={p.id}
ref={(el) => {
cardRefs.current[p.id] = el
}}
className={cls('pq-card', open && 'is-open', second && 'has-alt', state === 'hover' && i === 0 && 'is-hover')}
style={{ ['--i' as string]: i } as React.CSSProperties}
>
{p.href ? (
<a className='pq-frame' href={p.href} tabIndex={-1} aria-hidden='true'>
{media}
</a>
) : (
<div className='pq-frame'>{media}</div>
)}
<div className='pq-info'>
<h3 className='pq-name'>{p.href ? <a href={p.href}>{p.name}</a> : p.name}</h3>
{p.note ? <p className='pq-note'>{p.note}</p> : null}
{typeof p.rating === 'number' ? (
<p className='pq-rating'>
<span className='pq-sr'>
{p.reviewCount != null
? fill(copy.ratingLabel, { rating: p.rating, count: p.reviewCount })
: fill(copy.ratingOnlyLabel, { rating: p.rating })}
</span>
<Star className='pq-star' size={16} strokeWidth={2.5} fill='currentColor' aria-hidden='true' />
<span aria-hidden='true'>{p.rating.toFixed(1)}</span>
{p.reviewCount != null ? (
<span className='pq-count' aria-hidden='true'>
{fill(copy.reviews, { count: p.reviewCount })}
</span>
) : null}
</p>
) : null}
{p.swatches && p.swatches.length > 0 ? (
<div className='pq-swatches' role='group' aria-label={fill(copy.swatchGroup, { name: p.name })}>
{p.swatches.map((s) => (
<button
key={s.id}
type='button'
className='pq-swatch'
aria-pressed={sw?.id === s.id}
aria-label={s.label}
title={s.label}
onClick={() => setPicks((m) => ({ ...m, [p.id]: s.id }))}
>
<span className='pq-dot' style={{ background: s.color }} />
</button>
))}
{sw ? (
<span className='pq-colour' aria-hidden='true'>
{sw.label}
</span>
) : null}
</div>
) : null}
<p className='pq-price'>
<span className='pq-sr'>
{p.compareAt
? copy.wasLabel + ' ' + p.compareAt + ', ' + copy.nowLabel + ' ' + p.price
: copy.priceLabel + ' ' + p.price}
{save ? ', ' + fill(copy.save, { amount: save }) : null}
</span>
<span className='pq-now' aria-hidden='true'>
{p.price}
</span>
{p.compareAt ? (
<s className='pq-was' aria-hidden='true'>
{p.compareAt}
</s>
) : null}
{save ? (
<span className='pq-save' aria-hidden='true'>
{fill(copy.save, { amount: save })}
</span>
) : null}
</p>
</div>
<button
ref={(el) => {
triggerRefs.current[p.id] = el
}}
type='button'
className='pq-quick'
aria-expanded={out ? undefined : open}
aria-controls={open ? drawerId : undefined}
aria-label={out ? undefined : fill(open ? copy.closeFor : copy.quickAddFor, { name: p.name })}
disabled={out}
onClick={() => toggle(p)}
>
{out ? (
<span>{copy.soldOut}</span>
) : (
<>
{open ? (
<ChevronUp size={18} strokeWidth={2.5} aria-hidden='true' />
) : (
<Plus size={18} strokeWidth={2.5} aria-hidden='true' />
)}
<span>{open ? copy.close : copy.quickAdd}</span>
</>
)}
</button>
</li>,
)
if (p.id === anchorId) {
items.push(<AnimatePresence key='pq-drawer'>{openId === p.id ? renderPanel(p) : null}</AnimatePresence>)
}
})
return (
<section className={cls('cf-product-grid-2', className)} aria-labelledby={headId}>
<style>{CSS}</style>
<div className='pq-wrap'>
<div className='pq-head'>
<h2 id={headId} className='pq-title'>
{renderHeadline(headline, emphasis)}
</h2>
{punch.length > 0 || punchWord ? (
<div className='pq-punch'>
{punch.map((line, i) => (
<p key={i}>{line}</p>
))}
{punchWord ? <p className='pq-punch-word'>{punchWord}</p> : null}
</div>
) : null}
</div>
{products.length > 0 ? (
<ul ref={gridRef} className='pq-grid' role='list'>
{items}
</ul>
) : null}
{note ? (
<p className='pq-foot'>
<ShieldCheck size={18} strokeWidth={2.5} aria-hidden='true' />
{note}
</p>
) : null}
</div>
</section>
)
}
export default ProductGrid2
function initialFor(
state: ProductGrid2Props['state'],
demo: ProductGrid2Product | undefined,
): { open: string | null; sizes: Record<string, string>; error: 'size' | 'add' | null } {
const opens = state === 'active' || state === 'disabled' || state === 'error'
const open = demo && opens ? demo.id : null
const first = demo?.sizes?.find((s) => !s.soldOut)
return {
open,
sizes: state === 'active' && demo && first ? { [demo.id]: first.label } : {},
error: state === 'error' && demo && (demo.sizes?.length ?? 0) > 0 ? 'size' : null,
}
}
function currentSwatch(p: ProductGrid2Product, picks: Record<string, string>): ProductGrid2Swatch | undefined {
const list = p.swatches ?? []
return list.find((s) => s.id === picks[p.id]) ?? list[0]
}
function isSoldOut(p: ProductGrid2Product) {
return Boolean(p.soldOut) || (!!p.sizes && p.sizes.length > 0 && p.sizes.every((s) => s.soldOut))
}
function isThenable(v: unknown): v is PromiseLike<unknown> {
return typeof v === 'object' && v !== null && typeof (v as PromiseLike<unknown>).then === 'function'
}
// Savings derived only from the two supplied amounts; null when they can't be compared honestly.
function savings(was: string, now: string): string | null {
const a = money(was)
const b = money(now)
if (!a || !b || a.prefix !== b.prefix || a.value <= b.value) return null
const d = Math.round((a.value - b.value) * 100) / 100
return a.prefix + (Number.isInteger(d) ? String(d) : d.toFixed(2))
}
function money(t: string): { prefix: string; value: number } | null {
const m = /^\s*([^\d\s.,-]*)\s*([\d,]+(?:\.\d+)?)\s*$/.exec(t)
if (!m) return null
const value = Number(m[2].replace(/,/g, ''))
return Number.isFinite(value) ? { prefix: m[1], value } : null
}
function fill(t: string, vars: Record<string, string | number | undefined>) {
return Object.keys(vars).reduce((s, k) => s.split('{' + k + '}').join(String(vars[k] ?? '')), t)
}
function cls(...parts: Array<string | false | null | undefined>) {
return parts.filter(Boolean).join(' ')
}
function renderHeadline(text: string, em?: string): React.ReactNode {
if (!em) return text
const at = text.indexOf(em)
if (at < 0) return text
return (
<>
{text.slice(0, at)}
<span className='pq-em'>{em}</span>
{text.slice(at + em.length)}
</>
)
}
const CSS = `
.cf-product-grid-2{--pq-ink:var(--ink,#18202f);--pq-muted:var(--muted,#4b5565);--pq-card:var(--card,#ffffff);--pq-accent:var(--accent,#2f5fd0);--pq-btn:var(--button-bg,var(--cta,#d23a2a));--pq-btn-2:var(--button-bg-2,var(--cta-2,#b52e20));--pq-shadow:var(--shadow,oklch(0.22 0.03 260));--pq-line:oklch(from var(--pq-ink) l c h / 0.14);--pq-well:color-mix(in oklch,var(--pq-ink) 5%,var(--pq-card));--pq-ring:oklch(from var(--pq-accent) l c h / 0.55);--pq-ease:cubic-bezier(.2,.7,.2,1);position:relative;background:var(--surface,#ffffff);color:var(--pq-ink);font-family:var(--font-body,system-ui,sans-serif);padding:clamp(56px,8vw,112px) clamp(16px,5vw,48px) clamp(64px,8.5vw,120px);overflow-x:clip}
.cf-product-grid-2 *,.cf-product-grid-2 *::before,.cf-product-grid-2 *::after{box-sizing:border-box}
.cf-product-grid-2 .pq-wrap{max-width:1120px;margin:0 auto}
.cf-product-grid-2 .pq-head{display:grid;grid-template-columns:minmax(0,1.35fr) minmax(0,1fr);gap:16px clamp(32px,5vw,72px);align-items:start;margin-bottom:clamp(32px,4.5vw,56px)}
.cf-product-grid-2 .pq-title{margin:0;font-family:var(--font-display,system-ui,sans-serif);font-size:clamp(2rem,3.6vw,3.25rem);line-height:1.06;font-weight:var(--display-weight,800);letter-spacing:var(--display-tracking,-0.025em);text-transform:var(--display-case,none);text-wrap:balance;color:var(--pq-ink)}
.cf-product-grid-2 .pq-em{color:var(--pq-accent)}
.cf-product-grid-2 .pq-punch{padding-top:6px}
.cf-product-grid-2 .pq-punch p{margin:0;font-size:clamp(1.125rem,1.5vw,1.375rem);line-height:1.4;font-weight:500;color:var(--pq-ink);text-wrap:pretty}
.cf-product-grid-2 .pq-punch p+p{margin-top:4px}
.cf-product-grid-2 .pq-punch .pq-punch-word{margin-top:8px;font-family:var(--font-display,system-ui,sans-serif);font-size:clamp(1.75rem,2.6vw,2.25rem);line-height:1.06;font-weight:var(--display-weight,800);letter-spacing:var(--display-tracking,-0.025em)}
.cf-product-grid-2 .pq-grid{display:grid;grid-template-columns:repeat(4,minmax(0,1fr));grid-auto-flow:row dense;gap:clamp(28px,3vw,40px) clamp(14px,1.8vw,24px);margin:0;padding:0;list-style:none}
.cf-product-grid-2 .pq-card{position:relative;display:flex;flex-direction:column;min-width:0;animation:cf-pg2-rise .45s var(--pq-ease) both;animation-delay:calc(min(var(--i,0),4) * 0.07s)}
@keyframes cf-pg2-rise{from{opacity:.82;transform:translateY(8px)}to{opacity:1;transform:none}}
.cf-product-grid-2 .pq-frame{position:relative;display:block;aspect-ratio:3/4;border-radius:12px;overflow:hidden;background:var(--pq-well);color:inherit;isolation:isolate}
.cf-product-grid-2 .pq-photo{position:absolute;inset:0;display:block;width:100%;height:100%;object-fit:cover;object-position:50% 50%;transition:opacity .3s ease,transform .6s var(--pq-ease)}
.cf-product-grid-2 .pq-photo-2{opacity:0}
@media (hover:hover){
.cf-product-grid-2 .pq-card:hover .pq-photo-2{opacity:1}
.cf-product-grid-2 .pq-card:not(.has-alt):hover .pq-photo-1{transform:scale(1.04)}
.cf-product-grid-2 .pq-name a:hover{text-decoration:underline;text-decoration-thickness:2px;text-underline-offset:.18em}
}
.cf-product-grid-2 .pq-card.is-hover .pq-photo-2,.cf-product-grid-2 .pq-card:has(:focus-visible) .pq-photo-2{opacity:1}
.cf-product-grid-2 .pq-card.is-hover:not(.has-alt) .pq-photo-1{transform:scale(1.04)}
.cf-product-grid-2 .pq-card:has(.pq-name a:focus-visible) .pq-frame{outline:3px solid var(--pq-ring);outline-offset:3px}
.cf-product-grid-2 .pq-flag{position:absolute;top:10px;left:10px;z-index:2;display:inline-flex;align-items:center;min-height:28px;max-width:calc(100% - 20px);padding:4px 12px;border-radius:999px;background:var(--pq-card);color:var(--pq-ink);font-size:.875rem;font-weight:800;line-height:1.2;white-space:nowrap;box-shadow:var(--shadow-sm,0 1px 2px oklch(0.22 0.03 260 / 0.2))}
.cf-product-grid-2 .pq-flag.is-out{background:var(--pq-ink);color:var(--pq-card)}
.cf-product-grid-2 .pq-info{display:flex;flex-direction:column;align-items:flex-start;flex:1 1 auto;min-width:0;padding-top:16px}
.cf-product-grid-2 .pq-name{margin:0;font-family:var(--font-display,system-ui,sans-serif);font-size:1.125rem;line-height:1.25;font-weight:800;letter-spacing:-0.01em;color:var(--pq-ink);text-wrap:balance}
.cf-product-grid-2 .pq-name a{color:inherit;text-decoration:none;border-radius:4px}
.cf-product-grid-2 .pq-name a:focus-visible{outline:3px solid var(--pq-ring);outline-offset:2px}
.cf-product-grid-2 .pq-note{margin:4px 0 0;font-size:.9375rem;line-height:1.4;color:var(--pq-muted);text-wrap:pretty}
.cf-product-grid-2 .pq-rating{display:flex;align-items:center;gap:4px;margin:8px 0 0;font-size:.875rem;font-weight:800;line-height:1.2;color:var(--pq-ink)}
.cf-product-grid-2 .pq-star{flex:0 0 auto;color:var(--accent-fill,var(--pq-accent))}
.cf-product-grid-2 .pq-count{font-weight:600;color:var(--pq-muted)}
.cf-product-grid-2 .pq-swatches{display:flex;flex-wrap:wrap;align-items:center;gap:2px 4px;margin-top:8px}
.cf-product-grid-2 .pq-swatch{display:inline-grid;place-items:center;width:32px;height:32px;padding:0;border:0;border-radius:999px;background:transparent;cursor:pointer}
.cf-product-grid-2 .pq-dot{display:block;width:20px;height:20px;border-radius:999px;border:1px solid oklch(from var(--pq-ink) l c h / 0.22);outline:2px solid transparent;outline-offset:2px;transition:outline-color .16s ease}
.cf-product-grid-2 .pq-swatch:hover .pq-dot{outline-color:oklch(from var(--pq-ink) l c h / 0.3)}
.cf-product-grid-2 .pq-swatch[aria-pressed='true'] .pq-dot{outline-color:var(--pq-ink)}
.cf-product-grid-2 .pq-swatch:focus-visible{outline:3px solid var(--pq-ring);outline-offset:1px}
.cf-product-grid-2 .pq-colour{margin-left:4px;font-size:.875rem;font-weight:600;line-height:1.2;color:var(--pq-muted)}
.cf-product-grid-2 .pq-price{position:relative;display:flex;flex-wrap:wrap;align-items:baseline;gap:4px 10px;width:100%;margin:auto 0 0;padding-top:16px}
.cf-product-grid-2 .pq-now{font-family:var(--font-display,system-ui,sans-serif);font-size:clamp(1.3125rem,1.8vw,1.625rem);font-weight:var(--display-weight,800);line-height:1;letter-spacing:-0.03em;color:var(--pq-ink);font-variant-numeric:tabular-nums}
.cf-product-grid-2 .pq-was{font-size:.9375rem;font-weight:700;line-height:1.2;color:var(--pq-muted);text-decoration:line-through;text-decoration-color:var(--danger,#c0392b);text-decoration-thickness:2px;font-variant-numeric:tabular-nums}
.cf-product-grid-2 .pq-save{flex-basis:100%;font-size:.875rem;font-weight:800;line-height:1.2;color:var(--success,#1f7a45);font-variant-numeric:tabular-nums}
.cf-product-grid-2 .pq-quick{display:inline-flex;align-items:center;justify-content:center;gap:8px;width:100%;min-height:48px;margin-top:16px;padding:0 16px;border:1px solid var(--button-2-border,transparent);border-radius:var(--button-radius,var(--radius,12px));background:var(--button-2-bg,var(--secondary,#e8ebf1));color:var(--button-2-ink,var(--secondary-ink,#18202f));font-family:var(--button-font,var(--font-display,system-ui,sans-serif));font-size:1rem;font-weight:var(--button-weight,800);line-height:1.15;text-transform:var(--button-case,none);white-space:nowrap;box-shadow:var(--button-2-shadow,var(--shadow-sm,0 1px 2px oklch(0.22 0.03 260 / 0.2)));cursor:pointer;transition:background .16s ease,border-color .16s ease,transform .16s ease}
.cf-product-grid-2 .pq-quick:hover{background:oklch(from var(--button-2-bg,var(--secondary,#e8ebf1)) calc(l - 0.04) c h)}
.cf-product-grid-2 .pq-quick:active{transform:translateY(1px)}
.cf-product-grid-2 .pq-quick:focus-visible{outline:3px solid var(--pq-ring);outline-offset:2px}
.cf-product-grid-2 .pq-card.is-open .pq-quick{background:color-mix(in oklch,var(--pq-accent) 12%,var(--pq-card));border-color:var(--pq-accent);color:var(--pq-ink)}
.cf-product-grid-2 .pq-card.is-open .pq-quick:hover{background:color-mix(in oklch,var(--pq-accent) 18%,var(--pq-card))}
.cf-product-grid-2 .pq-quick:disabled,.cf-product-grid-2 .pq-quick:disabled:hover{background:color-mix(in oklch,var(--pq-ink) 4%,var(--pq-card));color:var(--pq-muted);box-shadow:none;transform:none;cursor:not-allowed}
.cf-product-grid-2 .pq-slot{grid-column:1/-1;min-width:0;margin:0 -12px;overflow:hidden}
.cf-product-grid-2 .pq-room{padding:14px 12px 18px}
.cf-product-grid-2 .pq-drawer{--pq-edge:color-mix(in oklch,var(--pq-accent) 38%,var(--pq-card));position:relative;display:grid;grid-template-columns:minmax(0,1fr) minmax(0,1.5fr) auto;grid-template-areas:'sum sizes add' '. err err';column-gap:clamp(20px,3vw,40px);row-gap:0;align-items:end;min-height:140px;padding:clamp(20px,2.6vw,28px);background:var(--pq-card);color:var(--pq-ink);border:1px solid var(--pq-edge);border-radius:var(--card-radius,var(--radius,14px));box-shadow:var(--card-shadow,var(--shadow-lg,0 2px 4px oklch(0.22 0.03 260 / 0.22),0 12px 24px -8px oklch(0.22 0.03 260 / 0.32)))}
.cf-product-grid-2 .pq-caret{position:absolute;top:-9px;left:var(--caret-x,50%);width:16px;height:16px;margin-left:-8px;background:var(--pq-card);border:1px solid var(--pq-edge);border-right-color:transparent;border-bottom-color:transparent;border-radius:4px 0 0 0;transform:rotate(45deg);transition:left .3s var(--pq-ease)}
.cf-product-grid-2 .pq-sum{grid-area:sum;display:flex;align-items:center;gap:16px;min-width:0}
.cf-product-grid-2 .pq-thumb{flex:0 0 auto;display:block;width:64px;height:auto;aspect-ratio:3/4;border-radius:8px;object-fit:cover;background:var(--pq-well)}
.cf-product-grid-2 .pq-sum-text{min-width:0}
.cf-product-grid-2 .pq-sum-name{margin:0;font-family:var(--font-display,system-ui,sans-serif);font-size:1.0625rem;font-weight:800;line-height:1.25;letter-spacing:-0.01em;text-wrap:balance}
.cf-product-grid-2 .pq-sum-meta{margin:4px 0 0;font-size:.9375rem;line-height:1.4;color:var(--pq-muted)}
.cf-product-grid-2 .pq-sum-price{display:flex;flex-wrap:wrap;align-items:baseline;gap:8px;margin:8px 0 0}
.cf-product-grid-2 .pq-sum-now{font-family:var(--font-display,system-ui,sans-serif);font-size:1.375rem;font-weight:800;line-height:1;letter-spacing:-0.02em;font-variant-numeric:tabular-nums}
.cf-product-grid-2 .pq-sum-was{font-size:.9375rem;font-weight:700;color:var(--pq-muted);text-decoration:line-through;text-decoration-color:var(--danger,#c0392b);text-decoration-thickness:2px;font-variant-numeric:tabular-nums}
.cf-product-grid-2 .pq-sizes{grid-area:sizes;min-width:0;margin:0;padding:0;border:0}
.cf-product-grid-2 .pq-legend{float:left;width:100%;margin:0 0 12px;padding:0;font-size:1rem;font-weight:700;line-height:1.2;color:var(--label-ink,var(--pq-ink))}
.cf-product-grid-2 .pq-legend-pick{font-weight:600;color:var(--pq-muted)}
.cf-product-grid-2 .pq-size-row{clear:both;display:flex;flex-wrap:wrap;gap:8px}
.cf-product-grid-2 .pq-size{position:relative;display:inline-flex}
.cf-product-grid-2 .pq-size input{position:absolute;inset:0;width:100%;height:100%;margin:0;opacity:0;cursor:pointer}
.cf-product-grid-2 .pq-size-face{display:inline-flex;align-items:center;justify-content:center;min-width:56px;min-height:48px;padding:0 14px;border-radius:var(--field-radius,var(--radius,12px));border:1px solid var(--field-border,color-mix(in oklch,var(--pq-ink) 22%,transparent));background:var(--field,#ffffff);color:var(--field-ink,var(--pq-ink));font-size:1.0625rem;font-weight:800;line-height:1;white-space:nowrap;font-variant-numeric:tabular-nums;pointer-events:none;transition:background .16s ease,border-color .16s ease,color .16s ease,transform .16s ease}
.cf-product-grid-2 .pq-size:hover input:not(:disabled)+.pq-size-face{border-color:var(--field-ink,var(--pq-ink))}
.cf-product-grid-2 .pq-size input:active:not(:disabled)+.pq-size-face{transform:translateY(1px)}
.cf-product-grid-2 .pq-sizes.is-error .pq-size input:not(:disabled):not(:checked)+.pq-size-face{border-color:var(--danger,#c0392b);box-shadow:inset 0 0 0 1px var(--danger,#c0392b)}
.cf-product-grid-2 .pq-size input:checked+.pq-size-face{background:var(--accent-fill,var(--pq-accent));border-color:var(--accent-fill,var(--pq-accent));color:var(--accent-fill-ink,var(--pq-card))}
.cf-product-grid-2 .pq-size input:focus-visible+.pq-size-face{outline:3px solid oklch(from var(--field-focus,var(--pq-accent)) l c h / 0.45);outline-offset:2px}
.cf-product-grid-2 .pq-size input:disabled{cursor:not-allowed}
.cf-product-grid-2 .pq-size input:disabled+.pq-size-face{background:color-mix(in oklch,var(--pq-ink) 4%,var(--pq-card));border-color:oklch(from var(--pq-ink) l c h / 0.1);color:var(--pq-muted);text-decoration:line-through;text-decoration-thickness:2px}
.cf-product-grid-2 .pq-add{grid-area:add;display:inline-flex;align-items:center;justify-content:center;gap:10px;min-width:240px;min-height:56px;padding:0 28px;border:0;border-radius:var(--button-radius,var(--radius,12px));background:linear-gradient(oklch(from var(--pq-btn) calc(l + 0.04) c h),oklch(from var(--pq-btn-2) calc(l - 0.02) c h));color:var(--button-ink,var(--cta-ink,#ffffff));font-family:var(--button-font,var(--font-display,system-ui,sans-serif));font-size:clamp(1.0625rem,1.3vw,1.1875rem);font-weight:var(--button-weight,800);line-height:1.15;text-transform:var(--button-case,none);text-shadow:var(--button-text-shadow,none);white-space:nowrap;cursor:pointer;box-shadow:var(--button-shadow,inset 0 1px 0 oklch(from var(--pq-btn) calc(l + 0.14) c h / 0.7),inset 0 -3px 0 oklch(from var(--pq-btn) calc(l - 0.16) c h),0 1px 2px oklch(from var(--pq-shadow) l c h / 0.3),0 8px 16px -6px oklch(from var(--pq-shadow) l c h / 0.45));transition:background .16s ease,box-shadow .16s ease,transform .16s ease}
.cf-product-grid-2 .pq-add:hover{background:linear-gradient(oklch(from var(--pq-btn) calc(l - 0.01) c h),oklch(from var(--pq-btn-2) calc(l - 0.07) c h));box-shadow:inset 0 1px 0 oklch(from var(--pq-btn) calc(l + 0.1) c h / 0.6),inset 0 -3px 0 oklch(from var(--pq-btn) calc(l - 0.2) c h),0 1px 2px oklch(from var(--pq-shadow) l c h / 0.32),0 10px 18px -6px oklch(from var(--pq-shadow) l c h / 0.5)}
.cf-product-grid-2 .pq-add:active{transform:translateY(1px);box-shadow:inset 0 2px 4px oklch(from var(--pq-btn-2) calc(l - 0.2) c h / 0.45),inset 0 -2px 0 oklch(from var(--pq-btn) calc(l - 0.16) c h),0 1px 1px oklch(from var(--pq-shadow) l c h / 0.3)}
.cf-product-grid-2 .pq-add:focus-visible{outline:3px solid var(--pq-ring);outline-offset:3px}
.cf-product-grid-2 .pq-add[aria-disabled='true'],.cf-product-grid-2 .pq-add[aria-disabled='true']:hover,.cf-product-grid-2 .pq-add[aria-disabled='true']:active{background:var(--button-2-bg,var(--secondary,#e8ebf1));color:var(--button-2-ink,var(--secondary-ink,#18202f));text-shadow:none;box-shadow:var(--button-2-shadow,var(--shadow-sm,0 1px 2px oklch(0.22 0.03 260 / 0.2)));transform:none;cursor:not-allowed}
.cf-product-grid-2 .pq-add[aria-busy='true']{cursor:progress}
.cf-product-grid-2 .pq-spin{animation:cf-pg2-spin .8s linear infinite}
@keyframes cf-pg2-spin{to{transform:rotate(360deg)}}
.cf-product-grid-2 .pq-err{grid-area:err;margin:12px 0 0;font-size:.9375rem;font-weight:600;line-height:1.4;color:var(--danger,#c0392b);text-wrap:pretty}
.cf-product-grid-2 .pq-err svg{display:inline-block;vertical-align:-0.2em;margin-inline-end:.4em}
.cf-product-grid-2 .pq-close{position:absolute;top:8px;right:8px;display:inline-grid;place-items:center;width:44px;height:44px;padding:0;border:0;border-radius:999px;background:transparent;color:var(--pq-muted);cursor:pointer;transition:background .16s ease,color .16s ease}
.cf-product-grid-2 .pq-close:hover{background:color-mix(in oklch,var(--pq-ink) 6%,var(--pq-card));color:var(--pq-ink)}
.cf-product-grid-2 .pq-close:focus-visible{outline:3px solid var(--pq-ring);outline-offset:1px}
.cf-product-grid-2 .pq-foot{margin:clamp(32px,4vw,48px) 0 0;font-size:.9375rem;font-weight:600;line-height:1.4;color:var(--pq-muted);text-wrap:pretty}
.cf-product-grid-2 .pq-foot svg{display:inline-block;vertical-align:-0.2em;margin-inline-end:.4em;color:var(--success,#1f7a45)}
.cf-product-grid-2 .pq-sr{position:absolute;width:1px;height:1px;padding:0;margin:-1px;overflow:hidden;clip:rect(0 0 0 0);white-space:nowrap;border:0}
@media (max-width:960px){
.cf-product-grid-2 .pq-drawer{grid-template-columns:minmax(0,1fr);grid-template-areas:'sum' 'sizes' 'err' 'add';align-items:stretch;min-height:0}
.cf-product-grid-2 .pq-sum{padding-right:48px}
.cf-product-grid-2 .pq-sizes{margin-top:20px}
.cf-product-grid-2 .pq-add{width:100%;min-width:0;margin-top:20px}
}
@media (max-width:760px){
.cf-product-grid-2 .pq-head{grid-template-columns:minmax(0,1fr);gap:16px}
.cf-product-grid-2 .pq-punch{padding-top:0}
.cf-product-grid-2 .pq-grid{grid-template-columns:repeat(2,minmax(0,1fr));gap:28px 12px}
.cf-product-grid-2 .pq-name{font-size:1.0625rem}
.cf-product-grid-2 .pq-thumb{width:56px}
.cf-product-grid-2 .pq-size-face{min-width:52px;padding:0 12px}
}
@media (prefers-reduced-motion:reduce){
.cf-product-grid-2 .pq-card{animation:none}
.cf-product-grid-2 .pq-photo,.cf-product-grid-2 .pq-quick,.cf-product-grid-2 .pq-add,.cf-product-grid-2 .pq-size-face,.cf-product-grid-2 .pq-caret,.cf-product-grid-2 .pq-close,.cf-product-grid-2 .pq-dot{transition:none}
.cf-product-grid-2 .pq-card:hover .pq-photo-1,.cf-product-grid-2 .pq-card.is-hover .pq-photo-1{transform:none}
.cf-product-grid-2 .pq-spin{animation:none}
}
`
pieces/offer/product-grid-2/specimen.tsx 117 lines
import __studioImagea3f4dea2 from "../assets/84f391a9b5b775bb.webp";
import __studioImage3223ab04 from "../assets/904835b6e57697c6.webp";
import __studioImage838fb288 from "../assets/90bcfd505002f2d4.webp";
import * as React from 'react'
import { ProductGrid2, type ProductGrid2Product } from '../product-grid-2'
import defaults from '../../studio-defaults.json'
import { slot } from '../../slots'
// Each designed photo is a 3:2 diptych: the left half is the card photo, the right half the hover photo (or a second product).
const SHELL = __studioImagea3f4dea2
const FLEECE = __studioImage3223ab04
const PACK = __studioImage838fb288
export const states = ['default', 'hover', 'active', 'disabled', 'error'] as const
type State = (typeof states)[number]
// Swatch chips show the product's own fabric colours (product data, not theme colours): each reads a
// page-overridable variable with its designed value as the fallback, so a store can retune them.
// Use the designed diptych half when no theme image is supplied; a supplied slot image is shown whole.
function half(name: string, designed: string, side: 'left' | 'right') {
const image = slot(name, designed)
const own = image === designed
return { image, own, imagePosition: own ? (side === 'left' ? '0% 50%' : '100% 50%') : undefined }
}
export default function ProductGrid2Specimen({ state = 'default' }: { state?: State }) {
const shell = half('item-1', SHELL, 'left')
const fleece = half('item-2', FLEECE, 'left')
const pant = half('item-3', PACK, 'left')
const beanie = half('item-4', PACK, 'right')
const products: ProductGrid2Product[] = [
{
id: 'ridgeline-shell',
name: 'Ridgeline Shell Jacket',
note: 'Packs into its own chest pocket',
image: shell.image,
imageAlt: 'Tern Ridgeline Shell Jacket in moss, front view',
imagePosition: shell.imagePosition,
hoverImage: shell.own ? SHELL : undefined,
hoverImagePosition: '100% 50%',
price: '$129',
compareAt: '$159',
flag: 'New colour',
rating: 4.8,
reviewCount: 212,
swatches: [
{ id: 'moss', label: 'Moss', color: 'var(--swatch-moss, #55703f)' },
{ id: 'slate', label: 'Slate', color: 'var(--swatch-slate, #4b5563)' },
{ id: 'ember', label: 'Ember', color: 'var(--swatch-ember, #c8562d)' },
],
sizes: [{ label: 'XS', soldOut: true }, { label: 'S' }, { label: 'M' }, { label: 'L' }, { label: 'XL' }],
},
{
id: 'cirrus-fleece',
name: 'Cirrus Grid Fleece',
note: 'Breathes on the climb, warm at the top',
image: fleece.image,
imageAlt: 'Tern Cirrus Grid Fleece in teal, front view',
imagePosition: fleece.imagePosition,
hoverImage: fleece.own ? FLEECE : undefined,
hoverImagePosition: '100% 50%',
price: '$89',
rating: 4.7,
reviewCount: 96,
swatches: [
{ id: 'teal', label: 'Teal', color: 'var(--swatch-teal, #0e6a72)' },
{ id: 'charcoal', label: 'Charcoal', color: 'var(--swatch-charcoal, #2f3238)' },
],
sizes: [{ label: 'S' }, { label: 'M' }, { label: 'L', soldOut: true }, { label: 'XL' }, { label: 'XXL' }],
},
{
id: 'switchback-pant',
name: 'Switchback Trail Pant',
note: 'Four-way stretch for every scramble',
image: pant.image,
imageAlt: 'Tern Switchback Trail Pant in charcoal, front view',
imagePosition: pant.imagePosition,
price: '$98',
compareAt: '$120',
swatches: [
{ id: 'charcoal', label: 'Charcoal', color: 'var(--swatch-charcoal, #2f3238)' },
{ id: 'olive', label: 'Olive', color: 'var(--swatch-olive, #6b6f3a)' },
],
sizes: [{ label: '28' }, { label: '30' }, { label: '32' }, { label: '34' }, { label: '36', soldOut: true }],
},
{
id: 'summit-beanie',
name: 'Summit Merino Beanie',
note: 'Soft merino rib, no itch',
image: beanie.image,
imageAlt: 'Tern Summit Merino Beanie in rust',
imagePosition: beanie.imagePosition,
price: '$32',
rating: 4.9,
reviewCount: 58,
swatches: [
{ id: 'rust', label: 'Rust', color: 'var(--swatch-rust, #b5512a)' },
{ id: 'navy', label: 'Navy', color: 'var(--swatch-navy, #243a64)' },
],
sizes: [{ label: 'One size' }],
},
]
return (
<ProductGrid2
headline='Tern trail layers, two taps from your cart'
emphasis='two taps'
punch={['Pick your size right on the card.', 'Add it to your cart.']}
punchWord='Done.'
products={products}
note={`${defaults.sample.guarantee} on every Tern piece.`}
onAdd={() => undefined}
state={state}
/>
)
}
| Name | Type | Details |
|---|---|---|
headline OptionalProductGrid2 |
string |
|
emphasis OptionalProductGrid2 |
string |
|
punch OptionalProductGrid2 |
React.ReactNode[] |
|
punchWord OptionalProductGrid2 |
React.ReactNode |
|
products OptionalProductGrid2 |
ProductGrid2Product[] |
|
note OptionalProductGrid2 |
React.ReactNode |
|
copy OptionalProductGrid2 |
Partial<ProductGrid2Copy> |
|
onAdd OptionalProductGrid2 |
(selection: ProductGrid2Selection) => void | Promise<unknown> |
|
onAction OptionalProductGrid2 |
(selection: ProductGrid2Selection) => void | Promise<unknown> |
|
state OptionalProductGrid2 |
'default' | 'hover' | 'active' | 'disabled' | 'error' |
|
className OptionalProductGrid2 |
string |
Theme roles it reads
Set by the theme bar, a preset or your brand. Colours come from the base tokens (--surface, --ink, --cta…) every piece uses.
--button-bg--button-bg-2--button-case--button-font--button-ink--button-radius--button-shadow--button-text-shadow--button-weight- Main CTA button: background, ink, font, weight, case, radius and shadow.
--button-2-bg--button-2-border--button-2-ink--button-2-shadow- Secondary button.
--card-radius--card-shadow- Cards and panels: radius, border and shadow.
--display-case--display-tracking--display-weight- Headlines: weight, letter case and tracking.
--field--field-border--field-focus--field-ink--field-radius- Form inputs: background, ink, border, radius and focus colour.
Image slots
Filled from the brand’s images; the specimen ships its own defaults.
This piece reads no image slots.
-
84f391a9b5b775bb.webp
image/webp · 33.6 KB
-
904835b6e57697c6.webp
image/webp · 89.6 KB
-
90bcfd505002f2d4.webp
image/webp · 77 KB
-
b77916eca54aa689.webp
image/webp · 8.32 KB
-
d435db6662febfcf.webp
image/webp · 10 KB
-
f0a5d3e1e61804ba.webp
image/webp · 11.6 KB