Slide-Over Cart Drawer
A basket panel with the dialog mechanics usually missing: focus trap, focus return, Escape to close and a background scroll lock.
The gifting step, placed in the cart where it is a choice rather than at checkout where it is friction.
components/gift-options-form.tsxnpx hoverlab add gift-options-form
Or over MCP, from your editor's agent — no account needed.
Free to read, copy and install, for personal and non-commercial projects. Shipping it in client work or a paid product needs Pro ($79 once). The source lands in your repo and stops being ours — no attribution, nothing to upgrade.
Start a page with this section — add more, order them, and leave with the page source.
In the cart rather than at checkout, because a gift message added while someone is entering card details is a step between them and paying. Here it is part of choosing.
Rendered live in your current theme — this is the same component whose source is below, not a screenshot of it.
'use client'
/**
* <GiftOptionsForm> — The gifting step, placed in the cart where it is a choice rather than at checkout where it is friction.
*
* Placement is the whole decision here, and it is a layout problem rather
* than a form problem. The obvious wrong answer is checkout, where every
* implementation puts it — a gift message typed while someone is entering
* card details is a step standing between them and paying, and it converts
* worse than not offering it.
*
* In the cart it is part of choosing, which is what it actually is. The
* reader is still deciding; adding a message is another decision of the same
* kind, and there is no payment flow to interrupt.
*
* The character limit is in the hint rather than in a counter that turns red.
* A limit stated before typing is a constraint; a limit enforced after is a
* correction, and the difference matters on a field where someone has
* composed something personal.
*
* Accessibility: the labels are associated with `htmlFor`/`id` so the hints
* ride on `aria-describedby`, and the `role="status"` region exists empty
* from the first paint so the confirmation is announced. The "From" hint
* carries a real option — leave it blank to stay anonymous — which is the
* kind of thing that must be announced with the field rather than sitting as
* unassociated text beside it.
*
* The demo defaults to `idle`. Both fields are required by the scaffold; a
* real implementation should make both optional, since an anonymous gift
* with no message is a legitimate order.
*/
import * as React from 'react'
export interface GiftOptionsFormProps {
heading?: string
intro?: string
submitLabel?: string
/** Called with the collected values. Resolve to accept, throw to reject. */
onSubmit?: (values: Record<string, string>) => Promise<void> | void
className?: string
}
type Status = 'idle' | 'pending' | 'done' | 'error'
/*
A typed array rather than `as const`. With `as const` the entries have
different shapes - some carry a hint, some do not - so `field.hint` is a
type error on the members that lack it, and the `'hint' in field` dance
needed to work around that is worse than declaring the field optional once.
*/
interface GiftOptionsFormField {
name: string
label: string
type: string
hint?: string
}
const FIELDS: GiftOptionsFormField[] = [
{ name: "message", label: "Message on the card", type: "text", hint: "Handwritten and enclosed. Up to 200 characters." },
{ name: "from", label: "From", type: "text", hint: "Signed as written. Leave blank to stay anonymous." },
]
export function GiftOptionsForm({
heading = "Sending this as a gift?",
intro = "In the cart rather than at checkout, because a gift message added while someone is entering card details is a step between them and paying. Here it is part of choosing.",
submitLabel = "Add gift options",
onSubmit,
className,
}: GiftOptionsFormProps) {
/*
Per-instance prefix for every id this block emits.
The literals these replaced were a latent duplicate the moment the
block appeared twice on one document, and `aria-labelledby` on a
duplicated id resolves to the first match -- so the second copy was
labelled by the first copy's heading. Client component, so `useId` is
the right tool.
*/
const uid = React.useId()
const [status, setStatus] = React.useState<Status>('idle')
const [message, setMessage] = React.useState('')
async function handleSubmit(event: React.FormEvent<HTMLFormElement>) {
event.preventDefault()
const data = new FormData(event.currentTarget)
const values = Object.fromEntries(
FIELDS.map((field) => [field.name, String(data.get(field.name) ?? '')]),
)
setStatus('pending')
try {
await onSubmit?.(values)
setStatus('done')
setMessage('Thanks — that came through.')
} catch (error) {
setStatus('error')
setMessage(error instanceof Error ? error.message : 'That did not go through.')
}
}
return (
<section
aria-labelledby={`${uid}-gift-options-form-heading`}
className={`w-full bg-background px-6 py-16 ${className ?? ''}`}
>
<div className="mx-auto max-w-md rounded-xl border border-border bg-card p-8 shadow-sm">
<h2
id={`${uid}-gift-options-form-heading`}
className="text-xl font-semibold tracking-tight text-card-foreground"
>
{heading}
</h2>
<p className="mt-2 text-sm text-muted-foreground">{intro}</p>
<form onSubmit={handleSubmit} className="mt-6 space-y-4">
{FIELDS.map((field) => (
<div key={field.name}>
{/*
htmlFor / id rather than a wrapping label, so the hint can
sit outside the label and still be announced — that is what
aria-describedby is for.
*/}
<label
htmlFor={`${uid}-gift-options-form-${field.name}`}
className="block text-sm font-medium text-foreground"
>
{field.label}
</label>
<input
id={`${uid}-gift-options-form-${field.name}`}
name={field.name}
type={field.type}
required
aria-describedby={field.hint ? `${uid}-gift-options-form-${field.name}-hint` : undefined}
className="mt-1.5 w-full rounded-md border border-input bg-background px-3 py-2 text-sm text-foreground placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring"
/>
{field.hint ? (
<p
id={`${uid}-gift-options-form-${field.name}-hint`}
className="mt-1 text-xs text-muted-foreground"
>
{field.hint}
</p>
) : null}
</div>
))}
<button
type="submit"
disabled={status === 'pending'}
className="w-full rounded-md bg-primary px-4 py-2 text-sm font-medium text-primary-foreground transition-opacity hover:opacity-90 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:opacity-60"
>
{status === 'pending' ? 'Working…' : submitLabel}
</button>
{/*
The live region is always in the DOM and starts empty. A region
mounted at the moment it gets text is frequently not announced —
the assistive tech never saw it become live.
*/}
<p
role="status"
aria-live="polite"
className={`min-h-5 text-sm ${
status === 'error' ? 'text-destructive' : 'text-muted-foreground'
}`}
>
{message}
</p>
</form>
</div>
</section>
)
}
bg-card, text-muted-foreground) — it inherits your theme instead of overriding it.Drop it at components/gift-options-form.tsx and import it where you need the section:
import { GiftOptionsForm } from '@/components/gift-options-form'2 of this block’s props are simple enough to drive from here. Change them and the block below re-renders — it is the same component whose source is above, not a mock of it. Everything else it accepts is in the table underneath.
Read out of the component’s own type and signature, so this cannot drift from the source below. Every prop has a default — the component renders standalone before you pass it anything.
| Prop | Type | Default |
|---|---|---|
heading | string | "Sending this as a gift?" |
intro | string | — |
submitLabel | string | "Add gift options" |
onSubmitCalled with the collected values. Resolve to accept, throw to reject. | (values: Record<string, string>) => Promise<void> | void | — |
className | string | — |
The same block rendered once to markup, wrapped as a file your framework compiles. Tailwind classes are framework-agnostic, so the design transfers intact — the behaviour does not.
This block is interactive. The markup below is its initial state with the event handlers stripped — you will need to re-wire the behaviour in your framework.
<!--
Gift Options Form — markup from the Hoverlab catalog.
This is the block rendered once to HTML and wrapped as a component
file. It is not a port of the React source: the Tailwind classes carry
the design, which is the part that took the work, and they are the same
in every framework.
This block is interactive in React and the handlers are NOT here.
Buttons, toggles and menus render in their initial state and do
nothing until you wire them up.
-->
<section aria-labelledby="_R_0_-gift-options-form-heading" class="w-full bg-background px-6 py-16 ">
<div class="mx-auto max-w-md rounded-xl border border-border bg-card p-8 shadow-sm">
<h2 id="_R_0_-gift-options-form-heading" class="text-xl font-semibold tracking-tight text-card-foreground">Sending this as a gift?</h2>
<p class="mt-2 text-sm text-muted-foreground">In the cart rather than at checkout, because a gift message added while someone is entering card details is a step between them and paying. Here it is part of choosing.</p>
<form class="mt-6 space-y-4">
<div>
<label for="_R_0_-gift-options-form-message" class="block text-sm font-medium text-foreground">Message on the card</label>
<input id="_R_0_-gift-options-form-message" type="text" required="" aria-describedby="_R_0_-gift-options-form-message-hint" class="mt-1.5 w-full rounded-md border border-input bg-background px-3 py-2 text-sm text-foreground placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring" name="message" />
<p id="_R_0_-gift-options-form-message-hint" class="mt-1 text-xs text-muted-foreground">Handwritten and enclosed. Up to 200 characters.</p>
</div>
<div>
<label for="_R_0_-gift-options-form-from" class="block text-sm font-medium text-foreground">From</label>
<input id="_R_0_-gift-options-form-from" type="text" required="" aria-describedby="_R_0_-gift-options-form-from-hint" class="mt-1.5 w-full rounded-md border border-input bg-background px-3 py-2 text-sm text-foreground placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring" name="from" />
<p id="_R_0_-gift-options-form-from-hint" class="mt-1 text-xs text-muted-foreground">Signed as written. Leave blank to stay anonymous.</p>
</div>
<button type="submit" class="w-full rounded-md bg-primary px-4 py-2 text-sm font-medium text-primary-foreground transition-opacity hover:opacity-90 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:opacity-60">Add gift options</button>
<p role="status" aria-live="polite" class="min-h-5 text-sm text-muted-foreground"></p>
</form>
</div>
</section>
What each framework gets across the whole catalog — effects convert properly; this rung is markup.
The component, its props, the design tokens it expects and the command that installs it — as one prompt. Paste it into Claude, Cursor, v0 or ChatGPT and what they build around it will match the rest of the catalog instead of inventing its own system.
Want the whole screen instead of this one section? Open a page and copy it entire.
All of them free to read, copy and install — no account, no locked tiles, no watermarked preview. The whole catalog is open, and so are the API and the CLI.
Browse Cart & CheckoutCopying the code is free. Putting it in client work or a paid product is what Pro is for — the licence, not the access.
A basket panel with the dialog mechanics usually missing: focus trap, focus return, Escape to close and a background scroll lock.
Quantity steppers and remove-with-undo, with every total derived rather than stored so the basket can never disagree with itself.
The full autocomplete token set that lets a browser fill eight fields in one tap, plus address labels that follow the selected country.
Subtotal, discount, delivery and tax all derived from the lines, with the free-delivery nudge driven by the same threshold as the charge.
The wallet buttons above the form, and what they do to it: the address a wallet returns is shown and stays editable, and the row disappears entirely when no wallet is actually available.
The only checkout where the buyer is not the recipient - live preview, a send date with a stated timezone, and the confirm-the-address field that prevents the expensive typo.
Guest as the default and the whole form, with a real autocomplete token on every field and the account offer moved to the end, where it costs one checkbox.
The offer popup with four rules applied: triggered by intent, a decline button of equal weight, a dismissal that is remembered, and the terms on its face.