Product card with quick view
A shop card where each color swatch swaps the product photo with a wipe, and Quick view slides out sizes and an add-to-bag button.
"use client";
import { useEffect, useId, useRef, useState } from "react";
import "./product-card.css";
export type Colorway = { name: string; swatch: string; image: string };
type ProductCardProps = {
name: string;
price: string;
tag?: string;
colorways: Colorway[];
sizes: string[];
soldOut?: string[];
theme?: "light" | "dark";
};
/** A photo that shows a tinted placeholder until the real file exists. */
function Photo({ src, alt, tone }: { src: string; alt: string; tone: string }) {
const img = useRef<HTMLImageElement>(null);
const [missing, setMissing] = useState(false);
useEffect(() => {
// The image may have failed before React attached onError.
const el = img.current;
if (el && el.complete && el.naturalWidth === 0) setMissing(true);
}, [src]);
return (
<div className="gu-prod__photo" style={{ background: tone }}>
{!missing && (
<img ref={img} src={src} alt={alt} onError={() => setMissing(true)} />
)}
</div>
);
}
/**
* ProductCard
* - Swatches swap the photo with a diagonal wipe (clip-path) instead of a hard cut.
* - Quick view expands a panel with sizes using a grid-rows animation.
* - Add to bag gives instant feedback in the button itself.
*/
export function ProductCard({
name,
price,
tag,
colorways,
sizes,
soldOut = [],
theme = "light",
}: ProductCardProps) {
const id = useId();
const [color, setColor] = useState(0);
const [open, setOpen] = useState(false);
const [size, setSize] = useState<string | null>(null);
const [added, setAdded] = useState(false);
const current = colorways[color];
return (
<article
className="gu-prod"
data-theme={theme}
aria-labelledby={`${id}-name`}
>
<div className="gu-prod__media">
{colorways.map((c, i) => (
<div
key={c.name}
className="gu-prod__layer"
data-on={i === color || undefined}
aria-hidden={i !== color}
>
<Photo src={c.image} alt={`${name} in ${c.name}`} tone={c.swatch} />
</div>
))}
{tag && <span className="gu-prod__tag">{tag}</span>}
</div>
<div className="gu-prod__body">
<div className="gu-prod__head">
<h3 id={`${id}-name`}>{name}</h3>
<p className="gu-prod__price">{price}</p>
</div>
<fieldset className="gu-prod__swatches">
<legend>
Color: <strong>{current.name}</strong>
</legend>
{colorways.map((c, i) => (
<label key={c.name} title={c.name}>
<input
type="radio"
name={`${id}-color`}
checked={i === color}
onChange={() => setColor(i)}
/>
<span style={{ background: c.swatch }} aria-hidden="true" />
<span className="gu-prod__sr">{c.name}</span>
</label>
))}
</fieldset>
<button
type="button"
className="gu-prod__quick"
aria-expanded={open}
aria-controls={`${id}-panel`}
onClick={() => setOpen((o) => !o)}
>
{open ? "Hide sizes" : "Quick view"}
<span aria-hidden="true">+</span>
</button>
<div
id={`${id}-panel`}
className="gu-prod__panel"
data-open={open || undefined}
>
<div inert={!open}>
<fieldset className="gu-prod__sizes">
<legend>Size (EU)</legend>
{sizes.map((s) => {
const out = soldOut.includes(s);
return (
<label key={s} data-out={out || undefined}>
<input
type="radio"
name={`${id}-size`}
disabled={out}
checked={size === s}
onChange={() => setSize(s)}
/>
<span>{s}</span>
</label>
);
})}
</fieldset>
<button
type="button"
className="gu-prod__add"
disabled={!size}
data-added={added || undefined}
onClick={() => {
setAdded(true);
setTimeout(() => setAdded(false), 1800);
}}
>
{added
? "Added to bag"
: size
? `Add size ${size} to bag`
: "Pick a size"}
</button>
<p className="gu-prod__sr" role="status">
{added
? `${name}, ${current.name}, size ${size}, added to bag`
: ""}
</p>
</div>
</div>
</div>
</article>
);
}
Paste this into ChatGPT, Claude, Cursor, v0, Lovable or Bolt. It describes the layout, motion, colors and accessibility and includes the code, so the AI can rebuild it in any framework.
# Build this UI piece: Product card with quick view
You are a senior front-end engineer. Recreate the piece below in my project. If I don't say which framework I use, ask once, then build it in that framework (React, Vue, Svelte, Angular, Astro, plain HTML/CSS/JS or anything else). Keep the behavior, motion, colors, spacing and accessibility exactly as described. Keep the code clean and commented for beginners.
## What it is
An online-shop product card. Choosing a color swatch swaps the product photo with a diagonal wipe. A "Quick view" button expands sizes (with sold-out sizes crossed out) and an add-to-bag button that confirms in place.
## Layout and look
- Card max 360px, radius 24px, 1px border, background #fbf8f2 (dark #18181b).
- Photo area 4:5, object-fit cover, slight zoom (1.04) on card hover. A lime (#d7ff3a) "New colors" pill top-left.
- Name (weight 800) and price on one row; "Color: Ember" legend; 28px round swatches inside 44px tap areas; the selected one gets a double ring (card color then text color) and scales to 0.9.
- Quick view: full-width outlined button with a "+" that turns into "×". Panel: 4-column grid of size boxes (44px tall), selected = filled dark; sold out = faded and struck through. Orange (#ff5a1f) add button, disabled until a size is picked; turns lime with "Added to bag".
- Missing photos show the swatch color with soft white diagonal stripes.
## Behavior and motion
1. All colorway photos are stacked. Inactive ones are clipped to a zero-width polygon at the left; the active one animates to polygon(0 0, 130% 0, 100% 100%, 0 100%) in 700ms (cubic-bezier(0.16, 1, 0.3, 1)), giving a slanted wipe.
2. The panel opens with grid-template-rows 0fr → 1fr (450ms).
3. Add to bag shows "Added to bag" for 1.8s.
## Touch
All controls are taps with 44px targets.
## Accessibility
- <article> labelled by the product name. Swatches and sizes are real radio inputs in fieldsets with legends; sold-out sizes are disabled.
- Quick view uses aria-expanded/aria-controls; the closed panel is inert; a status region announces the addition.
- prefers-reduced-motion: no wipe, no panel slide, no zoom.
## Props
name, price, tag, colorways ({ name, swatch, image }[]), sizes, soldOut, theme.
## Images
Three product photos, 4:5, one per colorway, same angle and lighting.
## Reference implementation
The original is written in React with one plain CSS file. Dependencies: none (plain React and CSS). Translate it faithfully; do not add new libraries unless my framework needs them.
### ProductCard.tsx
```tsx
"use client";
import { useEffect, useId, useRef, useState } from "react";
import "./product-card.css";
export type Colorway = { name: string; swatch: string; image: string };
type ProductCardProps = {
name: string;
price: string;
tag?: string;
colorways: Colorway[];
sizes: string[];
soldOut?: string[];
theme?: "light" | "dark";
};
/** A photo that shows a tinted placeholder until the real file exists. */
function Photo({ src, alt, tone }: { src: string; alt: string; tone: string }) {
const img = useRef<HTMLImageElement>(null);
const [missing, setMissing] = useState(false);
useEffect(() => {
// The image may have failed before React attached onError.
const el = img.current;
if (el && el.complete && el.naturalWidth === 0) setMissing(true);
}, [src]);
return (
<div className="gu-prod__photo" style={{ background: tone }}>
{!missing && (
<img ref={img} src={src} alt={alt} onError={() => setMissing(true)} />
)}
</div>
);
}
/**
* ProductCard
* - Swatches swap the photo with a diagonal wipe (clip-path) instead of a hard cut.
* - Quick view expands a panel with sizes using a grid-rows animation.
* - Add to bag gives instant feedback in the button itself.
*/
export function ProductCard({
name,
price,
tag,
colorways,
sizes,
soldOut = [],
theme = "light",
}: ProductCardProps) {
const id = useId();
const [color, setColor] = useState(0);
const [open, setOpen] = useState(false);
const [size, setSize] = useState<string | null>(null);
const [added, setAdded] = useState(false);
const current = colorways[color];
return (
<article
className="gu-prod"
data-theme={theme}
aria-labelledby={`${id}-name`}
>
<div className="gu-prod__media">
{colorways.map((c, i) => (
<div
key={c.name}
className="gu-prod__layer"
data-on={i === color || undefined}
aria-hidden={i !== color}
>
<Photo src={c.image} alt={`${name} in ${c.name}`} tone={c.swatch} />
</div>
))}
{tag && <span className="gu-prod__tag">{tag}</span>}
</div>
<div className="gu-prod__body">
<div className="gu-prod__head">
<h3 id={`${id}-name`}>{name}</h3>
<p className="gu-prod__price">{price}</p>
</div>
<fieldset className="gu-prod__swatches">
<legend>
Color: <strong>{current.name}</strong>
</legend>
{colorways.map((c, i) => (
<label key={c.name} title={c.name}>
<input
type="radio"
name={`${id}-color`}
checked={i === color}
onChange={() => setColor(i)}
/>
<span style={{ background: c.swatch }} aria-hidden="true" />
<span className="gu-prod__sr">{c.name}</span>
</label>
))}
</fieldset>
<button
type="button"
className="gu-prod__quick"
aria-expanded={open}
aria-controls={`${id}-panel`}
onClick={() => setOpen((o) => !o)}
>
{open ? "Hide sizes" : "Quick view"}
<span aria-hidden="true">+</span>
</button>
<div
id={`${id}-panel`}
className="gu-prod__panel"
data-open={open || undefined}
>
<div inert={!open}>
<fieldset className="gu-prod__sizes">
<legend>Size (EU)</legend>
{sizes.map((s) => {
const out = soldOut.includes(s);
return (
<label key={s} data-out={out || undefined}>
<input
type="radio"
name={`${id}-size`}
disabled={out}
checked={size === s}
onChange={() => setSize(s)}
/>
<span>{s}</span>
</label>
);
})}
</fieldset>
<button
type="button"
className="gu-prod__add"
disabled={!size}
data-added={added || undefined}
onClick={() => {
setAdded(true);
setTimeout(() => setAdded(false), 1800);
}}
>
{added
? "Added to bag"
: size
? `Add size ${size} to bag`
: "Pick a size"}
</button>
<p className="gu-prod__sr" role="status">
{added
? `${name}, ${current.name}, size ${size}, added to bag`
: ""}
</p>
</div>
</div>
</div>
</article>
);
}
```
### product-card.css
```css
/* ProductCard: change these colors to match your brand. */
.gu-prod {
--card: #fbf8f2;
--text: #0e0e10;
--muted: #57534b;
--line: rgb(14 14 16 / 0.14);
--accent: #ff5a1f;
--accent-text: #0e0e10;
--ok: #d7ff3a;
--focus: #2b35ff;
--ease: cubic-bezier(0.16, 1, 0.3, 1);
width: min(100%, 360px);
overflow: hidden;
border: 1px solid var(--line);
border-radius: 24px;
background: var(--card);
color: var(--text);
font-family: system-ui, sans-serif;
}
.gu-prod[data-theme="dark"] {
--card: #18181b;
--text: #f3eee3;
--muted: #aea89c;
--line: rgb(243 238 227 / 0.14);
--focus: #d7ff3a;
}
.gu-prod :focus-visible {
outline: 2px solid var(--focus);
outline-offset: 2px;
}
/* Photos are stacked; the selected one wipes in diagonally */
.gu-prod__media {
position: relative;
aspect-ratio: 4 / 5;
overflow: hidden;
}
.gu-prod__layer {
position: absolute;
inset: 0;
clip-path: polygon(0 0, 0 0, 0 100%, 0 100%);
transition: clip-path 0.7s var(--ease);
}
.gu-prod__layer[data-on] {
z-index: 1;
clip-path: polygon(0 0, 130% 0, 100% 100%, 0 100%);
}
.gu-prod__photo {
position: absolute;
inset: 0;
/* Placeholder: soft stripes over the swatch color until the photo exists */
background-image: repeating-linear-gradient(
135deg,
rgb(255 255 255 / 0.16) 0 2px,
transparent 2px 16px
) !important;
background-blend-mode: normal;
}
.gu-prod__photo img {
width: 100%;
height: 100%;
object-fit: cover;
transition: transform 0.9s var(--ease);
}
.gu-prod:hover .gu-prod__photo img {
transform: scale(1.04);
}
.gu-prod__tag {
position: absolute;
top: 14px;
left: 14px;
z-index: 2;
padding: 6px 11px;
border-radius: 999px;
background: var(--ok);
color: #0e0e10;
font-size: 0.75rem;
font-weight: 800;
}
.gu-prod__body {
padding: 18px 20px 20px;
}
.gu-prod__head {
display: flex;
align-items: baseline;
justify-content: space-between;
gap: 12px;
}
.gu-prod__head h3 {
margin: 0;
font-size: 1.15rem;
font-weight: 800;
letter-spacing: -0.02em;
}
.gu-prod__price {
margin: 0;
font-weight: 800;
}
.gu-prod fieldset {
margin: 0;
padding: 0;
border: 0;
}
.gu-prod legend {
padding: 0;
margin-bottom: 8px;
color: var(--muted);
font-size: 0.82rem;
}
.gu-prod legend strong {
color: var(--text);
}
.gu-prod input {
position: absolute;
opacity: 0;
pointer-events: none;
}
.gu-prod__swatches {
display: flex;
flex-wrap: wrap;
gap: 4px;
margin-top: 14px !important;
}
.gu-prod__swatches legend {
width: 100%;
}
.gu-prod__swatches label {
position: relative;
display: grid;
place-items: center;
width: 44px;
height: 44px;
cursor: pointer;
}
.gu-prod__swatches label > span:first-of-type {
width: 28px;
height: 28px;
border-radius: 50%;
box-shadow: inset 0 0 0 1px rgb(0 0 0 / 0.15);
transition:
box-shadow 0.25s,
transform 0.25s var(--ease);
}
.gu-prod__swatches input:checked + span {
box-shadow:
0 0 0 2px var(--card),
0 0 0 4px var(--text);
transform: scale(0.9);
}
.gu-prod__swatches input:focus-visible + span {
outline: 2px solid var(--focus);
outline-offset: 5px;
}
.gu-prod__quick {
display: flex;
align-items: center;
justify-content: space-between;
width: 100%;
min-height: 46px;
margin-top: 12px;
padding: 0 16px;
border: 1.5px solid var(--line);
border-radius: 12px;
background: none;
color: inherit;
font: inherit;
font-weight: 700;
cursor: pointer;
}
.gu-prod__quick span {
font-size: 1.3rem;
transition: transform 0.35s var(--ease);
}
.gu-prod__quick[aria-expanded="true"] span {
transform: rotate(45deg);
}
.gu-prod__panel {
display: grid;
grid-template-rows: 0fr;
transition: grid-template-rows 0.45s var(--ease);
}
.gu-prod__panel[data-open] {
grid-template-rows: 1fr;
}
.gu-prod__panel > div {
min-height: 0;
overflow: hidden;
}
.gu-prod__sizes {
display: grid;
grid-template-columns: repeat(4, 1fr);
gap: 6px;
padding-top: 14px !important;
}
.gu-prod__sizes legend {
grid-column: 1 / -1;
}
.gu-prod__sizes label span {
display: grid;
place-items: center;
min-height: 44px;
border: 1.5px solid var(--line);
border-radius: 10px;
font-weight: 700;
cursor: pointer;
transition:
background-color 0.2s,
color 0.2s,
border-color 0.2s;
}
.gu-prod__sizes input:checked + span {
border-color: var(--text);
background: var(--text);
color: var(--card);
}
.gu-prod__sizes input:focus-visible + span {
outline: 2px solid var(--focus);
outline-offset: 2px;
}
.gu-prod__sizes label[data-out] span {
color: var(--muted);
text-decoration: line-through;
cursor: not-allowed;
opacity: 0.5;
}
.gu-prod__add {
width: 100%;
min-height: 50px;
margin-top: 12px;
border: 0;
border-radius: 12px;
background: var(--accent);
color: var(--accent-text);
font: inherit;
font-weight: 800;
cursor: pointer;
transition:
background-color 0.25s,
opacity 0.25s;
}
.gu-prod__add:disabled {
opacity: 0.45;
cursor: not-allowed;
}
.gu-prod__add[data-added] {
background: var(--ok);
color: #0e0e10;
}
.gu-prod__sr {
position: absolute;
width: 1px;
height: 1px;
overflow: hidden;
clip-path: inset(50%);
}
@media (prefers-reduced-motion: reduce) {
.gu-prod__layer,
.gu-prod__panel,
.gu-prod__photo img,
.gu-prod__quick span {
transition: none;
}
}
```
You might also want
Next piece: Product shop pageExpanding image accordion
Components, beginner
3D tilt card
Components, intermediate
Spotlight cards
Components, beginner


