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 isVisible and close from onDismiss.
  • Inherits the UIProvider glass toggle and intensity with regular material for legibility. Use glass={false} for an opaque local override. Accessibility preferences and unsupported browsers restore an opaque surface.
  • Buttons support default, cancel, and destructive styles. 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

PropTypeRequiredDescription
glassGlassPreferenceNoOptional material override; inherits UIProvider with the legible regular variant.
titlestringYesThe title of the alert.
messagestringNoThe message body of the alert.
isVisiblebooleanYesWhether the alert is visible.
onDismiss() => voidYesCallback fired when the alert should be dismissed.
buttonsIAlertButton[]NoThe buttons to display in the alert.

Inherits additional props from IBaseComponent.