SwipeUI

Dialog

Ask for a decision with clear primary and secondary actions, including pending and retry states.

npx @swipeui/cli add dialog
Variant
Preset
Material
Scheme
Feel
Real free component with a browser animation bridge. Native motion, haptics and materials need a device.

When to use it

  • Confirming important actions, such as Delete project? or Sign out?
  • Short decisions with two or three clear options.
  • Errors that must be acknowledged before continuing.
  • Actions that run on a server and should keep the dialog open if they fail.

When not to use it

  • Non-blocking messages. Use Toast or Alert.
  • Lists of actions. Use Action sheet.
  • Forms or long content. Use Sheet.

Installation

Run this from your app's root. If SwipeUI isn't set up yet, run npx @swipeui/cli init first; it sets up Uniwind, the theme tokens and the cn helper.

npx @swipeui/cli add dialog
  • Adds components/swipeui/overlay/dialog.tsx and 11 shared helpers.
  • Installs react-native-reanimated, react-native-worklets, uniwind, clsx, tailwind-merge, expo-haptics, class-variance-authority, react-native-gesture-handler, react-native-safe-area-context. In Expo apps it uses npx expo install so versions match your SDK.

Setup

Place OverlayProvider inside SafeAreaProvider near the application root. Register OverlayScope inside each native modal screen or native sheet content. Root absolute views alone cannot establish layering across native windows. Native cross-window presentation remains unverified.

Usage

app/route.tsx
import { Dialog } from '@/components/swipeui/overlay/dialog';

<Dialog
  title="Remove saved route?"
  triggerLabel="Remove"
  actions={[
    { id: 'remove', label: 'Remove', destructive: true },
    { id: 'cancel', label: 'Cancel' },
  ]}
/>;

API reference

PropTypeDefaultDescription
titlestring—

Visible title and initial accessibility focus.

description?string—

Supporting message.

icon?ReactNode—

Optional decorative icon for the subject of the dialog.

children?ReactNode—

Optional body, such as an input field or the terms scroll region.

contentAlign?"center" | "start"'center'

Position body copy and the inline footer.

showClose?booleanfalse

Display the optional close control in the header.

closeStyle?"plain" | "tinted"'tinted'

Use a plain corner control.

initialFocusRef?OverlayFocusRef—

Optional field or control to focus when the dialog opens. Defaults to the heading.

secondaryVariant?"ghost" | "outline"'ghost'

Secondary action appearance.

pillActions?booleanfalse

Render actions as capsules.

fixedActions?booleanfalse

Keep the header and actions outside a caller-provided scroll region.

backdropContent?ReactNode—

Optional custom visual backdrop. Outside dismissal continues to work.

clearBackdrop?booleanfalse

Hide the dim surface so a custom backdrop is visible.

actionsreadonly DialogAction[]—

Actions; successful completion closes the dialog.

presentation?"alert" | "sheet"'alert'

Surface location; ActionSheet uses sheet.

materialTone?ThemeSurfaceTone—

Semantic Glass tint for the panel.

tone?"ios" | "material"'ios'

Native visual convention.

open?boolean—

Controlled visibility.

defaultOpen?booleanfalse

Initial visibility.

onOpenChange?((open: boolean) => void)—

Reports visibility intent.

triggerLabel?string—

Optional built-in trigger.

triggerStyle?"plain" | "tinted"'plain'

Built-in trigger appearance.

actionLayout?"inline" | "stacked"'stacked'

Action arrangement.

dismissible?booleantrue

Permit backdrop/back/escape dismissal.

primaryActionId?string—

Action emphasized in the dialog. Defaults to the first enabled action.

messages?{ pending?: string; actionError?: string; close?: string; }—

Localized submission and failure text.

onActionError?((error: unknown) => void)—

Error handler; operations are never logged.

disabled?boolean—

Disable trigger/actions.

haptics?boolean—

Action feedback.

motion?MotionOverride—

Shared overlay/press character.

className?string—

Trigger wrapper classes.

testID?string—

Root identifier.

Composition and behavior

  • title and description above actions, each with an id, label, onPress, destructive and disabled.
  • presentation is alert or sheet; tone is ios or material; actionLayout is stacked or inline.
  • triggerLabel adds a built-in button; or control with open and onOpenChange.
  • dismissible controls backdrop and back dismissal.

Use primaryActionId for the action to emphasize. A rejected callback leaves the dialog open with an inline message. Set messages.pending and messages.actionError to localize progress and retry guidance.

Composing a dialog

SettingBehavior
children, iconAdd an input, a fixed-height scroll region or a decorative icon.
contentAlign, pillActions, secondaryVariantChoose leading or centred copy, capsule actions, and a ghost or outlined secondary action.
fixedActions, showCloseKeep the header and actions outside a scrollable body and optionally show an accessible close icon.
backdropContent, clearBackdropPaint an optional backdrop layer and choose whether to show the default dim scrim. Respect Reduce Transparency in an app-provided blur layer.
triggerStyleUse the plain or tinted built-in trigger.

For a destructive input confirmation, hold the draft in the caller and disable Delete until the phrase matches exactly. Pass the input ref through initialFocusRef when the confirmation should open with the keyboard. For long terms, use closeStyle="plain" to simplify the header and keep the agree action outside the scroll region. Each action can override variant, size, className and textClassName.

Behavior and gestures

  • Opens over the screen with a dimmed backdrop.
  • Tap an action to run it; the dialog closes when it succeeds and stays open if it fails.
  • While an action runs, other actions and dismissal are blocked.
  • Tap the backdrop, press back or use the escape gesture to dismiss, unless dismissible is false.
  • Actions stack vertically by default or sit side by side with actionLayout="inline".

Accessibility

  • Focus moves to the title when it opens and returns when it closes.
  • Only the top dialog is accessible; a dialog on top of another hides the one below.
  • Each action is a named button; destructive actions look destructive and should say what they do, like "Delete project".
  • Errors are passed to onActionError and never logged.

Motion

  • Uses the press and overlay motion roles, so it follows your app's feel. Pass motion to tune this one instance.
  • Opens and closes with the overlay role.
  • Reduce Motion uses a short fade.

Performance

  • Nothing is rendered while closed.

Notes for AI

  • Return a promise from onPress for async actions; give every action an id and label.

Compatibility

Runs onSupported
Expo SDK 57Yes
Expo SDK 58Yes
React Native CLI (with Expo modules)Yes
Expo GoYes
iOSYes
AndroidYes

This table describes API support and static bundle checks. Native runtime, device accessibility and bare Uniwind compatibility remain pending.

Related items