Skip to content

cn

A utility function to merge Tailwind class names using clsx and tailwind-merge. Use this library to write conditional classes in your components.

Import

Terminal window
import { cn } from "@aeonkit/helpers";

Parameters

cn accepts a single parameter, which can be a string, an object, or a conditional statement.

Usage

Simple

Terminal window
cn('text-center bg-slate-100 transition duration-300 ease-in-out')

Conditional logic

Terminal window
cn('text-center bg-slate-100', error && 'text-red-500 bg-blue-500')

With an object

Terminal window
cn('text-center bg-slate-100', { 'text-red-500': error, 'bg-blue-500': !error })

Returns

A string of merged class names.

References