Skip to content
Commerce block

Back In Stock Form

The capture that replaces a dead sold-out button, with the honest caveat that a notification is not a reservation.

177 linesNo dependenciesAdded 9 Sept 2026
  • stock
  • notify
  • product
  • commerce
  • waitlist

What's included

  • components/back-in-stock-form.tsx
  • No runtime dependencies

Works with

  • React
  • Next.js
  • Tailwind CSS
  • TypeScript

npx hoverlab add back-in-stock-form

Or over MCP, from your editor's agent — no account needed.

License

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.

Was this useful?

Start a page with this section — add more, order them, and leave with the page source.

Preview

Tell me when it is back

A sold-out product page with a greyed-out button is a dead end and a lost address. One field turns it into the only useful thing left on the page.

One message when it restocks. This is not a reservation — stock is first come.

Only that size triggers the alert. Leave blank for any.

Rendered live in your current theme — this is the same component whose source is below, not a screenshot of it.

Source

components/back-in-stock-form.tsx
'use client'

/**
 * <BackInStockForm> — The capture that replaces a dead sold-out button, with the honest caveat that a notification is not a reservation.
 *
 * A sold-out product page is the highest-intent, lowest-yield page in
 * commerce: someone has decided, and there is nothing for them to do. The
 * layout problem is what occupies the space the buy button had. The obvious
 * wrong answer is a disabled button, which is a dead end that still looks
 * like the primary action.
 *
 * So the capture takes that slot, and the second field is the one most
 * implementations omit: without the size, the alert fires on a restock of a
 * variant the reader cannot use, which teaches them to ignore the next one.
 *
 * The hint on the email field carries the sentence that keeps this honest —
 * a notification is not a reservation. Sending "it's back!" to four hundred
 * people for eleven units and calling it a reservation is how this feature
 * generates complaints rather than orders.
 *
 * Accessibility: the label/hint pairing is `htmlFor`/`id` plus
 * `aria-describedby`, so "this is not a reservation" is announced as part of
 * the field rather than floating after it — which is exactly the sentence
 * that must not be missed. The live region is mounted empty from first
 * paint, because a region created when the message arrives is usually never
 * announced.
 *
 * The demo defaults to `idle`. Both fields are marked required by the
 * scaffold; a real implementation should relax the size field, since "any
 * size" is a legitimate answer and the hint already says so.
 */

import * as React from 'react'

