Skip to content

Commit

Permalink
Merge branch 'main' into mbm/fix-class-type
Browse files Browse the repository at this point in the history
  • Loading branch information
mskelton committed Sep 6, 2023
2 parents 145a68a + 35c7854 commit cc5bc05
Show file tree
Hide file tree
Showing 5 changed files with 301 additions and 111 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "tailwind-variants",
"version": "0.1.13",
"version": "0.1.14",
"description": "🦄 Tailwindcss first-class variant API",
"author": "Junior Garcia <jrgarciadev@gmail.com>",
"license": "MIT",
Expand Down Expand Up @@ -96,7 +96,7 @@
"esm"
]
},
"packageManager": "pnpm@8.3.1",
"packageManager": "pnpm@8.6.8",
"engines": {
"node": ">=16.x",
"pnpm": ">=7.x"
Expand Down
142 changes: 142 additions & 0 deletions src/__tests__/tv.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -691,6 +691,148 @@ describe("Tailwind Variants (TV) - Slots", () => {
expectTv(list(), ["list-none", "color--secondary-list", "compound--list"]);
expectTv(wrapper(), ["flex", "flex-col", "color--secondary-wrapper", "compound--wrapper"]);
});

test("should support slot level variant overrides", () => {
const menu = tv({
base: "text-3xl",
slots: {
title: "text-2xl",
},
variants: {
color: {
primary: {
base: "color--primary-base",
title: "color--primary-title",
},
secondary: {
base: "color--secondary-base",
title: "color--secondary-title",
},
},
},
defaultVariants: {
color: "primary",
},
});

const {base, title} = menu();

expectTv(base(), ["text-3xl", "color--primary-base"]);
expectTv(title(), ["text-2xl", "color--primary-title"]);
expectTv(base({color: "secondary"}), ["text-3xl", "color--secondary-base"]);
expectTv(title({color: "secondary"}), ["text-2xl", "color--secondary-title"]);
});

test("should support slot level variant overrides - compoundSlots", () => {
const menu = tv({
base: "text-3xl",
slots: {
title: "text-2xl",
subtitle: "text-xl",
},
variants: {
color: {
primary: {
base: "color--primary-base",
title: "color--primary-title",
subtitle: "color--primary-subtitle",
},
secondary: {
base: "color--secondary-base",
title: "color--secondary-title",
subtitle: "color--secondary-subtitle",
},
},
},
compoundSlots: [
{
slots: ["title", "subtitle"],
color: "secondary",
class: ["truncate"],
},
],
defaultVariants: {
color: "primary",
},
});

const {base, title, subtitle} = menu();

expectTv(base(), ["text-3xl", "color--primary-base"]);
expectTv(title(), ["text-2xl", "color--primary-title"]);
expectTv(subtitle(), ["text-xl", "color--primary-subtitle"]);
expectTv(base({color: "secondary"}), ["text-3xl", "color--secondary-base"]);
expectTv(title({color: "secondary"}), ["text-2xl", "color--secondary-title", "truncate"]);
expectTv(subtitle({color: "secondary"}), ["text-xl", "color--secondary-subtitle", "truncate"]);
});

test("should support slot level variant and array variants overrides - compoundSlots", () => {
const menu = tv({
slots: {
base: "flex flex-wrap",
cursor: ["absolute", "flex", "overflow-visible"],
},
variants: {
size: {
xs: {},
sm: {},
},
},
compoundSlots: [
{
slots: ["base"],
size: ["xs", "sm"],
class: "w-7 h-7 text-xs",
},
],
});

const {base, cursor} = menu();

expect(base()).toEqual("flex flex-wrap w-7 h-7 text-xs");
expect(base({size: "xs"})).toEqual("flex flex-wrap w-7 h-7 text-xs");
expect(base({size: "sm"})).toEqual("flex flex-wrap w-7 h-7 text-xs");
expect(cursor()).toEqual("absolute flex overflow-visible");
});

test("should support slot level variant overrides - compoundVariants", () => {
const menu = tv({
base: "text-3xl",
slots: {
title: "text-2xl",
},
variants: {
color: {
primary: {
base: "color--primary-base",
title: "color--primary-title",
},
secondary: {
base: "color--secondary-base",
title: "color--secondary-title",
},
},
},
compoundVariants: [
{
color: "secondary",
class: {
title: "truncate",
},
},
],
defaultVariants: {
color: "primary",
},
});

const {base, title} = menu();

expectTv(base(), ["text-3xl", "color--primary-base"]);
expectTv(title(), ["text-2xl", "color--primary-title"]);
expectTv(base({color: "secondary"}), ["text-3xl", "color--secondary-base"]);
expectTv(title({color: "secondary"}), ["text-2xl", "color--secondary-title", "truncate"]);
});
});

describe("Tailwind Variants (TV) - Compound Slots", () => {
Expand Down
4 changes: 2 additions & 2 deletions src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,8 @@ export type TVReturnType<
(props?: TVProps<V, S, C, EV, ES>): ES extends undefined
? S extends undefined
? string
: {[K in TVSlotsWithBase<S, B>]: (slotProps?: ClassProp) => string}
: {[K in TVSlotsWithBase<ES & S, B>]: (slotProps?: ClassProp) => string};
: {[K in TVSlotsWithBase<S, B>]: (slotProps?: TVProps<V, S, C, EV, ES>) => string}
: {[K in TVSlotsWithBase<ES & S, B>]: (slotProps?: TVProps<V, S, C, EV, ES>) => string};
} & TVReturnProps<V, S, B, EV, ES, E>;

export type TV = {
Expand Down
Loading

0 comments on commit cc5bc05

Please sign in to comment.