Quantity Breaks 1
Lets buyers choose a quantity tier and see its supplied price and calculated saving.
Use it in a prompt
Use offer/quantity-breaks 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/quantity-breaks.tsx. - Import it and pass your copy and images (Props tab):
import { QuantityBreaks } from "@/components/funneldna/offer/quantity-breaks"
It restyles from the theme tokens on any wrapper (Theme tab). The specimen source is a complete working example.
pieces/offer/quantity-breaks/component.tsx 843 lines
// Lets buyers choose a quantity tier and see its supplied price and calculated saving.
import * as React from "react"
import { AlertCircle, Check, Loader2, Lock, ShieldCheck, ShoppingCart } from "lucide-react"
export type QuantityBreaksProps = {
/** Generated labels and accessible copy; templates retain the named placeholders. */
copy?: Partial<QuantityBreaksCopy>
productName?: string
/** Singular unit word, e.g. "Kit" or "Bottle". */
unit?: string
unitPlural?: string
heading?: string
tiers?: QuantityTier[]
defaultTierId?: string
/** Button label. {label} and {price} are filled from the selected tier. */
ctaLabel?: string
loadingLabel?: string
/** Deprecated: ignored. The builder wires what happens after the action. */
successLabel?: string
/** Deprecated: ignored. The builder wires what happens after the action. */
successMessage?: string
errorMessage?: string
totalLabel?: string
bestValueLabel?: string
reassurance?: string[]
/** "success" is accepted for older callers and renders as default. */
state?: QuantityBreaksState
name?: string
/** Receives the chosen tier; takes precedence over onAdd. Without either the button does nothing visible. */
onSubmit?: (tier: QuantityTier) => void | Promise<void>
/** Legacy submit alias. */
onAdd?: (tier: QuantityTier) => void | Promise<void>
className?: string
style?: React.CSSProperties
}
export function QuantityBreaks({
copy,
productName = "The Funnel Starter Kit",
unit = "Kit",
unitPlural,
heading = "How many do you want?",
tiers = DEFAULT_TIERS,
defaultTierId,
ctaLabel = "Add {label} To My Cart",
loadingLabel = "Adding To Your Cart…",
errorMessage = "We couldn’t add that to your cart. Please try again.",
totalLabel = "Today’s total",
bestValueLabel = "Best value",
reassurance = ["30-day money-back guarantee"],
state = "default",
name,
onAdd,
onSubmit = onAdd,
className,
style,
}: QuantityBreaksProps) {
const text = { ...DEFAULT_COPY, ...copy }
const plural = unitPlural ?? template(text.plural, { unit })
const unitLower = unit.toLowerCase()
const autoId = React.useId()
const groupName = name ?? "qb" + autoId
const headingId = groupName + "-heading"
const rows: Row[] = React.useMemo(() => {
const parsed = tiers.map((t) => ({ t, money: parseMoney(t.price) }))
const base = parsed
.filter((p) => p.money && p.t.quantity > 0)
.sort((a, b) => a.t.quantity - b.t.quantity)[0]
const baseMoney = base ? base.money : null
const baseUnit = base && baseMoney ? baseMoney.n / base.t.quantity : null
const units = parsed.map((p) => (p.money && p.t.quantity > 0 ? p.money.n / p.t.quantity : null))
const valid = units.filter((u): u is number => u !== null)
const minUnit = valid.length > 1 ? Math.min(...valid) : null
const bestCount = minUnit === null ? 0 : valid.filter((u) => Math.abs(u - minUnit) < 0.005).length
return parsed.map((p, i) => {
const { t, money } = p
const label = t.label ?? template(text.tier, { quantity: t.quantity, unit: t.quantity === 1 ? unit : plural })
const unitValue = units[i]
const sameCurrency = !!(
money &&
baseMoney &&
money.prefix === baseMoney.prefix &&
money.suffix === baseMoney.suffix
)
const compareValue = sameCurrency && baseUnit !== null ? baseUnit * t.quantity : null
const savingValue = compareValue !== null && money ? compareValue - money.n : 0
const hasSaving = savingValue >= 0.01
const isBest =
minUnit !== null &&
bestCount === 1 &&
unitValue !== null &&
Math.abs(unitValue - minUnit) < 0.005 &&
hasSaving
return {
...t,
itemImage: t.itemImage ?? t.image,
label,
unitPrice: money && unitValue !== null && t.quantity > 1 ? formatMoney(unitValue, money) : null,
compare: hasSaving && money && compareValue !== null ? formatMoney(compareValue, money) : null,
saving: hasSaving && money ? formatMoney(savingValue, money) : null,
savingPct: hasSaving && compareValue ? Math.round((savingValue / compareValue) * 100) : 0,
tagText: t.tag === false ? null : t.tag ?? (isBest ? bestValueLabel : null),
isBest,
}
})
}, [tiers, unit, plural, bestValueLabel, text.tier])
const initialId =
defaultTierId ?? (rows.find((r) => r.isBest) ?? rows[0] ?? { id: "" }).id
const [selectedId, setSelectedId] = React.useState(initialId)
const [localStatus, setLocalStatus] = React.useState<Status>("idle")
const mounted = React.useRef(false)
React.useEffect(() => {
mounted.current = true
return () => {
mounted.current = false
}
}, [])
if (!rows.length) return null
const selected = rows.find((r) => r.id === selectedId) ?? rows[0]
const forced: Status | null =
state === "loading" || state === "error" ? state : null
const status: Status = forced ?? localStatus
const disabled = state === "disabled"
const force = state === "hover" || state === "active" ? state : undefined
function choose(id: string) {
setSelectedId(id)
setLocalStatus("idle")
}
async function handleSubmit(e: React.FormEvent<HTMLFormElement>) {
e.preventDefault()
if (disabled || status === "loading" || !onSubmit) return
setLocalStatus("loading")
try {
await onSubmit(selected)
if (mounted.current) setLocalStatus("idle")
} catch {
if (mounted.current) setLocalStatus("error")
}
}
return (
<form
className={"cf-quantity-breaks" + (className ? " " + className : "")}
style={style}
data-force={force}
data-status={status}
data-disabled={disabled || undefined}
onSubmit={handleSubmit}
noValidate
aria-busy={status === "loading" || undefined}
>
<style>{CSS}</style>
<input type="hidden" name="quantity" value={selected.quantity} />
{heading ? (
<div className="qb-head">
<h2 className="qb-heading" id={headingId}>
{heading}
</h2>
</div>
) : null}
<div
className="qb-list"
role="radiogroup"
aria-labelledby={heading ? headingId : undefined}
aria-label={heading ? undefined : template(text.chooseQuantity, { units: plural.toLowerCase() })}
>
{rows.map((row) => {
const isSelected = row.id === selected.id
return (
<label
key={row.id}
className="qb-row"
data-selected={isSelected}
data-noimg={row.itemImage ? undefined : ""}
data-disabled={disabled || undefined}
data-tagged={row.tagText ? "" : undefined}
>
<input
className="qb-input"
type="radio"
name={groupName}
value={row.id}
checked={isSelected}
disabled={disabled}
onChange={() => choose(row.id)}
/>
{row.tagText ? <span className="qb-tag">{row.tagText}</span> : null}
<span className="qb-radio" aria-hidden="true">
<Check />
</span>
{row.itemImage ? (
<span className="qb-thumb">
<img
src={row.itemImage}
alt={row.imageAlt ?? template(text.imageAlt, { label: row.label, productName })}
width={168}
height={168}
loading="lazy"
decoding="async"
/>
</span>
) : null}
<span className="qb-body">
<span className="qb-name">{row.label}</span>
{row.note ? <span className="qb-note">{row.note}</span> : null}
{row.unitPrice ? (
<span className="qb-unit">
<b>{row.unitPrice}</b>{template(text.perUnit, { unit: unitLower })}
</span>
) : null}
</span>
<span className="qb-price">
{row.compare ? (
<s className="qb-was">
<span className="qb-sr">{text.regularly}</span>
{row.compare}
</s>
) : null}
<span className="qb-now">{row.price}</span>
{row.saving ? <span className="qb-save">{template(text.save, { saving: row.saving })}</span> : null}
</span>
</label>
)
})}
</div>
<div className="qb-dock">
<p className="qb-sum-item">
{template(text.summary, { quantity: selected.quantity, productName })}
</p>
<div className="qb-sum-row" aria-live="polite" aria-atomic="true">
<div className="qb-sum-total">
<span className="qb-sum-label">{totalLabel}</span>
<span className="qb-sum-price" key={selected.id}>
<span className="qb-sum-now">{selected.price}</span>
{selected.compare ? (
<s className="qb-sum-was">
<span className="qb-sr">{text.regularly}</span>
{selected.compare}
</s>
) : null}
</span>
</div>
{selected.saving || selected.unitPrice ? (
<div className="qb-sum-side">
{selected.saving ? (
<span className="qb-sum-save">
{template(text.youSave, { saving: selected.saving })}
{selected.savingPct > 0 ? template(text.percent, { percent: selected.savingPct }) : ""}
</span>
) : null}
{selected.unitPrice ? (
<span className="qb-sum-unit">
{template(text.justPerUnit, { price: selected.unitPrice, unit: unitLower })}
</span>
) : null}
</div>
) : null}
</div>
{status === "error" ? (
<div className="qb-msg qb-msg-error" role="alert">
<AlertCircle aria-hidden="true" />
<span>{errorMessage}</span>
</div>
) : null}
<button
type="submit"
className="qb-btn"
disabled={disabled}
aria-disabled={status === "loading" || undefined}
data-busy={status === "loading" || undefined}
>
{status === "loading" ? (
<>
<span className="qb-btn-label">
<Loader2 className="qb-ico qb-spin" aria-hidden="true" />
{loadingLabel}
</span>
</>
) : (
<>
<span className="qb-btn-label">
<ShoppingCart className="qb-ico" aria-hidden="true" />
{fill(ctaLabel, selected.label, selected.price)}
</span>
</>
)}
</button>
{reassurance.length ? (
<ul className="qb-assure">
{reassurance.map((line, i) => (
<li key={line}>
{i === 0 ? <Lock aria-hidden="true" /> : <ShieldCheck aria-hidden="true" />}
<span>{line}</span>
</li>
))}
</ul>
) : null}
</div>
</form>
)
}
export default QuantityBreaks
export type QuantityTier = {
/** Stable id, used as the radio value and the cart line. */
id: string
/** Units in this tier: 1, 2, 3 or 1, 3, 6. */
quantity: number
/** Row title. Defaults to "3 Kits" from quantity + unit. */
label?: string
/** One short line under the title. */
note?: string
/** Supplied price for the whole tier, e.g. "$111". */
price: string
/** Product image for this tier (one, two or three units in the shot). */
itemImage?: string
/** Legacy image alias; itemImage takes precedence. */
image?: string
imageAlt?: string
/** Badge text. Undefined auto-tags the lowest per-unit price; false hides it. */
tag?: string | false
}
export type QuantityBreaksState =
| "default"
| "hover"
| "active"
| "disabled"
| "loading"
| "error"
| "success"
type Money = { n: number; prefix: string; suffix: string }
function parseMoney(value: string): Money | null {
let start = -1
let end = -1
for (let i = 0; i < value.length; i++) {
const c = value[i]
const digit = c >= "0" && c <= "9"
const sep = (c === "." || c === ",") && start !== -1
if (digit || sep) {
if (start === -1) start = i
end = i + 1
} else if (start !== -1) {
break
}
}
if (start === -1) return null
const n = Number(value.slice(start, end).split(",").join(""))
if (!Number.isFinite(n)) return null
return { n, prefix: value.slice(0, start).trim(), suffix: value.slice(end).trim() }
}
function formatMoney(n: number, m: Money) {
const r = Math.round(n * 100) / 100
const whole = Math.abs(r - Math.round(r)) < 0.001
const body = r.toLocaleString("en-US", {
minimumFractionDigits: whole ? 0 : 2,
maximumFractionDigits: whole ? 0 : 2,
})
return m.prefix + body + (m.suffix ? " " + m.suffix : "")
}
function fill(template: string, label: string, price: string) {
return template.split("{label}").join(label).split("{price}").join(price)
}
const DEFAULT_TIERS: QuantityTier[] = [
{ id: "one", quantity: 1, price: "$47", note: "One complete kit, just for you" },
{ id: "two", quantity: 2, price: "$84", note: "Keep one, hand one to a partner" },
{ id: "three", quantity: 3, price: "$111", note: "Kit out your whole launch team" },
]
type Row = QuantityTier & {
label: string
unitPrice: string | null
compare: string | null
saving: string | null
savingPct: number
tagText: string | null
isBest: boolean
}
type Status = "idle" | "loading" | "error"
const CSS = `
.cf-quantity-breaks, .cf-quantity-breaks *, .cf-quantity-breaks *::before, .cf-quantity-breaks *::after { box-sizing: border-box; }
.cf-quantity-breaks{
--qb-soft-ink: var(--band-ink);
container: qb / inline-size;
position: relative;
width: 100%;
max-width: 640px;
margin: 0 auto;
background: var(--card, #ffffff);
color: var(--ink, #101828);
font-family: var(--font-body, Arial, sans-serif);
text-align: left;
border:1px solid oklch(from var(--band, #0f2747) l c h / 0.18);
overflow: hidden;
;--qb-radius:var(--card-radius,var(--radius,14px));--qb-marker:var(--marker,#fae37c);--qb-save-ink:var(--success);--qb-save-bg:var(--success-soft);--qb-line:var(--card-border,oklch(from var(--ink) l c h / 0.13));border-color:var(--card-border,oklch(from var(--ink) l c h / 0.18));border-radius:var(--card-radius,var(--radius,20px));box-shadow:var(--card-shadow, 0 2px 3px oklch(from var(--shadow, oklch(0.22 0.03 260)) l c h / 0.35));}
.cf-quantity-breaks :where(h2, h3, p, ul) { margin: 0; }
:where(.cf-quantity-breaks) .qb-sr{
position: absolute; width: 1px; height: 1px; overflow: hidden;
clip-path: inset(50%); white-space: nowrap;
;}
:where(.cf-quantity-breaks) .qb-head { padding: 28px 28px 2px; }
:where(.cf-quantity-breaks) .qb-heading{
font-family: var(--font-display, Arial, sans-serif);
font-size: clamp(1.5rem, 1.05rem + 2.4cqi, 2.125rem);
line-height: 1.05;
color: var(--ink, #101828);
text-wrap: balance;
;font-weight:var(--display-weight,900);text-transform:var(--display-case,none);letter-spacing:var(--display-tracking,-.02em);}
:where(.cf-quantity-breaks) .qb-list { display: grid; gap: 18px; padding: 26px 28px 30px; }
:where(.cf-quantity-breaks) .qb-row{
position: relative;
display: grid;
grid-template-columns: 28px 84px minmax(0, 1fr) auto;
grid-template-areas: "radio thumb body price";
align-items: center;
column-gap: 16px;
padding: 16px 20px 16px 16px;
border: 2px solid var(--qb-line);
border-radius: var(--qb-radius);
cursor: pointer;
transition: border-color .18s ease, box-shadow .22s ease, transform .22s ease, background-color .18s ease;
;background:var(--card);box-shadow:var(--card-shadow, 0 2px 3px oklch(from var(--shadow, oklch(0.22 0.03 260)) l c h / 0.35));}
:where(.cf-quantity-breaks) .qb-row[data-tagged] { padding-top: 20px; }
:where(.cf-quantity-breaks) .qb-row[data-noimg] {
grid-template-columns: 28px minmax(0, 1fr) auto;
grid-template-areas: "radio body price";
}
:where(.cf-quantity-breaks) .qb-row:hover{
border-color: color-mix(in oklch, var(--accent, #0f5fc2) 45%, var(--qb-line));
transform: translateY(-2px);
;background:var(--card);box-shadow:var(--card-shadow, 0 2px 3px oklch(from var(--shadow, oklch(0.22 0.03 260)) l c h / 0.35));}
:where(.cf-quantity-breaks) .qb-row[data-selected="true"]{
;background:var(--card);box-shadow:var(--card-shadow, 0 2px 3px oklch(from var(--shadow, oklch(0.22 0.03 260)) l c h / 0.35));border-color:var(--accent);}
:where(.cf-quantity-breaks) .qb-row:has(.qb-input:focus-visible){
outline-offset: 3px;
;outline:3px solid var(--field-focus,var(--accent));}
:where(.cf-quantity-breaks) .qb-row[data-disabled] {
cursor: not-allowed;
opacity: .55;
transform: none;
box-shadow: none;
}
.cf-quantity-breaks input{accent-color:var(--field-focus,var(--accent))}
:where(.cf-quantity-breaks) .qb-input{
position: absolute; width: 1px; height: 1px; margin: 0;
opacity: 0; pointer-events: none;
;accent-color:var(--field-focus,var(--accent));}
:where(.cf-quantity-breaks) .qb-tag{
position: absolute;
top: -14px;
right: 18px;
display: inline-flex;
align-items: center;
padding: 6px 12px 5px;
border-radius: 999px;
border:1px solid oklch(from var(--ink) l c h / 0.18);
font-family: var(--font-display, Arial, sans-serif);
font-weight: 900;
font-size: .8125rem;
letter-spacing: .06em;
line-height: 1;
text-transform: uppercase;
white-space: nowrap;
;background:color-mix(in oklch,var(--marker,#fae37c) 25%,var(--card));color:var(--ink);border-color:var(--card-border,oklch(from var(--ink) l c h / 0.12));box-shadow:0 2px 3px oklch(from var(--shadow, oklch(0.22 0.03 260)) l c h / 0.35);}
:where(.cf-quantity-breaks) .qb-radio{
grid-area: radio;
display: grid;
place-items: center;
width: 28px;
height: 28px;
border-radius: 50%;
background: var(--field, #ffffff);
border:2px solid oklch(from var(--ink, #101828) l c h / 0.28);
color: var(--band-ink, #ffffff);
box-shadow:inset 0 1px 2px oklch(from var(--surface) min(0.24, calc(l - 0.12)) c h / .14);
transition: background-color .18s ease, border-color .18s ease, box-shadow .18s ease;
;border-color:var(--field-border,oklch(from var(--ink) l c h / 0.28));}
:where(.cf-quantity-breaks) .qb-radio svg {
width: 16px; height: 16px; stroke-width: 3.25;
transform: scale(0);
transition: transform .24s cubic-bezier(.3, 1.6, .5, 1);
}
:where(.cf-quantity-breaks) .qb-row[data-selected="true"] .qb-radio {background:var(--success);
border-color: var(--band, #0f2747);
box-shadow:0 2px 3px oklch(from var(--shadow, oklch(0.22 0.03 260)) l c h / 0.35);
;color:var(--card)}
:where(.cf-quantity-breaks) .qb-row[data-selected="true"] .qb-radio svg { transform: scale(1); }
:where(.cf-quantity-breaks) .qb-thumb{
grid-area: thumb;
align-self: center;
position: relative;
display: block;
width: 84px;
aspect-ratio: 1;
border-radius: calc(var(--qb-radius) - 4px);
overflow: hidden;
border: 1px solid var(--qb-line);
;background:transparent;border-color:transparent;box-shadow:none;}
:where(.cf-quantity-breaks) .qb-thumb img{
display: block; width: 100%; height: 100%;
transition: transform .4s ease;
;object-fit:contain;filter:drop-shadow(0 2px 3px oklch(from var(--shadow, oklch(0.22 0.03 260)) l c h / 0.35));}
:where(.cf-quantity-breaks) .qb-row[data-selected="true"] .qb-thumb img { transform: scale(1.06); }
:where(.cf-quantity-breaks) .qb-body { grid-area: body; display: grid; gap: 4px; min-width: 0; }
:where(.cf-quantity-breaks) .qb-name{
font-family: var(--font-display, Arial, sans-serif);
font-size: clamp(1.25rem, 1rem + 1.2cqi, 1.5rem);
line-height: 1.1;
color: var(--ink, #101828);
;font-weight:var(--display-weight,900);text-transform:var(--display-case,none);letter-spacing:var(--display-tracking,-.02em);}
:where(.cf-quantity-breaks) .qb-note {
font-size: 1rem;
line-height: 1.35;
font-weight: 500;
color: var(--muted, #4a5565);
text-wrap: pretty;
}
:where(.cf-quantity-breaks) .qb-unit { font-size: .9375rem; font-weight: 500; color: var(--muted, #4a5565); }
:where(.cf-quantity-breaks) .qb-unit b { font-weight: 800; color: var(--ink, #101828); }
:where(.cf-quantity-breaks) .qb-price {
grid-area: price;
display: grid;
justify-items: end;
text-align: right;
gap: 2px;
}
:where(.cf-quantity-breaks) .qb-was {
font-size: 1rem;
font-weight: 600;color:var(--danger);
text-decoration: line-through;text-decoration-color:var(--danger);
text-decoration-thickness: 2px;
font-variant-numeric: tabular-nums;
}
:where(.cf-quantity-breaks) .qb-now {
font-family: var(--font-display, Arial, sans-serif);
font-weight: 900;
font-size: clamp(1.625rem, 1.2rem + 1.8cqi, 2.125rem);
line-height: 1.05;
letter-spacing: -.02em;
color: var(--ink, #101828);
font-variant-numeric: tabular-nums;
}
:where(.cf-quantity-breaks) .qb-save {
margin-top: 6px;
display: inline-flex;
align-items: center;
padding: 4px 12px;
border-radius: 999px;
background: var(--qb-save-bg);
color: var(--qb-save-ink);
border:1px solid oklch(from var(--qb-save-ink) l c h / 0.24);
font-size: .875rem;
font-weight: 800;
white-space: nowrap;
}
:where(.cf-quantity-breaks) .qb-dock {
position: relative;
padding: 24px 28px 26px;
background: var(--band, #0f2747);
color: var(--band-ink, #ffffff);
box-shadow:inset 0 1px 3px oklch(from var(--surface) min(0.24, calc(l - 0.12)) c h / 0.35);
}
:where(.cf-quantity-breaks) .qb-sum-item {
font-size: .9375rem;
font-weight: 600;
color: var(--qb-soft-ink);
text-wrap: pretty;
}
:where(.cf-quantity-breaks) .qb-sum-row {
margin-top: 8px;
display: flex;
flex-wrap: wrap;
align-items: flex-end;
justify-content: space-between;
gap: 10px 24px;
}
:where(.cf-quantity-breaks) .qb-sum-total { display: grid; gap: 4px; }
:where(.cf-quantity-breaks) .qb-sum-label { font-size: .9375rem; font-weight: 700; color: var(--qb-soft-ink); }
:where(.cf-quantity-breaks) .qb-sum-price {
display: flex;
flex-wrap: wrap;
align-items: baseline;
gap: 4px 14px;
animation: qb-pop .35s ease both;
}
:where(.cf-quantity-breaks) .qb-sum-now {
font-family: var(--font-display, Arial, sans-serif);
font-weight: 900;
font-size: clamp(2.25rem, 1.6rem + 3cqi, 3rem);
line-height: 1;
letter-spacing: -.025em;
color: var(--band-ink, #ffffff);
font-variant-numeric: tabular-nums;
}
:where(.cf-quantity-breaks) .qb-sum-was{
font-size: 1.125rem;
font-weight: 700;color:var(--danger);
text-decoration: line-through;
text-decoration-thickness: 2px;
font-variant-numeric: tabular-nums;
;text-decoration-color:var(--danger);;background:var(--danger-soft)}
:where(.cf-quantity-breaks) .qb-sum-side { display: grid; gap: 4px; justify-items: end; text-align: right; }
:where(.cf-quantity-breaks) .qb-sum-save{
font-family: var(--font-display, Arial, sans-serif);
font-weight: 800;
font-size: 1.125rem;
;color:var(--success);;background:var(--success-soft)}
:where(.cf-quantity-breaks) .qb-sum-unit { font-size: .9375rem; font-weight: 500; color: var(--qb-soft-ink); }
:where(.cf-quantity-breaks) .qb-msg {
margin-top: 18px;
display: flex;
align-items: flex-start;
gap: 10px;
padding: 12px 14px;
border-radius: calc(var(--qb-radius) - 4px);
font-size: 1rem;
font-weight: 600;
line-height: 1.4;
text-wrap: pretty;
}
:where(.cf-quantity-breaks) .qb-msg svg { flex: none; width: 20px; height: 20px; margin-top: 1px; }
:where(.cf-quantity-breaks) .qb-msg-error{ ;background:var(--danger-soft);color:var(--danger);border:1px solid var(--card-border,oklch(from var(--ink) l c h / 0.12));}
:where(.cf-quantity-breaks) .qb-btn{
position: relative;
margin-top: 18px;
display: inline-flex;
align-items: center;
justify-content: center;
gap: 12px;
width: 100%;
min-height: 66px;
padding: 14px 20px 15px;
overflow: hidden;
letter-spacing: -.005em;
text-shadow:var(--button-text-shadow, 0 1px 0 oklch(from var(--button-bg, var(--cta)) calc(l - 0.2) c h / 0.75));
cursor: pointer;
transition: transform .12s ease, box-shadow .12s ease, filter .15s ease;
;border:1px solid var(--button-bg-2,var(--cta-2));border-radius:var(--button-radius,var(--radius));background:linear-gradient(180deg,var(--button-bg,var(--cta)),var(--button-bg-2,oklch(from var(--button-bg,var(--cta)) calc(l - 0.05) c h)));color:var(--button-ink,var(--cta-ink));font:var(--button-weight,900) clamp(1.0625rem,.8rem + 1.6cqi,1.375rem)/1.1 var(--button-font,var(--font-display));text-transform:var(--button-case,none);white-space:normal;box-shadow:var(--button-shadow, inset 0 -2px 0 oklch(from var(--surface) min(0.24, calc(l - 0.12)) c h / .16),0 2px 3px oklch(from var(--shadow, oklch(0.22 0.03 260)) l c h / 0.35));}
:where(.cf-quantity-breaks) .qb-btn::after{
content: "";
position: absolute;
inset: 0;
transform: translateX(-120%);
transition: transform .75s ease;
pointer-events: none;
;background:linear-gradient(105deg,transparent 35%,oklch(from var(--button-bg,var(--cta)) calc(l - 0.06) c h / 0.14) 50%,transparent 65%);}
:where(.cf-quantity-breaks) .qb-btn-label { position: relative; text-align: center; }
:where(.cf-quantity-breaks) .qb-ico { position: relative; display: inline-block; vertical-align: -0.15em; margin-inline-end: .4em; width: 22px; height: 22px; stroke-width: 2.5; }
:where(.cf-quantity-breaks) .qb-btn:hover:not(:disabled),
.cf-quantity-breaks[data-force="hover"] .qb-btn:not(:disabled){
transform: translateY(-1px);
;filter:none;box-shadow:var(--button-shadow, 0 2px 3px oklch(from var(--shadow, oklch(0.22 0.03 260)) l c h / 0.35));}
:where(.cf-quantity-breaks) .qb-btn:hover:not(:disabled)::after,
.cf-quantity-breaks[data-force="hover"] .qb-btn:not(:disabled)::after { transform: translateX(120%); }
:where(.cf-quantity-breaks) .qb-btn:active:not(:disabled),
.cf-quantity-breaks[data-force="active"] .qb-btn:not(:disabled){
transform: translateY(3px);
;filter:none;box-shadow:var(--button-shadow, 0 2px 3px oklch(from var(--shadow, oklch(0.22 0.03 260)) l c h / 0.35));}
:where(.cf-quantity-breaks) .qb-btn:focus-visible{ outline-offset: 3px; ;outline:3px solid var(--accent);}
:where(.cf-quantity-breaks) .qb-btn[data-busy] { cursor: progress; }
:where(.cf-quantity-breaks) .qb-btn:disabled{
cursor: not-allowed;
text-shadow: none;
;background:var(--button-2-bg,var(--card));color:var(--button-2-ink,var(--ink));border-color:var(--button-2-border,oklch(from var(--ink) l c h / 0.22));box-shadow:var(--button-shadow, none);}
:where(.cf-quantity-breaks) .qb-btn:disabled::after { display: none; }
:where(.cf-quantity-breaks) .qb-spin { animation: qb-spin .8s linear infinite; }
:where(.cf-quantity-breaks) .qb-assure {
margin-top: 14px;
padding: 0;
list-style: none;
display: flex;
flex-wrap: wrap;
justify-content: center;
gap: 6px 20px;
}
:where(.cf-quantity-breaks) .qb-assure li {
display: inline-flex;
align-items: center;
gap: 7px;
font-size: .875rem;
font-weight: 600;
color: var(--qb-soft-ink);
}
:where(.cf-quantity-breaks) .qb-assure svg{ flex: none; width: 16px; height: 16px; ;color:var(--success);;background:var(--success-soft)}
@keyframes qb-pop { from { opacity: .6; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@keyframes qb-spin { to { transform: rotate(360deg); } }
@container qb (max-width: 520px) {
:where(.cf-quantity-breaks) .qb-head { padding: 22px 18px 0; }
:where(.cf-quantity-breaks) .qb-list { padding: 24px 16px 26px; gap: 18px; }
:where(.cf-quantity-breaks) .qb-row {
grid-template-columns: 24px 64px minmax(0, 1fr);
grid-template-areas: "radio thumb body" "radio thumb price";
align-items: start;
column-gap: 12px;
row-gap: 8px;
padding: 14px 14px 14px 12px;
}
:where(.cf-quantity-breaks) .qb-row[data-tagged] { padding-top: 20px; }
:where(.cf-quantity-breaks) .qb-row[data-noimg] {
grid-template-columns: 24px minmax(0, 1fr);
grid-template-areas: "radio body" "radio price";
}
:where(.cf-quantity-breaks) .qb-radio { width: 24px; height: 24px; align-self: center; }
:where(.cf-quantity-breaks) .qb-radio svg { width: 14px; height: 14px; }
:where(.cf-quantity-breaks) .qb-thumb { width: 64px; }
:where(.cf-quantity-breaks) .qb-price {
display: flex;
flex-wrap: wrap;
align-items: baseline;
justify-content: flex-start;
text-align: left;
gap: 4px 10px;
}
:where(.cf-quantity-breaks) .qb-now { order: -1; }
:where(.cf-quantity-breaks) .qb-save { margin-top: 0; }
:where(.cf-quantity-breaks) .qb-tag { right: 14px; }
:where(.cf-quantity-breaks) .qb-dock { padding: 20px 16px 22px; }
:where(.cf-quantity-breaks) .qb-sum-side { justify-items: start; text-align: left; }
}
@media (prefers-reduced-motion: reduce) {
.cf-quantity-breaks *, .cf-quantity-breaks *::before, .cf-quantity-breaks *::after {
transition-duration: .01ms !important;
animation-duration: .01ms !important;
animation-iteration-count: 1 !important;
}
:where(.cf-quantity-breaks) .qb-row:hover,
:where(.cf-quantity-breaks) .qb-btn:hover:not(:disabled),
.cf-quantity-breaks[data-force="hover"] .qb-btn:not(:disabled) { transform: none; }
:where(.cf-quantity-breaks) .qb-btn::after { display: none; }
:where(.cf-quantity-breaks) .qb-row[data-selected="true"] .qb-thumb img { transform: none; }
}
`
export type QuantityBreaksCopy = {
/** {unit} is the singular unit. */
plural: string
/** {quantity} and {unit} build each default tier name. */
tier: string
/** {units} is the lowercase plural. */
chooseQuantity: string
/** {label} and {productName}. */
imageAlt: string
regularly: string
/** {saving} is the computed amount. */
save: string
/** {unit} is lowercase. */
perUnit: string
/** {quantity} and {productName}. */
summary: string
/** {saving} is the computed amount. */
youSave: string
/** {percent} is the computed percentage. */
percent: string
/** {price} and lowercase {unit}. */
justPerUnit: string
}
const DEFAULT_COPY: QuantityBreaksCopy = { plural: "{unit}s", tier: "{quantity} {unit}", chooseQuantity: "Choose how many {units}", imageAlt: "{label} of {productName}", regularly: "Regularly ", save: "Save {saving}", perUnit: " per {unit}", summary: "{quantity} × {productName}", youSave: "You save {saving}", percent: " ({percent}%)", justPerUnit: "Just {price} per {unit}" }
function template(value: string, fields: Record<string, string | number>) { return value.replace(/\{(\w+)\}/g, (match, key) => key in fields ? String(fields[key]) : match) }
pieces/offer/quantity-breaks/specimen.tsx 55 lines
import __studioImage473edc71 from "../assets/c5dc346fc9072396.webp";
import __studioImage76dc9de6 from "../assets/09abb0ada33062ac.webp";
import __studioImage1f21c3fd from "../assets/79b5cb832bef6f79.webp";
import * as React from "react"
import { QuantityBreaks, type QuantityBreaksState, type QuantityTier } from "../quantity-breaks"
import { slot } from "../../slots"
import defaults from "../../studio-defaults.json"
export const states = ["default", "hover", "active", "disabled", "error"]
const sample = defaults.sample
const tiers: QuantityTier[] = [
{
id: "one",
quantity: 1,
note: "One complete kit, just for you",
price: sample.price,
itemImage: __studioImage473edc71,
imageAlt: "One boxed copy of The Funnel Starter Kit, lid open to show the guide, workbook and checklist",
},
{
id: "two",
quantity: 2,
note: "Keep one, hand one to a partner",
price: "$84",
itemImage: __studioImage76dc9de6,
imageAlt: "Two boxed copies of The Funnel Starter Kit standing side by side",
},
{
id: "three",
quantity: 3,
note: "Kit out your whole launch team",
price: "$111",
itemImage: __studioImage1f21c3fd,
imageAlt: "Three boxed copies of The Funnel Starter Kit grouped together",
},
]
export default function QuantityBreaksSpecimen({ state = "default" }: { state?: string }) {
return (
<div>
<QuantityBreaks
productName={sample.name}
unit="Kit"
unitPlural="Kits"
heading="How many kits do you want?"
tiers={tiers.map((tier, i) => ({ ...tier, itemImage: slot(i === 0 ? "product" : `item-${i}`, tier.itemImage!) }))}
ctaLabel="Add {label} To My Cart"
reassurance={["Secure checkout", sample.guarantee]}
state={state as QuantityBreaksState}
/>
</div>
)
}
| Name | Type | Details |
|---|---|---|
copy OptionalQuantityBreaks |
Partial<QuantityBreaksCopy> |
|
productName OptionalQuantityBreaks |
string |
Default "The Funnel Starter Kit"
|
unit OptionalQuantityBreaks |
string |
Default "Kit"
|
unitPlural OptionalQuantityBreaks |
string |
|
heading OptionalQuantityBreaks |
string |
Default "How many do you want?"
|
tiers OptionalQuantityBreaks |
QuantityTier[] |
Default DEFAULT_TIERS
|
defaultTierId OptionalQuantityBreaks |
string |
|
ctaLabel OptionalQuantityBreaks |
string |
Default "Add {label} To My Cart"
|
loadingLabel OptionalQuantityBreaks |
string |
Default "Adding To Your Cart…"
|
successLabel OptionalQuantityBreaks |
string |
|
successMessage OptionalQuantityBreaks |
string |
|
errorMessage OptionalQuantityBreaks |
string |
Default "We couldn’t add that to your cart. Please try again."
|
totalLabel OptionalQuantityBreaks |
string |
Default "Today’s total"
|
bestValueLabel OptionalQuantityBreaks |
string |
Default "Best value"
|
reassurance OptionalQuantityBreaks |
string[] |
Default ["30-day money-back guarantee"]
|
state OptionalQuantityBreaks |
QuantityBreaksState |
Default "default"
|
name OptionalQuantityBreaks |
string |
|
onSubmit OptionalQuantityBreaks |
(tier: QuantityTier) => void | Promise<void> |
Default onAdd
|
onAdd OptionalQuantityBreaks |
(tier: QuantityTier) => void | Promise<void> |
|
className OptionalQuantityBreaks |
string |
|
style OptionalQuantityBreaks |
React.CSSProperties |
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- Secondary button.
--card-border--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- Form inputs: background, ink, border, radius and focus colour.
--marker- The highlighter colour behind key phrases.
Image slots
Filled from the brand’s images; the specimen ships its own defaults.
item-*- One image per offer item (item-1, item-2…), shown in stacks and lists.
product- The main product shot or cover (ebook, kit, bottle).
-
09abb0ada33062ac.webp
image/webp · 50.1 KB
-
79b5cb832bef6f79.webp
image/webp · 78.3 KB
-
b77916eca54aa689.webp
image/webp · 8.32 KB
-
c5dc346fc9072396.webp
image/webp · 93.9 KB
-
d435db6662febfcf.webp
image/webp · 10 KB
-
f0a5d3e1e61804ba.webp
image/webp · 11.6 KB