Skip to content

Commit 3a3afce

Browse files
authored
fix: update cn function type and import cx from tailwind-variants/lite (#285)
- Change the type of cn function to allow callable string representation. - Update import statement in MIGRATION-V3.md to use cx instead of cnBase.
1 parent c19f93d commit 3a3afce

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

MIGRATION-V3.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,5 @@ pnpm add tailwind-merge
3333
If you do not need conflict resolution, switch to the lite build by importing from `tailwind-variants/lite`:
3434

3535
```ts
36-
import {createTV, tv, cn, cnBase} from "tailwind-variants/lite";
36+
import {createTV, tv, cn, cx} from "tailwind-variants/lite";
3737
```

src/index.d.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,16 @@ export type * from "./types.d.ts";
2121
*/
2222
export declare const cx: <T extends CnOptions>(...classes: T) => CnReturn;
2323

24+
/**
25+
* Type representing a callable function that can also be coerced to a string.
26+
* This allows `cn` to work both as a function and directly in template literals.
27+
*/
28+
type CnCallable = ((config?: TWMConfig) => CnReturn) & {
29+
toString(): string;
30+
valueOf(): CnReturn;
31+
[Symbol.toPrimitive](hint: "string" | "number" | "default"): string | CnReturn;
32+
} & string;
33+
2434
/**
2535
* Combines class names and merges conflicting Tailwind CSS classes using `tailwind-merge`.
2636
* @param classes - Class names to combine (strings, arrays, objects, etc.)
@@ -39,7 +49,7 @@ export declare const cx: <T extends CnOptions>(...classes: T) => CnReturn;
3949
* // Use: cx('bg-red-500', 'bg-blue-500') // => 'bg-red-500 bg-blue-500'
4050
* ```
4151
*/
42-
export declare const cn: <T extends CnOptions>(...classes: T) => (config?: TWMConfig) => CnReturn;
52+
export declare const cn: <T extends CnOptions>(...classes: T) => CnCallable;
4353

4454
/**
4555
* Creates a variant-aware component function with Tailwind CSS classes.

0 commit comments

Comments
 (0)