Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(Alert): add icon & avatar slots #1401

Merged
merged 11 commits into from
Mar 13, 2024
21 changes: 21 additions & 0 deletions docs/components/content/examples/AlertExampleAvatar.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<template>
<UAlert
title="Customize Alert Avatar"
description="Insert custom content into the avatar slot!"
:avatar="{
src: 'https://avatars.githubusercontent.com/u/739984?v=4',
alt: 'Avatar'
}"
>
<template #avatar="{ avatar, ui }">
<UAvatar
v-bind="{ size: ui.size, ...avatar }"
:class="ui.base"
chip-color="primary"
chip-text=""
chip-position="top-right"
/>
</template>
</UAlert>
</template>

10 changes: 10 additions & 0 deletions docs/components/content/examples/AlertExampleIcon.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<template>
<UAlert title="Customize Alert Icon" description="Insert custom content into the icon slot!" icon="i-heroicons-command-line">
<template #icon="{ icon, ui }">
<UBadge title="3" size="sm">
benjamincanac marked this conversation as resolved.
Show resolved Hide resolved
<UIcon :name="icon" :class="ui.base" />
</UBadge>
</template>
</UAlert>
</template>

12 changes: 12 additions & 0 deletions docs/content/2.components/alert.md
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,18 @@ This can be handy when you want to display HTML content. To achieve this, you ca

:component-example{component="alert-example-html"}

### `icon`

Use the `#icon` slot to customize the displayed icon.

:component-example{component="alert-example-icon"}

### `avatar`

Use the `#avatar` slot to customize the displayable avatar.

:component-example{component="alert-example-avatar"}

## Props

:component-props
Expand Down
8 changes: 6 additions & 2 deletions src/runtime/components/elements/Alert.vue
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
<template>
<div :class="alertClass" v-bind="attrs">
<div class="flex" :class="[ui.gap, { 'items-start': (description || $slots.description), 'items-center': !description && !$slots.description }]">
<UIcon v-if="icon" :name="icon" :class="ui.icon.base" />
<UAvatar v-if="avatar" v-bind="{ size: ui.avatar.size, ...avatar }" :class="ui.avatar.base" />
<slot name="icon" :icon="icon" :ui="ui.icon">
zoobzio marked this conversation as resolved.
Show resolved Hide resolved
<UIcon v-if="icon" :name="icon" :ui="ui.icon.base" />
</slot>
<slot name="avatar" :avatar="avatar" :ui="ui.avatar">
<UAvatar v-if="avatar" v-bind="{ size: ui.avatar.size, ...avatar }" :class="ui.avatar.base" />
</slot>

<div :class="ui.inner">
<p v-if="(title || $slots.title)" :class="ui.title">
Expand Down
Loading