visua-vue/src/components/badge/VBadge.vue

72 lines
1.7 KiB
Vue
Raw Normal View History

2025-07-23 14:37:06 +02:00
<script setup lang="ts">
import type IVBadge from './IVBadge.type';
import Tag from 'primevue/tag';
import { computed } from 'vue';
const props = withDefaults(defineProps<IVBadge>(), {
type: undefined,
noIcon: false,
small: false,
})
const severity = computed(() => {
switch (props.type) {
case 'error': return 'danger';
case 'warning' : return 'warn';
case 'success' : return 'success';
case 'info': return 'info';
case 'new': return 'secondary';
default:
return undefined;
}
});
const icon = computed(() => {
switch (props.type) {
2025-07-24 02:32:35 +02:00
case 'error': return 'ri-spam-fill';
case 'warning' : return 'ri-alert-fill';
case 'success' : return 'ri-checkbox-circle-fill';
case 'info': return 'ri-information-fill';
case 'new': return 'ri-flashlight-fill';
2025-07-23 14:37:06 +02:00
default:
return undefined;
}
})
2025-07-23 15:38:02 +02:00
const limit = computed(() => props.maxWidth);
2025-07-23 14:37:06 +02:00
</script>
<template>
<Tag
role="alert"
:value="props.label"
:severity="severity"
2025-07-23 15:38:02 +02:00
:title="props.label"
2025-07-23 14:37:06 +02:00
class="p-tag"
:class="{'small': props.small}"
>
2025-07-24 02:32:35 +02:00
<i v-if="!props.noIcon || props.type === undefined" :class="icon" style="font-weight: 100;"></i>
2025-07-23 15:38:02 +02:00
<span :class="{'limit': props.maxWidth}">{{ props.label }}</span>
2025-07-23 14:37:06 +02:00
</Tag>
</template>
<style lang="css" scoped>
2025-07-23 15:38:02 +02:00
.p-tag{height: fit-content;}
2025-07-23 14:37:06 +02:00
.p-tag.small{
--p-tag-icon-size: var( --text-body-SM-detail-text-Maj-size);
--p-tag-font-size: var( --text-body-XS-mention-text-Maj-size);
--p-tag-font-weight: var( --text-body-XS-mention-text-Maj-weight);
--p-tag-padding: 0.125rem 0.325rem;
2025-07-23 15:38:02 +02:00
align-self: center;
}
.limit{
max-width: v-bind(limit);
2025-07-23 14:37:06 +02:00
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
2025-07-23 15:38:02 +02:00
2025-07-23 14:37:06 +02:00
</style>