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

Contact Form

ProNew

Name, email, phone and message with real validation and a confirmation, shown inline, in a side pane behind a floating button, or beside your contact details.

Installation

pnpm dlx shadcn@latest add @viewport/contact-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
onSubmit*(values: ContactFormValues) => void | Promise<unknown>

Called with the values once they pass validation. Return a promise to show the sending state; reject with an `Error` to show its message above the button.

—
layout"inline" | "floating" | "split"

`inline` sits in the page, `floating` is a corner button that opens a side pane, `split` puts your details beside the form.

"inline"
fieldStyle"outline" | "filled" | "underline"

Look of the inputs: bordered boxes, soft filled pills, or a single underline.

"outline"
titlestring"Get in touch"
descriptionstring"Leave your message and we'll get back to you shortly."
fieldsContactField[]

Which fields to show, in a fixed order.

ORDER
requiredContactField[]

Fields that cannot be left empty.

["email", "message"]
maxLengthnumber

Longest message accepted; a counter appears as it fills up.

1000
submitLabelstring"Send"
accentstring

Any CSS color, for the button, focus rings and the split panel.

"#1672f3"
successTitlestring"Message sent"
successMessagestring"Thanks for reaching out. We'll reply within one business day."
errorMessagestring

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

"We couldn't send your message. Please try again."
launcherLabelstring

Accessible name and tooltip of the floating button.

"Contact us"
detailsContactDetail[]

Rows for the side panel of the `split` layout: address, phone, hours.

[]
disabledbooleanfalse
classNamestring—

Accessibility

  • Every input has a visible label; errors are tied to their field with aria-describedby and focus jumps to the first one.
  • A live region says how many fields need attention, then announces sending and success.
  • The floating pane is a dialog: it traps focus, closes on Escape and returns focus to the button.
  • The confirmation takes focus when it replaces the form, and “Send another message” brings the form back.
  • The pane slides and the check draws only when motion is allowed.