Alert informs users about important events or status messages. Supports multiple colors, variants, and optional icons.
Basic Usage
Alerts with different colors and icons.
await import('/components/data-display/alert.js');
const { tags, $ } = Lightview;
const { div, span, Alert } = tags;
const alerts = div({ style: 'display: flex; flex-direction: column; gap: 1rem;' },
Alert({ color: 'info', icon: 'info' },
span({}, 'New update available! Click to learn more.')
),
Alert({ color: 'success', icon: 'success' },
span({}, 'Your order has been placed successfully!')
),
Alert({ color: 'warning', icon: 'warning' },
span({}, 'Please review your information before proceeding.')
),
Alert({ color: 'error', icon: 'error' },
span({}, 'Unable to connect to server. Please try again.')
)
);
$('#example').content(alerts);
Dismissible Alert
Alert with close button using signals.
await import('/components/data-display/alert.js');
await import('/components/actions/button.js');
const { signal, tags, $ } = Lightview;
const { div, span, Alert, Button } = tags;
const visible = signal(true);
const demo = div({},
() => visible.value
? Alert({ color: 'success', icon: 'success' },
span({}, 'Message sent successfully!'),
Button({
size: 'sm',
color: 'ghost',
onclick: () => { visible.value = false; }
}, '✕')
)
: div({ style: 'display: flex; gap: 0.5rem;' },
span({ style: 'font-size: 0.875rem; opacity: 0.5;' }, 'Alert dismissed'),
Button({
size: 'sm',
color: 'primary',
onclick: () => { visible.value = true; }
}, 'Show again')
)
);
$('#example').content(demo);
Props
| Prop | Type | Default | Description |
|---|---|---|---|
color |
string | - | 'info' | 'success' | 'warning' | 'error' |
icon |
string | - | Auto-icon: 'info' | 'success' | 'warning' | 'error' |
soft |
boolean | false | Use soft/light background variant |
outline |
boolean | false | Use outlined border style |
dash |
boolean | false | Use dashed border style |
Colors
Default alert — neutral information message.
Info alert — informational message.
Success alert — operation completed successfully.
Warning alert — caution is advised.
Error alert — something went wrong!
Variants
Soft variant — lighter background.
Outline variant — bordered style.
Dash variant — dashed border.
With Actions
We have sent an email with a confirmation link.