@meltdownjs/cn
Version:
`@meltdownjs/cn` is a utility function for combining multiple CSS class names into a single string while also resolving any conflicting classes.
45 lines (38 loc) • 1.81 kB
TypeScript
import { ClassValue } from 'clsx';
export declare type Cn = (...args: ClassValue[]) => string;
/**
* Combines multiple className strings together,
* merging them into a single string.
*
* @remarks
* This function is a wrapper around `clsx` and `twMerge`,
* which are both popular packages for working with CSS classes.
* clsx (constructing classes) --> twMerge (merge conflicting classes)
*
* `clsx` is used to construct a new array of class names from the arguments provided.
* `twMerge` is then used to merge any conflicting class names together.
*
* For example, passing in the arguments `["bg-red-500", "bg-blue-500"]` would result in the string `"bg-red-500 bg-blue-500"`.
* However, if both of those classes have the same styles, `twMerge` will merge them into a single class, like so: `"bg-purple-500"`.
*
* @param args - The class names to combine.
* @returns A single string of all the merged class names.
*
* @see {@link https://github.com/lukeed/clsx} for more information on `clsx`.
* @see {@link https://github.com/dcastil/tailwind-merge} for more information on `twMerge`.
* @see {@link https://github.com/dcastil/tailwind-merge/discussions/137#discussioncomment-3482513} for more information on `twMerge`-Creators suggestion.
*/
declare const cn: Cn;
export default cn;
export declare interface CnConfigInterface {
prefix: string;
}
export declare type CreateCn = (config: CnConfigInterface) => Cn;
/**
* Creates a new instance of the `cn` function with a custom configuration.
*
* @param {Partial<CnConfigInterface>} cnConfig - The configuration object for the `cn` function.
* @returns {Cn} A new instance of the `cn` function with the custom configuration.
*/
export declare const createCn: CreateCn;
export { }