Utils
cn
Tailwind class-name merge helper.
Installed to components/control-ui/lib/cn.ts with every Control UI component, so the shared helper stays in one place.
Source
Installed util source
import { type ClassValue, clsx } from "clsx";import { type Config, extendTailwindMerge, mergeConfigs } from "tailwind-merge";
// tw-merge only knows stock sizes and misreads these as text COLOR group, so size and color in one cn() collide and one is dropped.const textScale = ["micro", "caption", "label", "body", "body-lg", "heading-1", "heading-2", "heading-3", "heading-4", "display", "hero"];
// unregistered, tw-merge reads these as shadow COLOR and lets them ride alongside later box-shadow util, so skin's override loses by CSS order instead of argument orderconst shadowScale = ["pop", "soft", "modal", "overlay", "inset"];
// theme.css maps --control-h* and the role radii into Tailwind's spacing and radius namespaces (h-control-sm, size-control-md, rounded-panel).// Unregistered, tw-merge treats them as unknown classes, so caller's `h-10` or `rounded-none` stays beside the default and CSS order picks the winner.const controlSpacingScale = ["control", "control-xs", "control-sm", "control-md", "control-lg"];const radiusScale = ["control", "field", "panel", "scene"];
export function withControlUiMerge(config: Config<string, string>) { return mergeConfigs(config, { extend: { theme: { spacing: controlSpacingScale, radius: radiusScale, }, classGroups: { "font-size": [{ text: textScale }], shadow: [{ shadow: shadowScale }], }, }, // stock Tailwind bakes line-height into `text-*`, so twMerge lets font-size clear preceding `leading-*`; this scale is size-only, so that conflict must go override: { conflictingClassGroups: { "font-size": [], }, }, });}
const twMerge = extendTailwindMerge(withControlUiMerge);
export function cn(...inputs: ClassValue[]) { return twMerge(clsx(inputs));}