-
-
Notifications
You must be signed in to change notification settings - Fork 14.6k
/
badge.vue
49 lines (43 loc) 路 1.11 KB
/
badge.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<template>
<div :class="ns.b()">
<slot />
<transition :name="`${ns.namespace.value}-zoom-in-center`">
<sup
v-show="!hidden && (content || isDot)"
:class="[
ns.e('content'),
ns.em('content', type),
ns.is('fixed', !!$slots.default),
ns.is('dot', isDot),
]"
:style="{ backgroundColor: color }"
v-text="content"
/>
</transition>
</div>
</template>
<script lang="ts" setup>
import { computed } from 'vue'
import { useNamespace } from '@element-plus/hooks'
import { isNumber } from '@element-plus/utils'
import { badgeProps } from './badge'
defineOptions({
name: 'ElBadge',
})
const props = defineProps(badgeProps)
const ns = useNamespace('badge')
const content = computed<string>(() => {
if (props.isDot) return ''
if (isNumber(props.value) && isNumber(props.max)) {
if (props.max < props.value) {
return `${props.max}+`
}
return props.value === 0 && !props.showZero ? '' : `${props.value}`
}
return `${props.value}`
})
defineExpose({
/** @description badge content */
content,
})
</script>