Refined UI

An opinionated, customizable superset of shadcn/ui

AgentsPrimitivesSkillsSkins
Guides
  • Overview
  • Get started
  • Shadcn compatibility
  • Architecture
  • Agent surface
Primitives
  • Accordion
  • Alert
  • Alert dialog
  • Aspect ratio
  • Autocomplete
  • Avatar
  • Badge
  • Button
  • Button group
  • Calendar
  • Card
  • Checkbox
  • Checkbox Group
  • Code
  • Code Diff
  • Collapsible
  • Color Picker
  • Combobox
  • Command
  • Date Picker
  • Dialog
  • Drawer
  • Empty
  • Field
  • Form
  • Gradient Editor
  • Hover card
  • Input
  • Input group
  • Input OTP
  • Item
  • Kbd
  • Markdown
  • Menu
  • Menubar
  • Meter
  • Native select
  • Navigation menu
  • Number Field
  • Pagination
  • Popover
  • Progress
  • Radio group
  • Resizable
  • Scroll area
  • Select
  • Sidebar
  • Skeleton
  • Slider
  • Spinner
  • Switch
  • Table
  • Table of contents
  • Tabs
  • Textarea
  • Toast
  • Toggle
  • Toolbar
  • Tooltip
  • Tree
  • Trigger Menu
  • Typography
Hooks
  • Use Chat Message
  • Use Chat Input
  • Use User Ask
  • Use Audio Recorder
  • Use Environment Variables
  • Use Copy To Clipboard
  • Use Tool Call
  • Use Sidebar Resize
Utils
  • cn
  • Skin
  • Contracts
  • Serialize
Extensions
  • Control Effects
  • View Transition
  • Send Aurora
  1. Primitives
  2. Badge
Primitives

Badge

Compact status, label, or count chip.

Composition

The preferred shape for composing the installed primitive from its exported parts.

Root

Single-slot surface with no nested parts.

Badge

The refined source installs this primitive from src/registry/sources/refined/ui/badge.tsx. Install it on its own with the command above, or inspect the source below.

Registry command
npx shadcn@latest add http://127.0.0.1:3000/r/refined/badge.json
See registry manifest

Installed dependencies

Installed with this primitive because the slot depends on them; they are support files, not standalone sidebar items.

Theme tokenssrc/registry/sources/refined/theme.cssSupport

Raw code

Primary installed primitive source

Badge slot
src/registry/sources/refined/ui/badge.tsx
"use client";
​
import { cva } from "class-variance-authority";
import type { BadgeProps } from "@/components/refined-ui/contracts";
import { cn } from "@/components/refined-ui/lib/cn";
import { useAsChildRender } from "@/components/refined-ui/lib/use-as-child-render";
import { skinSlot } from "@/components/refined-ui/skin";
​
type BadgeVariant = NonNullable<BadgeProps["variant"]>;
type BadgeColor = NonNullable<BadgeProps["color"]>;
​
const defaultColorByVariant: Record<BadgeVariant, BadgeColor> = {
default: "neutral",
secondary: "neutral",
destructive: "red",
outline: "neutral",
};
​
const badgeVariant = cva(
"inline-flex w-fit shrink-0 items-center justify-center gap-1 overflow-hidden whitespace-nowrap rounded-md border px-2 py-0.5 text-meta font-medium transition-colors focus-visible:ring-2 focus-visible:ring-foreground/20 [&>svg]:pointer-events-none [&>svg]:size-3",
{
variants: {
variant: {
default: "",
secondary: "",
destructive: "",
outline: "",
},
},
defaultVariants: {
variant: "default",
},
},
);
​
export function Badge({ variant = "default", color, asChild = false, render, className, children, ...props }: BadgeProps) {
const resolvedColor = color ?? defaultColorByVariant[variant];
​
return useAsChildRender({
defaultTagName: "span",
asChild,
render,
children,
props: {
...props,
"data-ui": "agent",
"data-slot": "badge",
"data-variant": variant,
"data-color": resolvedColor,
className: cn(badgeVariant({ variant }), skinSlot("badge", { variant, color: resolvedColor }), className),
},
});
}
​

On this page

  • Preview
  • Composition
  • Installation
  • Dependencies
  • Source
DefaultBeta15DeniedOutlineAllowedslategrayzincstoneredorangeamberyellowlimegreenemeraldtealcyanskyblueindigovioletpurplefuchsiapinkroseLink badge