Alert
Compact or detailed wrapping status with independent pill/cross controls and a pushing banner.
npx @swipeui/cli add alertWhen 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.tsxand 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 installso versions match your SDK.
Usage
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
| Prop | Type | Default | Description |
|---|---|---|---|
preset? | | — | |
title? | | — | |
description? | | | Optional detail; null removes the preset detail. |
tone? | | | Semantic status override. |
compact? | | | Compact title row with a reserved cross slot and no Dismiss pill. |
appearance? | | | Surface treatment. |
outlineTone? | | | Outline follows the title tone or stays neutral. |
accent? | | | Leading semantic accent. |
showIcon? | | | Render the leading icon. |
showTitle? | | | Render the title. |
showDescription? | | | Render supporting content; banners always stay compact. |
icon? | | — | Decorative icon; null also hides it. |
variant? | | | Inline card or a solid compact pushing banner. |
action? | | — | Optional named corrective action. |
onDismiss? | | — | Dismiss callback, shared by the independently enabled controls. |
showDismiss? | | | Show the semantic Dismiss pill when a callback exists. |
showClose? | | | Show a circular cross when a callback exists. |
dismissLabel? | | | Caller-owned wording for the pill and accessible close action. |
contentWidth? | | — | Optional text-column width; title and detail wrap within the same column. |
duration? | | | Banner lifetime in milliseconds; 0 persists. |
visible? | | | Whether visible. |
motion? | | — | Shared overlay/layout/press motion. |
haptics? | | | Action haptics. |
className? | | — | Root classes. |
style? | | — | Native dimensions, padding and layout escape hatch. |
testID? | | — | 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
| Prop | Does / default |
|---|---|
appearance | Surface treatment. @default 'filled' |
accent | Leading semantic accent. @default false |
showDescription | Render supporting content. @default true |
icon | Decorative icon; the title carries its meaning. |
variant | Inline card or top banner. @default 'inline' |
action | Optional named corrective action. |
onDismiss | Shows a dismiss button when supplied. |
visible | Whether visible. @default true |
motion | Shared overlay/layout/press motion. |
className | Root classes. |
style | Native layout escape hatch. |
testID | Root 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.
| Prop | Default | Behavior |
|---|---|---|
compact | false | Center icon/title, hide supporting detail and Dismiss, and reserve a stable cross slot. |
showDismiss | true | Semantic Dismiss pill when onDismiss exists; detailed inline notices only. |
showClose | false | Independent 44pt cross target around a 28pt circle. |
dismissLabel | Dismiss | Caller wording for the pill. The cross is named Close plus the title. |
showIcon | true | Toggle the leading glyph without changing notice meaning. |
showTitle | true | Toggle the title independently of the detail. |
contentWidth | available width | Shared wrapping width of title and detail. |
outlineTone | tone | Match the outline to the title, or use neutral. |
duration | banner 1800, inline 0 | Auto-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,layoutandpressmotion roles, so it follows your app's feel. Passmotionto 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 on | Supported |
|---|---|
| Expo SDK 57 | Yes |
| Expo SDK 58 | Yes |
| React Native CLI (with Expo modules) | Yes |
| Expo Go | Yes |
| iOS | Yes |
| Android | Yes |
This table describes API support and static bundle checks. Native runtime, device accessibility and bare Uniwind compatibility remain pending.