Components
Alert
Present a short message that requires attention or a decision.
Example
Requires React 18.2+ or 19 and shared styles. See setup.
Default
Loading preview…
Code
'use client';
import { useState } from 'react';
import { Button } from '@swiftuijs/ui';
import { Alert } from '@swiftuijs/ui';
function DefaultAlert() {
const [isVisible, setIsVisible] = useState(false);
return (<>
<Button onClick={() => setIsVisible(true)}>Show Alert</Button>
<Alert title="Alert" message="This is an alert message" isVisible={isVisible} onDismiss={() => setIsVisible(false)}/>
</>);
}
export default function Example() {
return (<DefaultAlert />);
}Simple Alert
Alert without a message:
Usage and limitations
- Control visibility with
isVisibleand close fromonDismiss. - Buttons support
default,cancel, anddestructivestyles. Use descriptive labels and mark dangerous actions as destructive. - The shared modal traps focus, isolates the background and restores focus on closing. Check keyboard dismissal and labeling in your composition.
- The alert stays inside the available viewport and scrolls when text grows or the screen is short. Keep messages concise; use a Sheet for longer tasks.
More examples
Simple Alert
With Custom Buttons
With Multiple Buttons
Warning Alert
API reference
| Prop | Type | Required | Description |
|---|---|---|---|
title | string | Yes | The title of the alert. |
message | string | No | The message body of the alert. |
isVisible | boolean | Yes | Whether the alert is visible. |
onDismiss | () => void | Yes | Callback fired when the alert should be dismissed. |
buttons | IAlertButton[] | No | The buttons to display in the alert. |
Inherits additional props from IBaseComponent.