refactor(components): [alert] introduce hasDesc helper (#19085)

refactor: introduce hasDesc helper
This commit is contained in:
zhangenming 2024-12-06 20:39:00 +08:00 committed by GitHub
parent e9f3fdd529
commit ea3cfc97c7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -5,18 +5,21 @@
:class="[ns.b(), ns.m(type), ns.is('center', center), ns.is(effect)]"
role="alert"
>
<el-icon v-if="showIcon && iconComponent" :class="iconClass">
<el-icon
v-if="showIcon && iconComponent"
:class="[ns.e('icon'), { [ns.is('big')]: hasDesc }]"
>
<component :is="iconComponent" />
</el-icon>
<div :class="ns.e('content')">
<span
v-if="title || $slots.title"
:class="[ns.e('title'), withDescription]"
:class="[ns.e('title'), { 'with-description': hasDesc }]"
>
<slot name="title">{{ title }}</slot>
</span>
<p v-if="$slots.default || description" :class="ns.e('description')">
<p v-if="hasDesc" :class="ns.e('description')">
<slot>
{{ description }}
</slot>
@ -60,14 +63,7 @@ const visible = ref(true)
const iconComponent = computed(() => TypeComponentsMap[props.type])
const iconClass = computed(() => [
ns.e('icon'),
{ [ns.is('big')]: !!props.description || !!slots.default },
])
const withDescription = computed(() => {
return { 'with-description': props.description || slots.default }
})
const hasDesc = computed(() => !!(props.description || slots.default))
const close = (evt: MouseEvent) => {
visible.value = false