Badge
A small status label in four variants.
Install
If this is the first component in the project, set up once. This writes ermine.json and copies the theme stylesheet. The installation guide covers Vue, Nuxt and Astro.
npx ermineui initpnpm dlx ermineui inityarn dlx ermineui initbunx ermineui initThen add the component:
npx ermineui add badgepnpm dlx ermineui add badgeyarn dlx ermineui add badgebunx ermineui add badgeThat copies 2 files into src/components/ui/badge/. Files you already have are kept.
Use
import { Badge } from '@/components/ui/badge'<script setup lang="ts">
import { Badge } from '@/components/ui/badge'
</script>
<template>
<Badge />
</template>In Nuxt, with the auto-import setting, the tags work in templates without the import. In Astro, use it inside a Vue island. The props are documented in the source below, on each one.
What gets copied
| File | Where it goes |
|---|---|
Badge.vue | src/components/ui/badge/Badge.vue |
index.ts | src/components/ui/badge/index.ts |
The folders are the suggested ones. ermine.json says where yours are.
Source
This is exactly what the command copies. To install by hand, create each file below and the helpers listed above.
Badge.vue 53 lines
<script setup lang="ts">
withDefaults(
defineProps<{
variant?: 'default' | 'secondary' | 'outline' | 'destructive'
}>(),
{ variant: 'default' },
)
</script>
<template>
<span class="er-badge" :data-variant="variant"><slot /></span>
</template>
<style>
@layer components {
.er-badge {
display: inline-flex;
align-items: center;
gap: 0.25rem;
padding: 0.125rem 0.5rem;
border: 1px solid transparent;
border-radius: var(--er-radius-sm);
background: var(--er-primary);
color: var(--er-primary-foreground);
font-size: 0.75rem;
font-weight: var(--er-weight-medium);
line-height: 1rem;
white-space: nowrap;
}
.er-badge svg {
width: 0.75rem;
height: 0.75rem;
}
.er-badge[data-variant='secondary'] {
background: var(--er-secondary);
color: var(--er-secondary-foreground);
}
.er-badge[data-variant='outline'] {
border-color: var(--er-border);
background: transparent;
color: var(--er-foreground);
}
.er-badge[data-variant='destructive'] {
background: var(--er-destructive);
color: var(--er-destructive-foreground);
}
}
</style>index.ts 3 lines
/** Badge — a small status label in four variants. */
export { default as Badge } from './Badge.vue'