Spaces:
Sleeping
Sleeping
File size: 4,319 Bytes
4343907 |
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 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 |
<template>
<span :class="badgeClasses" v-bind="$attrs">
<!-- Dot indicator -->
<span v-if="dot" class="saap-badge__dot" aria-hidden="true" />
<!-- Icon -->
<component
v-if="icon"
:is="iconComponent"
class="saap-badge__icon"
aria-hidden="true"
/>
<!-- Content -->
<span class="saap-badge__content">
<slot />
</span>
</span>
</template>
<script setup lang="ts">
import { computed, defineProps, withDefaults } from 'vue'
import type { BadgeProps } from '@/types'
interface Props extends BadgeProps {
icon?: string
}
const props = withDefaults(defineProps<Props>(), {
variant: 'neutral',
size: 'md',
dot: false,
outline: false
})
// Computed
const badgeClasses = computed(() => [
'saap-badge',
`saap-badge--${props.variant}`,
`saap-badge--${props.size}`,
{
'saap-badge--outline': props.outline,
'saap-badge--with-dot': props.dot,
'saap-badge--with-icon': props.icon
}
])
const iconComponent = computed(() => {
if (props.icon) {
return resolveIconComponent(props.icon)
}
return null
})
// Methods
function resolveIconComponent(iconName: string) {
try {
return () => import(`lucide-vue-next/dist/esm/icons/${iconName}.js`)
} catch {
return null
}
}
</script>
<style lang="scss" scoped>
@import '@/styles/mixins.scss';
.saap-badge {
@include badge-base;
// Variants - Solid
&--success:not(&--outline) {
@include badge-success;
}
&--warning:not(&--outline) {
@include badge-warning;
}
&--error:not(&--outline) {
@include badge-error;
}
&--info:not(&--outline) {
@include badge-info;
}
&--neutral:not(&--outline) {
background: var(--saap-neutral-200);
color: var(--saap-neutral-800);
}
// Variants - Outline
&--success#{&--outline} {
background: transparent;
color: var(--saap-success);
border: 1px solid var(--saap-success);
}
&--warning#{&--outline} {
background: transparent;
color: var(--saap-warning);
border: 1px solid var(--saap-warning);
}
&--error#{&--outline} {
background: transparent;
color: var(--saap-error);
border: 1px solid var(--saap-error);
}
&--info#{&--outline} {
background: transparent;
color: var(--saap-info);
border: 1px solid var(--saap-info);
}
&--neutral#{&--outline} {
background: transparent;
color: var(--saap-neutral-600);
border: 1px solid var(--saap-neutral-300);
}
// Sizes
&--sm {
padding: var(--saap-space-1) var(--saap-space-2);
font-size: 0.625rem; // 10px
gap: var(--saap-space-1);
}
&--md {
padding: var(--saap-space-1) var(--saap-space-3);
font-size: var(--saap-text-xs);
gap: var(--saap-space-1);
}
&--lg {
padding: var(--saap-space-2) var(--saap-space-4);
font-size: var(--saap-text-sm);
gap: var(--saap-space-2);
}
}
.saap-badge__dot {
width: 0.375rem; // 6px
height: 0.375rem;
border-radius: 50%;
background: currentColor;
flex-shrink: 0;
.saap-badge--sm & {
width: 0.25rem; // 4px
height: 0.25rem;
}
.saap-badge--lg & {
width: 0.5rem; // 8px
height: 0.5rem;
}
}
.saap-badge__icon {
width: 0.75rem; // 12px
height: 0.75rem;
flex-shrink: 0;
.saap-badge--sm & {
width: 0.625rem; // 10px
height: 0.625rem;
}
.saap-badge--lg & {
width: 1rem; // 16px
height: 1rem;
}
}
.saap-badge__content {
line-height: 1;
}
// Special agent status badges
.saap-badge {
&--agent-active {
background: var(--saap-success);
color: white;
}
&--agent-inactive {
background: var(--saap-neutral-400);
color: white;
}
&--agent-processing {
background: var(--saap-warning);
color: white;
&::after {
content: '';
display: inline-block;
width: 0.5rem;
height: 0.5rem;
margin-left: var(--saap-space-1);
border: 1px solid currentColor;
border-top-color: transparent;
border-radius: 50%;
animation: spin 1s linear infinite;
}
}
&--agent-error {
background: var(--saap-error);
color: white;
}
&--agent-idle {
background: var(--saap-neutral-500);
color: white;
}
}
@keyframes spin {
to {
transform: rotate(360deg);
}
}
</style>
|