Get Started

cn

조건부 클래스를 합치고 Tailwind 클래스 충돌을 정리합니다.

가져오기

import { cn } from "@olundot/ui";

조건부 클래스

clsx로 조건부 값을 합친 뒤 tailwind-merge로 충돌을 정리합니다. 같은 역할의 클래스는 뒤에 쓴 값이 남습니다.

const className = cn(
  "text-body-sm text-text-secondary",
  isActive && "text-foreground",
  "text-body-lg",
);

글자 크기와 색은 서로 다른 역할입니다. text-body-lg는 text-body-sm만 대체하고 색 클래스는 그대로 둡니다.

컴포넌트 확장

외부에서 받은 className을 마지막 인자로 둡니다.

import { cn } from "@olundot/ui";

export function Panel({ className }: { className?: string }) {
  return <div className={cn("rounded-md border border-border-subtle", className)} />;
}

목차