feat(message): add icon suppoer to message component

This commit is contained in:
Timothy Yin 2024-11-28 14:07:18 +08:00
parent e20572648d
commit d24140f673
3 changed files with 29 additions and 5 deletions

View File

@ -48,6 +48,20 @@ props:
--- ---
:: ::
### Icon
Or you can use the `icon` prop to change the icon of the message.
::ComponentPreview
---
privateProps:
content: Thanks for activating
props:
icon: tabler:circle-key
---
::
### Color ### Color
Use the `color` prop to change the color of the message. Use the `color` prop to change the color of the message.

View File

@ -1,5 +1,5 @@
<script lang="ts"> <script lang="ts">
import { ref, onMounted, defineComponent, type PropType, toRef, computed } from 'vue' import { onMounted, defineComponent, type PropType, toRef, computed } from 'vue'
import { twJoin, twMerge } from 'tailwind-merge' import { twJoin, twMerge } from 'tailwind-merge'
import { message } from '../../themes' import { message } from '../../themes'
import type { DeepPartial, Message, MessageColor, MessageType, Strategy } from '../../types/index' import type { DeepPartial, Message, MessageColor, MessageType, Strategy } from '../../types/index'
@ -17,6 +17,10 @@ export default defineComponent({
type: String as PropType<MessageColor>, type: String as PropType<MessageColor>,
default: undefined, default: undefined,
}, },
icon: {
type: String,
default: null,
},
duration: { duration: {
type: Number, type: Number,
default: config.default.duration, default: config.default.duration,
@ -63,6 +67,10 @@ export default defineComponent({
} }
}) })
const iconName = computed(() => {
return props.icon || ui.value.type[props.type]?.icon || null
})
onMounted(() => { onMounted(() => {
setTimeout(() => { setTimeout(() => {
message.remove(messageBody.value.id) message.remove(messageBody.value.id)
@ -75,6 +83,7 @@ export default defineComponent({
attrs, attrs,
messageBody, messageBody,
containerClass, containerClass,
iconName,
} }
}, },
}) })
@ -83,10 +92,7 @@ export default defineComponent({
<template> <template>
<div :class="ui.wrapper" v-bind="attrs"> <div :class="ui.wrapper" v-bind="attrs">
<div :class="containerClass"> <div :class="containerClass">
<IconCircleSuccess v-if="messageBody?.type === 'success'" class="text-xl" /> <RayIcon v-if="iconName" :name="iconName" class="text-xl" />
<IconCircleWarning v-if="messageBody?.type === 'warning'" class="text-xl" />
<IconCircleError v-if="messageBody?.type === 'error'" class="text-xl" />
<IconCircleInfo v-if="messageBody?.type === 'info'" class="text-xl" />
<span> <span>
{{ messageBody.content }} {{ messageBody.content }}
</span> </span>

View File

@ -9,15 +9,19 @@ export default {
type: { type: {
success: { success: {
color: 'emerald', color: 'emerald',
icon: 'tabler:circle-check',
}, },
warning: { warning: {
color: 'amber', color: 'amber',
icon: 'tabler:alert-circle',
}, },
error: { error: {
color: 'red', color: 'red',
icon: 'tabler:circle-x',
}, },
info: { info: {
color: 'blue', color: 'blue',
icon: 'tabler:info-circle',
}, },
}, },
default: { default: {