Skip to content

Commit

Permalink
fix: nested class value type (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
tianenpang authored Feb 1, 2023
1 parent debd6b2 commit a0150ed
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
39 changes: 39 additions & 0 deletions src/__tests__/tv.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1016,4 +1016,43 @@ describe("Tailwind Variants (TV)", () => {
"wrapper--size--medium",
]);
});

test("should work with nested arrays", () => {
const menu = tv({
base: ["base--styles-1", ["base--styles-2", ["base--styles-3"]]],
slots: {
item: ["slots--item-1", ["slots--item-2", ["slots--item-3"]]],
},
variants: {
color: {
primary: {
item: [
"item--color--primary-1",
["item--color--primary-2", ["item--color--primary-3"]],
],
},
},
},
});

const popover = tv({
variants: {
isOpen: {
true: ["isOpen--true-1", ["isOpen--true-2", ["isOpen--true-3"]]],
false: ["isOpen--false-1", ["isOpen--false-2", ["isOpen--false-3"]]],
},
},
});

const {base, item} = menu({color: "primary"});

expectTv(base(), ["base--styles-1", "base--styles-2", "base--styles-3"]);
expectTv(item(), [
"item--color--primary-1",
"item--color--primary-2",
"item--color--primary-3",
]);
expectTv(popover({isOpen: true}), ["isOpen--true-1", "isOpen--true-2", "isOpen--true-3"]);
expectTv(popover({isOpen: false}), ["isOpen--false-1", "isOpen--false-2", "isOpen--false-3"]);
});
});
2 changes: 1 addition & 1 deletion src/utils.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {TVConfig} from "./config";

export declare type ClassValue = string | string[] | null | undefined;
export declare type ClassValue = string | string[] | null | undefined | ClassValue[];

export declare type ClassProp<V extends unknown = ClassValue> =
| {
Expand Down

0 comments on commit a0150ed

Please sign in to comment.