cn() utility
shadcn-htmx/utilsFreeUtility
Minimal class-name joiner. Drop-in replacement for clsx in the small surface this library uses. JSX projects only.
Install it
npx shadcn@latest add https://shadcn-htmx.productdevbook.com/r/utils.jsonSource
1// Minimal class-name joiner. Drops falsy values; flattens arrays.2// Equivalent to clsx for the subset we need. No tailwind-merge — author3// the variants so they don't collide, the way shadcn does for cva-defined classes.4export type ClassValue = string | number | null | undefined | false | ClassValue[]56export function cn(...inputs: ClassValue[]): string {7 const out: string[] = []8 const walk = (v: ClassValue) => {9 if (!v && v !== 0) return10 if (Array.isArray(v)) {11 for (const x of v) walk(x)12 } else {13 out.push(String(v))14 }15 }16 for (const v of inputs) walk(v)17 return out.join(" ")18}
