Alerts communicate important information without interrupting the user’s workflow.
Setup
<script lang="ts">
import { Alert } from '.';
</script> Default alert
Info alert! Change a few things up and try submitting again.
Danger alert! Change a few things up and try submitting again.
Success alert! Change a few things up and try submitting again.
Warning alert! Change a few things up and try submitting again.
Dark alert! Change a few things up and try submitting again.
<script lang="ts">
import { Alert } from '.';
</script>
<Alert>
<span class="font-medium">Info alert!</span> Change a few things up and try submitting again.
</Alert>
<Alert color="red">
<span class="font-medium">Danger alert!</span> Change a few things up and try submitting again.
</Alert>
<Alert color="green">
<span class="font-medium">Success alert!</span> Change a few things up and try submitting again.
</Alert> Bordered alert
Info alert! Change a few things up and try submitting again.
<Alert border color="blue">
<span class="font-medium">Info alert!</span> Change a few things up and try submitting again.
</Alert> Alert with icon
Success! Your changes have been saved.
<script lang="ts">
import { Alert } from '.';
</script>
<Alert color="green">
{#snippet icon()}
<svg class="h-4 w-4" fill="currentColor" viewBox="0 0 20 20"><!-- check icon --></svg>
{/snippet}
<span class="font-medium">Success!</span> Your changes have been saved.
</Alert> Dismissable alert
Info alert! Click the close icon to dismiss.
<Alert dismissable>
<span class="font-medium">Info alert!</span> Click the close icon to dismiss.
</Alert> Colors
Theme color tokens: primary, secondary, gray, red, orange, amber, yellow, lime, green, emerald, teal, cyan, sky, blue, indigo, violet, purple, fuchsia, pink, rose.
Composition notes
- Default content goes in
children. Pass aniconsnippet for a leading graphic; dismissable alerts lay out as a flex row. - Bind
alertStatuswhen you need programmatic show/hide; dismiss sets it tofalsewith the configured transition.
Props
AlertProps
| Prop | Type | Default | Description |
|---|---|---|---|
children | Snippet | — | Alert message content |
color | primary | secondary | gray | red | orange | amber | yellow | lime | green | emerald | teal | cyan | sky | blue | indigo | violet | purple | fuchsia | pink | rose | primary | Theme color |
rounded | boolean | — | Rounded corners (rounded-lg) |
border | boolean | — | Show border (color-matched) |
dismissable | boolean | — | Show close control |
alertStatus | boolean | true | Bindable visibility |
icon | Snippet | — | Leading icon |
closeIcon | Component | — | Custom close icon component |
transition | TransitionFunc | — | Dismiss transition |
params | ParamsType | — | Transition params |
onclick | () => void | — | Click handler on the alert |
class | ClassValue | — | Extra classes |
…rest | div attrs (except color) | — | Forwarded to the root |
Snippets
| Snippet | Description |
|---|---|
children | Main message |
icon | Leading icon node |