ZINC-FYP-2022-23 / console

ZINC UI for teaching assistants
1 stars 0 forks source link

feat(utils): wrapper for `clsx` and `tailwind-merge` #39

Open AnsonH opened 1 year ago

AnsonH commented 1 year ago

Description

Create a new wrapper utility that combines the functionality of the following 2 libraries:

Example Implementation

import { ClassValue, clsx } from 'clsx';
import { twMerge } from 'tailwind-merge';

function cn(...args: ClassValue[]) {
  return twMerge(clsx(args));
}

export default cn;

Example Usage

// Suppose there's a boolean prop called `warning`
<button
   className={cn(
     "text-gray-800",
     // With tailwind-merge, we don't need to add `!` before `text-yellow-800` to make sure
     // this class overrides the original `text-gray-800` styles
     warning && "text-yellow-800",
   )}
>Test</button>

Reference

https://twitter.com/shadcn/status/1614692419039105024/photo/1