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

Popup

ProNew

A promo popup as a split photo/form modal, left or right slide-in panel, corner card or countdown banner, opened by delay, scroll depth or exit intent.

Installation

pnpm dlx shadcn@latest add @viewport/popup

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
layout"modal" | "side" | "corner" | "banner"

`modal` is a centred dialog, `side` a slide-in panel, `corner` a small pinned card, `banner` a bar along the top or bottom.

"modal"
openboolean

Controlled visibility.

—
defaultOpenboolean

Initial visibility when uncontrolled.

false
onOpenChange(open: boolean) => void

Called when the popup opens by a trigger or is closed.

—
returnFocusHTMLElement | null

Element to refocus on close when a controlled popup opens after its previous focus target was removed.

—
triggerPopupTrigger

Opens the popup by itself; the first condition that is met wins.

—
frequency"always" | "session" | "once"

How often a visitor sees it once dismissed: every time, once per browser session, or once ever.

"always"
storageKeystring

Storage key used to remember a dismissal.

"viewport-popup"
containerHTMLElement | null

Render inside this element instead of over the page. The popup is placed against it, scroll depth and exit intent are read from it, and the modal layout no longer traps focus or locks scrolling. Meant for previews and embedded frames; the element must be positioned.

—
position"bottom-left" | "bottom-right" | "top-left" | "top-right" | "bottom" | "top"

Corner for the `corner` layout; `top` or `bottom` for the banner.

—
title*string

Headline.

—
eyebrowstring

Small line above the headline.

—
descriptionstring

Text under the headline.

—
logoReact.ReactNode

Logo shown above the headline.

—
imagestring

Photo: half of the modal, the top of the corner card, a thumbnail in the banner.

—
imageAltstring

Alt text for the photo; leave empty when it is decorative.

""
imageSide"left" | "right"

Side of the photo in the modal on wide screens.

"left"
fieldsPopupField[]

Form fields. With none, the button is a plain call to action.

[]
ctastring

Button label.

—
hrefstring

Makes the call to action a link. Ignored when there are fields.

—
onCta() => void

Called when the call to action is pressed and there are no fields. The popup then closes.

—
onSubmit(values: Record<string, string>) => void | Promise<void>

Called with the field values. Return a promise to show the busy state; reject to show `errorText`.

—
dismissLabelstring

Text button under the form that closes the popup, for example "No, thanks".

—
codestring

Coupon code shown in a box with a copy button.

—
codeLabelstring

Caption above the coupon code.

"Your coupon code"
countdownDate | number | string

Deadline for the countdown: a Date, a timestamp or a date string.

—
countdownLabelstring

Caption above the countdown.

—
expiredTextstring

Shown in place of the countdown once the deadline has passed.

"This offer has ended."
onExpire() => void

Called once when the countdown reaches zero.

—
successTitlestring

Heading shown after a successful submission.

"You're in!"
successTextstring

Text shown after a successful submission.

"Check your inbox for the details."
errorTextstring

Message shown when `onSubmit` fails.

"Something went wrong. Please try again."
closeLabelstring

Name of the close button, also the label of the button under the success message.

"Close"
tone"auto" | "dark" | "accent"

Surface: `auto` follows the theme, `dark` is always dark, `accent` fills the popup with the accent color.

"auto"
accentstring

Brand color for the button, or the surface when `tone` is `accent`.

"#1f4bff"
buttonColorstring

Button fill; defaults to the accent, or near black on an accent surface.

—
buttonTextColorstring

Button text color.

"#fff"
shape"rounded" | "square"

`rounded` uses soft corners and pill fields, `square` uses sharp ones.

"rounded"
closeOnOverlayboolean

Close the modal when the backdrop is pressed.

true
classNamestring—

Accessibility

  • Full-page modals and side panels are Radix dialogs: focus is trapped, the page behind is hidden from screen readers, Escape closes and focus returns to the opener or supplied returnFocus element.
  • The corner card and banner are labelled non-modal dialogs that never take focus; a live region reads the headline when they arrive.
  • Fields are labelled, a bad value is marked aria-invalid with its own role=alert message, and focus moves to the first one.
  • While sending the button is aria-busy; the success heading takes focus so the result is read at once.
  • The countdown is a role=timer with the time left as its name; paired panel/backdrop timing runs only when motion is allowed.