export interface BackInStockFormProps {
  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 BackInStockFormField {
  name: string
  label: string
  type: string
  hint?: string
}

const FIELDS: BackInStockFormField[] = [
  { name: "email", label: "Email", type: "email", hint: "One message when it restocks. This is not a reservation — stock is first come." },
  { name: "size", label: "Size", type: "text", hint: "Only that size triggers the alert. Leave blank for any." },
]

export function BackInStockForm({
  heading = "Tell me when it is back",
  intro = "A sold-out product page with a greyed-out button is a dead end and a lost address. One field turns it into the only useful thing left on the page.",
  submitLabel = "Notify me",
  onSubmit,
  className,
}: BackInStockFormProps) {
  /*
    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}-back-in-stock-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}-back-in-stock-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}-back-in-stock-form-${field.name}`}
                className="block text-sm font-medium text-foreground"
              >
                {field.label}
              </label>
              <input
                id={`${uid}-back-in-stock-form-${field.name}`}
                name={field.name}
                type={field.type}
                required
                aria-describedby={field.hint ? `${uid}-back-in-stock-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}-back-in-stock-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>
  )
}

Before you paste

  • Styling is Tailwind utility classes on semantic tokens (bg-card, text-muted-foreground) — it inherits your theme instead of overriding it.
  • Nothing to install. No component library, no icon package.
  • Every prop has a default, so it renders standalone before you wire it up.

Where it goes

Drop it at components/back-in-stock-form.tsx and import it where you need the section:

import { BackInStockForm } from '@/components/back-in-stock-form'

Customize

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.

Props

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.

PropTypeDefault
headingstring"Tell me when it is back"
introstring—
submitLabelstring"Notify me"
onSubmitCalled with the collected values. Resolve to accept, throw to reject.(values: Record<string, string>) => Promise<void> | void—
classNamestring—

Not using React?

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.

back-in-stock-form.html
<!--
  Back In Stock 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_-back-in-stock-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_-back-in-stock-form-heading" class="text-xl font-semibold tracking-tight text-card-foreground">Tell me when it is back</h2>
    <p class="mt-2 text-sm text-muted-foreground">A sold-out product page with a greyed-out button is a dead end and a lost address. One field turns it into the only useful thing left on the page.</p>
    <form class="mt-6 space-y-4">
      <div>
        <label for="_R_0_-back-in-stock-form-email" class="block text-sm font-medium text-foreground">Email</label>
        <input id="_R_0_-back-in-stock-form-email" type="email" required="" aria-describedby="_R_0_-back-in-stock-form-email-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="email" />
        <p id="_R_0_-back-in-stock-form-email-hint" class="mt-1 text-xs text-muted-foreground">One message when it restocks. This is not a reservation — stock is first come.</p>
      </div>
      <div>
        <label for="_R_0_-back-in-stock-form-size" class="block text-sm font-medium text-foreground">Size</label>
        <input id="_R_0_-back-in-stock-form-size" type="text" required="" aria-describedby="_R_0_-back-in-stock-form-size-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="size" />
        <p id="_R_0_-back-in-stock-form-size-hint" class="mt-1 text-xs text-muted-foreground">Only that size triggers the alert. Leave blank for any.</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">Notify me</button>
      <p role="status" aria-live="polite" class="min-h-5 text-sm text-muted-foreground"></p>
    </form>
  </div>
</section>
  • This is rendered HTML, not a translation of the React source. The Tailwind classes carry the design and work in any framework.
  • It is one frame: the component in its initial state, with no props applied beyond the defaults.
  • This block is interactive in React — toggles, menus or form state. None of that survives here; the markup is the closed/default state and the handlers are gone. Re-wire them in your own framework.
  • Requires Tailwind, and the design tokens the classes reference (bg-card, text-muted-foreground, and so on). The template ZIPs ship a globals.css that defines them.

What each framework gets across the whole catalog — effects convert properly; this rung is markup.

For AI

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.

See the prompt

Used in these pages

Want the whole screen instead of this one section? Open a page and copy it entire.

6 more blocks in Product Detail

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 Product Detail

Shipping one commercially

Copying the code is free. Putting it in client work or a paid product is what Pro is for — the licence, not the access.

  • A commercial licence for everything in the catalog
  • Unlimited bundle exports, in Vue, Svelte and Tailwind
  • One payment — no subscription, nothing to renew
Pro — $79 once

More Product Detail blocks

View category
Open the full page for this block

Variant & Add-to-Cart Box

Price, variant radiogroup, quantity stepper and add-to-bag — with sold-out sizes disabled and visible rather than hidden.

Product Detail347 lines1 dep
Open the full page for this block

Product Details Accordion

Description, materials, delivery and returns in named <details> elements — no JavaScript, and the copy stays indexable while collapsed.

Product Detail156 lines1 dep
Open the full page for this block

Rating Distribution Summary

Average rating with a clickable histogram — because a 4.3 of forties and fives is a different product from a 4.3 of ones and fives.

Product Detail126 lines1 dep
Open the full page for this block

Size Guide

The panel that decides whether the parcel comes back: what the model is wearing and what previous buyers did, above a table whose inches are converted rather than maintained twice.

Product Detail227 lines1 dep
Open the full page for this block

Product Spec Split

The specification table beside the product image, with the two or three figures that decide the purchase pulled out of it.

Product Detail159 linesNo deps