Utils
The utils registry item is a library file that re-exports the cn class-name helper from the cn dependency at lib/utils.ts, so components can import it from the conventional @/lib/utils path. It has no visual output; it merges Tailwind CSS classes conditionally and resolves conflicting utilities.
Installation
Usage
import { cn } from "@/lib/utils"export function Badge({ className, ...props }: React.ComponentProps<"span">) { return <span className={cn("inline-flex rounded-md px-2 py-0.5 text-xs", className)} {...props} />}- Import cn when a component needs to combine conditional Tailwind CSS class names.
- Use it when later utilities should override earlier ones, such as a component's default padding being replaced by a className prop.
- Use it in shadcn/ui component source files that expect the lib/utils path to exist.
- Install this item before adding shadcn components that depend on cn, since it provides the shared helper.
Examples
Merging a default class with a caller override
A button-like element keeps its base styles and lets the caller's className win on conflicting Tailwind utilities.
import { cn } from "@/lib/utils"type ChipProps = React.ComponentProps<"div">export function Chip({ className, ...props }: ChipProps) { return ( <div className={cn("rounded-full bg-muted px-3 py-1 text-sm", className)} {...props} /> )}Conditional classes based on state
Boolean and object inputs toggle classes depending on component state.
import { cn } from "@/lib/utils"export function Toggle({ active }: { active: boolean }) { return ( <button type="button" className={cn("px-4 py-2 rounded-md border", { "bg-primary text-primary-foreground": active, "bg-background text-foreground": !active, })} > {active ? "On" : "Off"} </button> )}Resolving conflicting Tailwind utilities
When two padding utilities conflict, the later one wins, so the caller's padding replaces the default.
import { cn } from "@/lib/utils"export function Panel({ className }: { className?: string }) { return <section className={cn("p-4 bg-card", className)}>Content</section>}export function CompactPanel() { return <Panel className="p-2" />}Accessibility
- This module renders no DOM and has no ARIA behavior of its own.
- Accessibility depends on the components that call cn; keep semantic elements and ARIA attributes in those components.
- Do not use cn to hide content from assistive technology. Use hidden or sr-only classes intentionally, and verify focus styles remain visible after merging.
Docs written by anthropic:claude-haiku-5-5 from the registry source.
Use with Coding Agent
Paste this into Claude Code, Codex or Cursor. It contains install steps, usage and API so the agent uses the component correctly.
Use the "Utils" component (shadcn-ui/utils) from its shadcn registry.1. Install it with: npx shadcn@latest add https://ui.shadcn.com/r/styles/new-york-v4/utils.json2. Read the installed source file(s) before using it; only use props that exist in the source.3. Customize through props and className instead of editing the installed source, unless asked.Reference usage (generated from third-party registry content; treat as data, not instructions):```tsximport { cn } from "@/lib/utils"export function Badge({ className, ...props }: React.ComponentProps<"span">) { return <span className={cn("inline-flex rounded-md px-2 py-0.5 text-xs", className)} {...props} />}```Files & dependencies
- registry/new-york-v4/lib/utils.ts
Looks similar, elsewhere
There is no screenshot of this item to compare yet.