Skip to content
ProLifetime access for $199, paid once, every future release included
Truffle UI

Subscription Form

ProNew

Email capture as a card, an inline row, a full-width bar or a picture split, with loading, success and error states built in.

Installation

pnpm dlx shadcn@latest add @viewport/subscription-form

First time? Add the @viewport registry to components.json. Setup takes one minute.

Usage

The code behind the preview above comes with Truffle Pro.

Props

PropTypeDefault
onSubscribe*(subscriber: Subscriber) => void | Promise<unknown>

Called with the address once it passes validation. Return a promise to show the loading state; reject with an `Error` to show its message under the field.

—
layout"inline" | "card" | "bar" | "split"

`inline` is a field and button in a row, `card` a centered card, `bar` a full-width strip, `split` a picture beside the form.

"card"
titlestring"Subscribe to our newsletter"
descriptionstring—
askNameboolean

Ask for a first name above the email.

false
placeholderstring"Enter your email here..."
buttonLabelstring"Subscribe"
notestring

Small print under the form, such as “No spam. Unsubscribe anytime.”

—
consentReact.ReactNode

Adds a required checkbox with this label, for consent to your terms.

—
imagestring

Picture for the `split` layout.

—
imageAltstring""
imageSide"left" | "right"

Side of the picture on wide containers. It always stacks on top on phones.

"left"
accentstring

Any CSS color, for the button and focus ring.

"#1672f3"
successTitlestring"You're on the list"
successMessagestring"Check your inbox to confirm your address."
errorMessagestring

Shown when `onSubscribe` rejects without a message of its own.

"Something went wrong. Please try again."
onDismiss() => void

With `layout="bar"`, shows a close button and calls this when it is pressed.

—
disabledbooleanfalse
classNamestring—

Accessibility

  • Every field has a real label, visible in the card and split layouts and for screen readers only in the compact ones.
  • Validation runs on submit: the message is tied to the field with aria-describedby, announced as an alert, and focus returns to the field.
  • The button stays focusable while the request runs; loading and success are announced through a live region.
  • On success the confirmation replaces the form and takes focus, so keyboard users are never dropped at the top of the page.
  • The check draws and the error shakes only when motion is allowed.