Skip to content

KAlert

示例

Alert banner with a light surface, a colored left accent bar, and optional filled semantic icon. Each variant derives its tint from the theme's color tokens so it adapts to light/dark automatically. Includes title and description sub-components.

Sub-Components

  • KAlert — Root alert container with variant and closable support
  • KAlertTitle — Alert title (<h5> element)
  • KAlertDescription — Alert description text

Props (KAlert)

NameTypeDefaultDescription
variant'default' | 'destructive' | 'warning' | 'info' | 'success''default'Visual style variant of the alert. default is neutral with no icon; the others get a semantic color, left accent bar, and icon.
closablebooleanfalseWhether the alert can be dismissed with a close button. Fades out (~200ms) before the close event fires.
titlestringConvenience title text. Ignored if the default slot is used.
descriptionstringConvenience description text. Ignored if the default slot is used.
classstringAdditional CSS classes.
theme'auto' | 'day' | 'night''auto'Theme mode. auto follows the current theme; day and night force a specific mode.

Emits

NameDescription
closeEmitted after the alert finishes its fade-out transition when the close button is clicked.

Slots

NameDescription
defaultAlert content. Use sub-components (KAlertTitle / KAlertDescription) for structured layouts; takes precedence over the title / description props.

Basic Usage

vue
<script setup>
import { KAlert, KAlertTitle, KAlertDescription } from '@kK-2004/ui-component'
</script>

<template>
  <!-- Slot layout -->
  <KAlert variant="info" :closable="true">
    <KAlertTitle>Information</KAlertTitle>
    <KAlertDescription>This is an informational alert message.</KAlertDescription>
  </KAlert>

  <!-- Props shorthand (no icon for default) -->
  <KAlert variant="success" title="Saved" description="Your changes are live." />
</template>