Alert
吸引用户注意力的一种方法。
用法
标题
使用title道具设置警报的标题。
Heads up!
<template>
<UAlert title="Heads up!" />
</template>说明
使用description属性设置警报的描述。
Heads up!
You can change the primary color in your app config.
<template>
<UAlert title="Heads up!" description="You can change the primary color in your app config." />
</template>Icon
使用icon道具显示Icon。
Heads up!
You can change the primary color in your app config.
<template>
<UAlert
title="Heads up!"
description="You can change the primary color in your app config."
icon="i-lucide-terminal"
/>
</template>Avatar
使用avatar道具显示Avatar。
Heads up!
You can change the primary color in your app config.
<template>
<UAlert
title="Heads up!"
description="You can change the primary color in your app config."
:avatar="{
src: 'https://github.com/nuxt.png'
}"
/>
</template>Color
使用color道具更改警报的颜色。
Heads up!
You can change the primary color in your app config.
<template>
<UAlert
color="neutral"
title="Heads up!"
description="You can change the primary color in your app config."
icon="i-lucide-terminal"
/>
</template>Variant
使用variant prop更改Alert的变体。
Heads up!
You can change the primary color in your app config.
<template>
<UAlert
color="neutral"
variant="subtle"
title="Heads up!"
description="You can change the primary color in your app config."
icon="i-lucide-terminal"
/>
</template>关闭
使用close道具显示按钮以解除警报。
当单击关闭按钮时,将发出
update:open事件。Heads up!
You can change the primary color in your app config.
<template>
<UAlert
title="Heads up!"
description="You can change the primary color in your app config."
color="neutral"
variant="outline"
close
/>
</template>您可以从Button组件传递任何属性来对其进行自定义。
Heads up!
You can change the primary color in your app config.
<template>
<UAlert
title="Heads up!"
description="You can change the primary color in your app config."
color="neutral"
variant="outline"
:close="{
color: 'primary',
variant: 'outline',
class: 'rounded-full'
}"
/>
</template>关闭图标
使用close-icon属性自定义关闭按钮Icon。
Heads up!
You can change the primary color in your app config.
<template>
<UAlert
title="Heads up!"
description="You can change the primary color in your app config."
color="neutral"
variant="outline"
close
close-icon="i-lucide-arrow-right"
/>
</template>Actions
使用actions prop向Alert添加一些Button操作。
Heads up!
You can change the primary color in your app config.
<template>
<UAlert
title="Heads up!"
description="You can change the primary color in your app config."
color="neutral"
variant="outline"
:actions="[
{
label: 'Action 1'
},
{
label: 'Action 2',
color: 'neutral',
variant: 'subtle'
}
]"
/>
</template>方向
使用orientation道具更改警报的方向。
Heads up!
You can change the primary color in your app config.
<template>
<UAlert
title="Heads up!"
description="You can change the primary color in your app config."
color="neutral"
variant="outline"
orientation="horizontal"
:actions="[
{
label: 'Action 1'
},
{
label: 'Action 2',
color: 'neutral',
variant: 'subtle'
}
]"
/>
</template>示例
class道具
使用class属性覆盖Alert的基本样式。
Heads up!
You can change the primary color in your app config.
<template>
<UAlert
title="Heads up!"
description="You can change the primary color in your app config."
class="rounded-none"
/>
</template>ui道具
使用ui道具覆盖警报的插槽样式。
Heads up!
You can change the primary color in your app config.
<template>
<UAlert
title="Heads up!"
description="You can change the primary color in your app config."
icon="i-lucide-rocket"
:ui="{
icon: 'size-11'
}"
/>
</template>API
Props
| Prop | Default | Type |
|---|---|---|
as | 'div' | anyThe element or component this component should render as. |
title | string | |
description | string | |
icon | any | |
avatar | AvatarProps | |
color | 'primary' | "error" | "primary" | "secondary" | "success" | "info" | "warning" | "neutral" |
variant | 'solid' | "solid" | "outline" | "soft" | "subtle" |
orientation | 'vertical' | "vertical" | "horizontal"The orientation between the content and the actions. |
actions | ButtonProps[]Display a list of actions:
| |
close | false | boolean | Omit<ButtonProps, LinkPropsKeys> Display a close button to dismiss the alert.
|
closeIcon | appConfig.ui.icons.close | anyThe icon displayed in the close button. |
ui | { root?: SlotClass; wrapper?: SlotClass; title?: SlotClass; description?: SlotClass; icon?: SlotClass; avatar?: SlotClass; avatarSize?: SlotClass; actions?: SlotClass; close?: SlotClass; } |
Slots
| Slot | Type |
|---|---|
leading | { ui: object; } |
title | {} |
description | {} |
actions | {} |
close | { ui: object; } |
Emits
| Event | Type |
|---|---|
update:open | [value: boolean] |
Theme
app.config.ts
export default defineAppConfig({
ui: {
alert: {
slots: {
root: 'relative overflow-hidden w-full rounded-lg p-4 flex gap-2.5',
wrapper: 'min-w-0 flex-1 flex flex-col',
title: 'text-sm font-medium',
description: 'text-sm opacity-90',
icon: 'shrink-0 size-5',
avatar: 'shrink-0',
avatarSize: '2xl',
actions: 'flex flex-wrap gap-1.5 shrink-0',
close: 'p-0'
},
variants: {
color: {
primary: '',
secondary: '',
success: '',
info: '',
warning: '',
error: '',
neutral: ''
},
variant: {
solid: '',
outline: '',
soft: '',
subtle: ''
},
orientation: {
horizontal: {
root: 'items-center',
actions: 'items-center'
},
vertical: {
root: 'items-start',
actions: 'items-start mt-2.5'
}
},
title: {
true: {
description: 'mt-1'
}
}
},
compoundVariants: [
{
color: 'primary',
variant: 'solid',
class: {
root: 'bg-primary text-inverted'
}
},
{
color: 'primary',
variant: 'outline',
class: {
root: 'text-primary ring ring-inset ring-primary/25'
}
},
{
color: 'primary',
variant: 'soft',
class: {
root: 'bg-primary/10 text-primary'
}
},
{
color: 'primary',
variant: 'subtle',
class: {
root: 'bg-primary/10 text-primary ring ring-inset ring-primary/25'
}
},
{
color: 'neutral',
variant: 'solid',
class: {
root: 'text-inverted bg-inverted'
}
},
{
color: 'neutral',
variant: 'outline',
class: {
root: 'text-highlighted bg-default ring ring-inset ring-default'
}
},
{
color: 'neutral',
variant: 'soft',
class: {
root: 'text-highlighted bg-elevated/50'
}
},
{
color: 'neutral',
variant: 'subtle',
class: {
root: 'text-highlighted bg-elevated/50 ring ring-inset ring-accented'
}
}
],
defaultVariants: {
color: 'primary',
variant: 'solid'
}
}
}
})vite.config.ts
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import ui from '@nuxt/ui/vite'
export default defineConfig({
plugins: [
vue(),
ui({
ui: {
alert: {
slots: {
root: 'relative overflow-hidden w-full rounded-lg p-4 flex gap-2.5',
wrapper: 'min-w-0 flex-1 flex flex-col',
title: 'text-sm font-medium',
description: 'text-sm opacity-90',
icon: 'shrink-0 size-5',
avatar: 'shrink-0',
avatarSize: '2xl',
actions: 'flex flex-wrap gap-1.5 shrink-0',
close: 'p-0'
},
variants: {
color: {
primary: '',
secondary: '',
success: '',
info: '',
warning: '',
error: '',
neutral: ''
},
variant: {
solid: '',
outline: '',
soft: '',
subtle: ''
},
orientation: {
horizontal: {
root: 'items-center',
actions: 'items-center'
},
vertical: {
root: 'items-start',
actions: 'items-start mt-2.5'
}
},
title: {
true: {
description: 'mt-1'
}
}
},
compoundVariants: [
{
color: 'primary',
variant: 'solid',
class: {
root: 'bg-primary text-inverted'
}
},
{
color: 'primary',
variant: 'outline',
class: {
root: 'text-primary ring ring-inset ring-primary/25'
}
},
{
color: 'primary',
variant: 'soft',
class: {
root: 'bg-primary/10 text-primary'
}
},
{
color: 'primary',
variant: 'subtle',
class: {
root: 'bg-primary/10 text-primary ring ring-inset ring-primary/25'
}
},
{
color: 'neutral',
variant: 'solid',
class: {
root: 'text-inverted bg-inverted'
}
},
{
color: 'neutral',
variant: 'outline',
class: {
root: 'text-highlighted bg-default ring ring-inset ring-default'
}
},
{
color: 'neutral',
variant: 'soft',
class: {
root: 'text-highlighted bg-elevated/50'
}
},
{
color: 'neutral',
variant: 'subtle',
class: {
root: 'text-highlighted bg-elevated/50 ring ring-inset ring-accented'
}
}
],
defaultVariants: {
color: 'primary',
variant: 'solid'
}
}
}
})
]
})Changelog
No recent changes