primevue-mirror/components/lib/badge/Badge.vue

50 lines
1.4 KiB
Vue
Raw Normal View History

2022-09-06 12:03:37 +00:00
<template>
2023-04-21 13:22:04 +00:00
<span :class="badgeClass" v-bind="ptm('root')">
2022-09-14 11:26:01 +00:00
<slot>{{ value }}</slot>
2022-09-06 12:03:37 +00:00
</span>
</template>
<script>
2023-04-21 13:22:04 +00:00
import BaseComponent from 'primevue/basecomponent';
import { ObjectUtils } from 'primevue/utils';
2022-09-06 12:03:37 +00:00
export default {
name: 'Badge',
2023-04-21 13:22:04 +00:00
extends: BaseComponent,
2022-09-06 12:03:37 +00:00
props: {
value: {
type: [String, Number],
default: null
},
severity: {
type: String,
default: null
},
size: {
type: String,
default: null
}
2022-09-06 12:03:37 +00:00
},
computed: {
containerClass() {
2022-09-14 11:26:01 +00:00
return this.$slots.default ? 'p-overlay-badge' : this.badgeClass;
2022-09-06 12:03:37 +00:00
},
badgeClass() {
2022-09-14 11:26:01 +00:00
return [
'p-badge p-component',
{
'p-badge-no-gutter': ObjectUtils.isNotEmpty(this.value) && String(this.value).length === 1,
'p-badge-dot': ObjectUtils.isEmpty(this.value) && !this.$slots.default,
2022-09-14 11:26:01 +00:00
'p-badge-lg': this.size === 'large',
'p-badge-xl': this.size === 'xlarge',
'p-badge-info': this.severity === 'info',
'p-badge-success': this.severity === 'success',
'p-badge-warning': this.severity === 'warning',
'p-badge-danger': this.severity === 'danger'
}
];
2022-09-06 12:03:37 +00:00
}
}
2022-09-14 11:26:01 +00:00
};
2022-09-06 12:03:37 +00:00
</script>