Components
Badge
A compact label for status, counts and categories.
Installation
$ npx veil-ui@latest add badgeUsage
import { Badge } from "@/components/ui/badge";
<Badge variant="outline">Draft</Badge>;Examples
Basic
New
Variants
DefaultSecondaryOutlineMutedDestructive
With icon
Operationalv0.1.0
As a link
API reference
| Prop | Type | Default | Description |
|---|---|---|---|
| variant | "default" | "secondary" | "outline" | "muted" | "destructive" | "default" | Visual style of the badge. |
| asChild | boolean | false | Render the child element instead of a span. |
| ...props | React.ComponentProps<"span"> | — | All native span attributes. |
Accessibility
- Badges are plain text containers; avoid using them as the only way to convey status. Pair color with a label or icon.
- When a badge is interactive, use
asChildwith a real link or button.
Vue and plain HTML
This component also ships for Vue (Reka UI) and plain HTML. Install it with npx veil-ui add badge --framework vue or switch the framework in components.json.
<script setup lang="ts">
import { Primitive } from "reka-ui";
import { computed } from "vue";
import { cn } from "@/lib/utils";
import { badgeVariants, type BadgeVariants } from "./variants";
defineOptions({ inheritAttrs: false });
const props = withDefaults(
defineProps<{
variant?: BadgeVariants["variant"];
asChild?: boolean;
class?: string;
}>(),
{ asChild: false },
);
const classes = computed(() =>
cn(badgeVariants({ variant: props.variant }), props.class),
);
</script>
<template>
<Primitive
:as="asChild ? undefined : 'span'"
:as-child="asChild"
data-slot="badge"
:data-variant="variant ?? 'default'"
:class="classes"
v-bind="$attrs"
>
<slot />
</Primitive>
</template>