SwipeUI

Alert

Compact or detailed wrapping status with independent pill/cross controls and a pushing banner.

npx @swipeui/cli add alert
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

  • Messages that belong to a screen or section, such as "Your trial ends in 3 days" above a settings list.
  • Form-level errors like "We couldn't save your changes" with a Try again button.
  • Banners at the top of a screen for offline mode or a pending update.
  • Success or warning notes that should stay until people deal with them.

When not to use it

  • Brief confirmations that disappear on their own. Use Toast.
  • Errors for a single field. Use the field's error message.
  • Decisions that block the flow. Use Dialog.
  • Marketing promos; they shouldn't look like system messages.

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 alert
  • Adds components/swipeui/ui/alert.tsx and 13 shared helpers.
  • Installs react-native-reanimated, uniwind, react-native-worklets, clsx, tailwind-merge, expo-haptics, class-variance-authority, react-native-svg, react-native-gesture-handler, react-native-safe-area-context. In Expo apps it uses npx expo install so versions match your SDK.

Usage

app/index.tsx
import { Alert } from '@/components/swipeui/ui/alert';

<Alert title="You are offline" description="Changes will sync when you reconnect." />;

Examples

Use the variant and appearance controls in the live specimen to compare the documented states. The application owns validation, operation results and persistence.

API reference

AlertProps

PropTypeDefaultDescription
preset?union—
title?string—
description?string | nullpreset detail

Optional detail; null removes the preset detail.

tone?FeedbackTonepreset tone or info

Semantic status override.

compact?booleanfalse

Compact title row with a reserved cross slot and no Dismiss pill.

appearance?"filled" | "outline" | "tinted"'filled'

Surface treatment.

outlineTone?"neutral" | "tone"'tone'

Outline follows the title tone or stays neutral.

accent?booleanfalse

Leading semantic accent.

showIcon?booleantrue

Render the leading icon.

showTitle?booleantrue

Render the title.

showDescription?booleantrue

Render supporting content; banners always stay compact.

icon?ReactNode—

Decorative icon; null also hides it.

variant?"banner" | "inline"'inline'

Inline card or a solid compact pushing banner.

action?{ label: string; onPress: () => void; }—

Optional named corrective action.

onDismiss?(() => void)—

Dismiss callback, shared by the independently enabled controls.

showDismiss?booleantrue

Show the semantic Dismiss pill when a callback exists.

showClose?booleanfalse

Show a circular cross when a callback exists.

dismissLabel?string'Dismiss'

Caller-owned wording for the pill and accessible close action.

contentWidth?DimensionValue—

Optional text-column width; title and detail wrap within the same column.

duration?number1800 for banner, 0 for inline

Banner lifetime in milliseconds; 0 persists.

visible?booleantrue

Whether visible.

motion?MotionOverride—

Shared overlay/layout/press motion.

haptics?booleantrue

Action haptics.

className?string—

Root classes.

style?StyleProp<ViewStyle>—

Native dimensions, padding and layout escape hatch.

testID?string—

Root ID.

Native view/input props not listed here pass through where the exported TypeScript type allows them.

Composition and behavior

  • title and optional description, with a decorative icon.
  • variant is inline or banner; tone is info, success, warning or error.
  • action adds a named button; onDismiss adds a dismiss button; visible shows or hides it.

Feedback lineup settings

PropDoes / default
appearanceSurface treatment. @default 'filled'
accentLeading semantic accent. @default false
showDescriptionRender supporting content. @default true
iconDecorative icon; the title carries its meaning.
variantInline card or top banner. @default 'inline'
actionOptional named corrective action.
onDismissShows a dismiss button when supplied.
visibleWhether visible. @default true
motionShared overlay/layout/press motion.
classNameRoot classes.
styleNative layout escape hatch.
testIDRoot ID.

Notice presentations

<Alert preset="offline" /> stays in flow. variant="banner" pushes following content down. compact creates a centered, wrapping compact notice. appearance="tinted" and accent are independent. Presets include offline, maintenance, load-failed, server-unreachable, timeout, slow-request and saved. Override text for your app.

AlertDialog accepts the same preset/text with Dialog's open, onOpenChange and actions. Presentation is explicit; length never opens a modal. For floating notices use Toast; for one action use Snackbar, including View details opening a dialog.

Action haptics can be disabled independently with haptics={false} (default true).

Dismiss controls and pushing banners

The title and detail share one wrapping column. contentWidth bounds that column; style controls the card's width or height. The leading icon and title retain their top anchors for detailed notices, while compact notices center the icon and title together.

PropDefaultBehavior
compactfalseCenter icon/title, hide supporting detail and Dismiss, and reserve a stable cross slot.
showDismisstrueSemantic Dismiss pill when onDismiss exists; detailed inline notices only.
showClosefalseIndependent 44pt cross target around a 28pt circle.
dismissLabelDismissCaller wording for the pill. The cross is named Close plus the title.
showIcontrueToggle the leading glyph without changing notice meaning.
showTitletrueToggle the title independently of the detail.
contentWidthavailable widthShared wrapping width of title and detail.
outlineTonetoneMatch the outline to the title, or use neutral.
durationbanner 1800, inline 0Auto-dismiss lifetime; zero persists.

A banner is always compact, solid and parent width, with minimal padding, a smaller glyph/title and a neutral close circle. The cross keeps its 44pt target. Compact and banner rows reserve the close slot even while its cross is hidden. Put it directly beneath the screen header in normal flow: its animated height pushes and releases the content below. For replacement notices, hide the old notice, wait for the overlay exit duration, then change the content and reveal it. The shared app/web example demonstrates this ordering. Use onDismiss to keep application visibility in sync with expiration.

Banner text is bold and its status/close glyphs use heavier strokes. The success banner uses white lettering in light mode to match the other semantic banners. Its neutral close circle remains independent of the status colour. Inline notice and semantic Dismiss colours retain their existing treatment.

Behavior and gestures

  • Shows inline in the page or as a banner; it animates in and out when visible changes.
  • An optional action button runs a fix, such as Retry or Update.
  • A dismiss button appears when you pass onDismiss.
  • Buttons are separate from the message, so tapping the text does nothing.

Accessibility

  • New messages are announced automatically: errors right away, other tones once the screen reader finishes what it's saying.
  • The icon is decorative; the title carries the meaning, so tone never relies on colour alone.
  • The dismiss button is named "Dismiss <title>".
  • Action and dismiss are separate focus stops.

Motion

  • Uses the overlay, layout and press motion roles, so it follows your app's feel. Pass motion to tune this one instance.
  • Enters and leaves with the overlay role; the page around it re-flows with the layout role.
  • Reduce Motion uses a short fade.

Performance

  • Mounted only while visible.

Notes for AI

  • Write the meaning into title, such as "Payment failed", not just the tone.

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