suiss/uim · React Native Component

Alert

A callout that shows a short message with an optional icon and action.

Alert is an open-source mobile component from suiss/uim for React Native and Expo, with SwiftUI and Jetpack Compose versions built from the same design tokens. The @esuiss/uim CLI copies its source into your project, so you own the code.

iOS
Alert on iOS in light mode

Alert is a View on a rounded secondary surface with an optional leading icon, a title and description column, and an optional action pinned to the top-end corner. It is static and stays in the layout; it is not a toast or a modal.

Use the default variant for neutral information, where the icon uses the accent color, and destructive for errors, where the icon uses the danger color.

Installation

$ pnpm dlx @esuiss/uim@latest add alert

The CLI also adds what it builds on: Icon, Text.

Manual

  1. Install the dependencies:
npx expo install cn phosphor-react-native react-native-svg
  1. Add the pieces it builds on: Icon, Text.

  2. Copy the source into components/ui/alert.tsx:

uniwind/components/ui/alert.tsx
import { cn } from "cn"
import type { Icon as PhosphorIcon } from "phosphor-react-native"
import * as React from "react"
import { View } from "react-native"
import { Icon } from "@/components/ui/icon"
import { Text, TextClassContext } from "@/components/ui/text"

function Alert({
  className,
  variant = "default",
  children,
  icon,
  iconClassName,
  ...props
}: React.ComponentProps<typeof View> &
  React.RefAttributes<View> & {
  1. Update the import paths to match your project.

Usage

import { Alert, AlertTitle, AlertDescription, AlertAction } from "@/components/ui/alert"
<Alert icon={CheckCircleIcon}>
  <AlertTitle>Payment successful</AlertTitle>
  <AlertDescription>
    Your payment of $29.99 has been processed. A receipt has been sent to
    your email.
  </AlertDescription>
</Alert>

Pass a Phosphor icon component to icon, and compose AlertTitle and AlertDescription as children. Any AlertAction child is detected and placed in the corner, and extra end padding is added so the text does not run under it.

Use iconClassName to adjust the icon's size or color.

Examples

Destructive

The destructive variant with a danger-colored icon.

iOS
Alert (destructive) on iOS in light mode

Title only

An alert with only a title.

iOS
Alert (title only) on iOS in light mode

With action

An AlertAction button in the top-end corner.

iOS
Alert (with action) on iOS in light mode

Without icon

An alert with text only and no icon.

iOS
Alert (without icon) on iOS in light mode

API Reference

Alert

Container with the icon, text column and action.

ExtendsReact.ComponentProps<typeof View>React.RefAttributes<View>
PropType
About
Phosphor icon component shown before the text.
Type
PhosphorIcon
Default
—
About
default or destructive; changes the icon color.
Type
"default""destructive"
Default
"default"
About
Extra classes for the icon.
Type
string
Default
—

AlertTitle

Bold first line.

ExtendsReact.ComponentProps<typeof Text>

AlertDescription

Secondary-colored supporting text.

ExtendsReact.ComponentProps<typeof Text>

AlertAction

Slot positioned in the top-end corner.

ExtendsReact.ComponentProps<typeof View>React.RefAttributes<View>

Accessibility

  • The container has the alert role.
  • The icon is decorative; put the meaning in the title or description.

Notes

  • Uses bg-surface-secondary, text-label, text-accent and text-danger tokens; light and dark follow the system appearance.
  • The action is positioned with end-4, so it flips in right-to-left layouts.