suiss/ui · Component
Alert
A static callout that draws attention to an important message without interrupting the user.
Alert is an open-source component from suiss/ui for React, React Native, SwiftUI and Jetpack Compose. The @esuiss/ui CLI copies its source into your project, so you own the code.
An Alert is a rounded container with an optional leading icon, an AlertTitle, an optional AlertDescription and an optional AlertAction. Place the icon as a direct child; the layout switches to a two-column grid so the title and description align beside it.
Use an alert for inline, persistent messages such as updates, warnings or errors. To interrupt the user and require a decision, use Alert Dialog instead; for short-lived notifications, use Toast.
Installation
Works in any project with a components.json. See Installation for the one-line registry setup. Or use the suiss/ui CLI:
- Install the following dependencies and add the
cnhelper:
- Copy and paste the following code into your project.
- Update the import paths to match your project setup.
Usage
Composition
Use the following composition to build a Alert:
Examples
Destructive
Set variant="destructive" to tint the icon with the destructive color for errors.
Without icon
Leave out the icon for a title and description only.
Title only
Leave out AlertDescription for an icon with a single line of text.
With action
Put a small button in an AlertAction to place it in the top-end corner.
Accessibility
Alertrenders withrole="alert", so assistive technology announces its content when it appears.- Interactive content in
AlertActionstays in the normal tab order. - Decorative icons should not need a label; put the meaning in the title text.
API Reference
Alert
The container that lays out the icon, text and action.
| Prop | Type | Default |
|---|---|---|
variant | "default" | "destructive" | "default" |
Also accepts the props of React.ComponentProps<"div">.
Put an icon from your icon library, or any svg, first inside Alert; it is sized to size-5 unless it already has a size class. When AlertDescription is present the icon spans both rows. Both variants use bg-muted and differ only in icon color: default uses text-primary and destructive uses text-destructive. Links inside the title or description are underlined automatically.
AlertTitle
The bold headline of the message.
Also accepts the props of React.ComponentProps<"div">.
AlertDescription
Secondary text that explains the message.
Also accepts the props of React.ComponentProps<"div">.
AlertAction
An absolutely positioned slot for a button or link in the top-end corner.
Also accepts the props of React.ComponentProps<"div">.
The alert reserves end padding for the action automatically. Each part sets a data-slot, such as alert-title or alert-action, for styling.
Web preview
Alert is a View on a rounded bg-muted 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 primary color, and destructive for errors, where the icon uses the destructive color.
Installation
-
Target iOS 17 or later.
-
Add the Swift package to your app:
- Copy the theme files every view uses:
- Copy the source:
- Add the files to your app target.
- Apply the Compose compiler plugin, enable Compose, set
compileSdkto 37 or higher andminSdkto 24 or higher, and add the dependencies:
- Copy the theme files every view uses:
- Copy the source and every file it uses:
- Update the
com.esuiss.uipackage names to match your project.
Usage
Examples
Destructive
Set variant to destructive to color the icon with the destructive color.
Web preview
Title only
Leave out the description for an alert with only a title.
Web preview
With action
Put a button in an AlertAction to pin it to the top-end corner.
Web preview
Without icon
Leave out the icon for an alert with text only.
Web preview
Accessibility
- The container has the
alertrole. - The icon is decorative; put the meaning in the title or description.
API Reference
Alert
Container with the icon, text column and action.
| Prop | Type | Default |
|---|---|---|
icon | PhosphorIcon | - |
variant | "default" | "destructive" | "default" |
iconClassName | string | - |
Also accepts the props of React.ComponentProps<typeof View>, React.RefAttributes<View>.
Pass a Phosphor icon component to icon to show it before the text, and use iconClassName to adjust its size or color. variant changes the icon color. Compose AlertTitle and AlertDescription as children.
AlertTitle
Bold first line.
Also accepts the props of React.ComponentProps<typeof Text>.
AlertDescription
Secondary-colored supporting text.
Also accepts the props of React.ComponentProps<typeof Text>.
AlertAction
Slot positioned in the top-end corner.
Also accepts the props of React.ComponentProps<typeof View>, React.RefAttributes<View>.
Any AlertAction child is detected and placed in the corner, and extra end padding is added so the text does not run under it. The action is positioned with end-4, so it flips in right-to-left layouts.
InlineAlert
| Parameter | Type | Default |
|---|---|---|
_ variant | Variant: .default | .destructive | .default |
icon | Image? | nil |
content | () -> Content | - |
action | () -> Action | - |
Overloads: init(_:icon:content:action:), init(_:icon:content:).
AlertTitle
Bold first line.
| Parameter | Type | Default |
|---|---|---|
_ title | LocalizedStringKey | - |
AlertDescription
Secondary-colored supporting text.
| Parameter | Type | Default |
|---|---|---|
_ description | LocalizedStringKey | - |
AlertVariant
Values: Default, Destructive.
Alert
Container with the icon, text column and action.
| Parameter | Type | Default |
|---|---|---|
modifier | Modifier | Modifier |
variant | AlertVariant: Default | Destructive | AlertVariant.Default |
icon | ImageVector? | null |
action | (@Composable () -> Unit)? | null |
content | @Composable ColumnScope.() -> Unit | - |
AlertTitle
Bold first line.
| Parameter | Type | Default |
|---|---|---|
text | String | - |
modifier | Modifier | Modifier |
AlertDescription
Secondary-colored supporting text.
| Parameter | Type | Default |
|---|---|---|
text | String | - |
modifier | Modifier | Modifier |