ZUI

Search documentation

Find a page or a heading.

Alert

A box that calls attention to a message, with an optional icon and action.

Installation

bash

The CLI writes components/ui/alert.tsx, installs Text, Icon and Utils, and adds class-variance-authority.

Usage

tsx
tsx

API reference

Alert

Takes every prop of React Native's View, plus:

It carries the alert role. An Icon placed as a direct child is drawn at 16px beside the title and description, in the colour of the variant's text. destructive draws the title, the description and the icon in the destructive colour.

AlertTitle, AlertDescription

Each takes every prop of Text. The title is the medium-weight line, and the description is muted, or destructive in a destructive Alert.

AlertAction

Takes every prop of React Native's View. It is pinned to the top right of the Alert, and the Alert's text keeps clear of it.

Differences from upstream

  • Upstream lays the alert out as a grid that puts an icon in a first column. Neither engine draws a grid, so the native Alert finds an Icon among its direct children and sets it in a row beside a column holding the rest. Pass the Icon, the title, the description and the action as direct children for that to work.
  • Upstream nudges the icon 2px down to line up with the title. The native icon sits at the top of the row.
  • Upstream's alert is a live region that a screen reader reads as soon as it appears. React Native's alert role names the box but does not announce it, and the box is not grouped into one element, so a screen reader still reaches its action.
  • text-balance on the description has no React Native counterpart and is dropped.