Skip to content
0

Badge ​

useBadge(options) creates a <span class="badge">; badgeClass(options) returns the classes for SSR markup.

Variants ​

ts
import { useBadge } from "@katanakit/ui";

row.append(
  useBadge({ label: "Draft" }),
  useBadge({ label: "Info", variant: "info" }),
  useBadge({ label: "Paid", variant: "success" }),
  useBadge({ label: "Pending", variant: "warning" }),
  useBadge({ label: "Failed", variant: "danger" }),
);

Contract

Every component in the kit follows one shape. Pure builders return a class string and touch nothing; factories build a DOM element and need a browser.

SurfaceImportNeeds a DOM
Pure class builderbadgeClassNo — safe during SSR
Element factoryuseBadgeYes — throws with a pointer to the pure surface
// Server and templates — pure
<div class={ badgeClass({ /* … */ }) }></div>

// Browser — imperative
document.body.append(useBadge({ /* … */ }));

Class names are unprefixed. The root class is badge, not kk-badge, and every component rule is wrapped in @layer katana.

That matters because these names collide 1:1 with daisyUI. Unlayered CSS always beats layered CSS regardless of specificity or import order, so loading both is deterministic instead of "whoever came last". See why.

Options ​

OptionTypeDefaultNotes
labelstring""Badge text.
variant"neutral" | "info" | "success" | "warning" | "danger""neutral"Semantic color.

Dark mode

Variants use KatanaKit palette tokens, so they invert automatically with data-theme="dark" (toggle the site theme to see it).

Released under the MIT License.