Feedback

Alert

Display contextual feedback messages to the user. Alerts support titles, descriptions, icons, action buttons, close functionality, and multiple visual variants.

Playground

Experiment with different props in real-time.

Basic Usage

Import and use the Alert component with a title and description.

<script lang="ts">
  import { Alert } from 'sv5ui';
</script>

<Alert
  title="Heads up!"
  description="You can add components to your app using the CLI."
/>

Variants

4 visual styles to match the context of your alert.

<Alert variant="solid" title="Solid" description="This is a solid alert." />
<Alert variant="outline" title="Outline" description="This is an outline alert." />
<Alert variant="soft" title="Soft" description="This is a soft alert." />
<Alert variant="subtle" title="Subtle" description="This is a subtle alert." />

Colors

Use semantic colors to convey different types of feedback.

<Alert color="success" title="Success" description="Your changes have been saved." icon="lucide:check-circle" />
<Alert color="warning" title="Warning" description="Your session is about to expire." icon="lucide:alert-triangle" />
<Alert color="error" title="Error" description="Something went wrong. Please try again." icon="lucide:x-circle" />
<Alert color="info" title="Info" description="A new version is available." icon="lucide:info" />

With Icon

Add a leading icon using the icon prop with any Iconify icon name.

<Alert
  title="Update available"
  description="A new software update is available for download."
  icon="lucide:download"
  color="info"
/>

With Actions

Add action buttons using the actions prop.

<Alert
  title="Confirm action"
  description="Are you sure you want to proceed with this action?"
  icon="lucide:alert-triangle"
  color="warning"
  :actions={[
    { label: 'Cancel', variant: 'outline', color: 'surface', size: 'xs' },
    { label: 'Confirm', variant: 'solid', color: 'warning', size: 'xs' }
  ]}
/>

Closable

Allow users to dismiss the alert with a close button using close and onClose.

<script lang="ts">
  import { Alert, Button } from 'sv5ui';

  let alertOpen = $state(true);
</script>

{#if alertOpen}
  <Alert
    title="Dismissible alert"
    description="Click the close button to dismiss this alert."
    close
    onClose={() => (alertOpen = false)}
  />
{/if}

{#if !alertOpen}
  <Button
    label="Show alert"
    size="sm"
    variant="outline"
    onclick={() => (alertOpen = true)}
  />
{/if}

Vertical Orientation

Use orientation="vertical" for a stacked layout.

<Alert
  orientation="vertical"
  title="Vertical layout"
  description="This alert uses a vertical orientation for a stacked layout."
  icon="lucide:layout"
  color="tertiary"
  :actions={[
    { label: 'Learn more', variant: 'outline', color: 'tertiary', size: 'xs' }
  ]}
/>

UI Slots

Use the ui prop to override classes on specific internal elements of the Alert.

SlotDescription
rootOutermost wrapper element — controls overall layout, padding, and border
wrapperInner content wrapper — controls flex layout direction and spacing
titleAlert title text — controls font size, weight, and color
descriptionAlert description text — controls font size and opacity
iconLeading icon element — controls icon size and color
avatarAvatar element when using avatar prop — controls avatar styling
actionsAction buttons container — controls button layout and spacing
closeClose button element — controls close icon size and position

Snippets

Use Svelte 5 snippets to customize specific parts of the Alert.

SnippetTypeDescription
leadingSnippetCustom leading content — replaces the default icon/avatar area
titleSlotSnippetCustom title content — replaces the default title text
descriptionSlotSnippetCustom description content — replaces the default description text
actionsSlotSnippetCustom actions area — replaces the default action buttons
closeSlotSnippetCustom close button — replaces the default close icon

Props

PropTypeDefault
askeyof HTMLElementTagNameMap'div'
titlestring-
descriptionstring-
iconstring-
avatarAvatarProps-
colorColor'primary'
variant'solid' | 'outline' | 'soft' | 'subtle''solid'
orientation'horizontal' | 'vertical''horizontal'
openbooleantrue
closeboolean | ButtonPropsfalse
closeIconstring'lucide:x'
actionsButtonProps[]-
onClose() => void-
classstring-
uiRecord<Slot, Class>-