Skip to content

Commit

Permalink
docs: add cva to benchmarks (#178)
Browse files Browse the repository at this point in the history
  • Loading branch information
mskelton committed May 13, 2024
1 parent 9effc2a commit e4811f6
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 0 deletions.
63 changes: 63 additions & 0 deletions benchmark.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
/* eslint-disable no-console */
import Benchmark from "benchmark";
import {cva} from "class-variance-authority";
import {extendTailwindMerge} from "tailwind-merge";

import {tv} from "./src/index.js";

Expand Down Expand Up @@ -322,6 +324,57 @@ export const avatarWithCustomConfig = tv(
},
);

// CVA without tw-merge config
const cvaNoMerge = {
avatar: cva("relative flex shrink-0 overflow-hidden rounded-full", {
variants: {
size: {
xs: "h-6 w-6",
sm: "h-8 w-8",
md: "h-10 w-10",
lg: "h-12 w-12",
xl: "h-14 w-14",
},
},
defaultVariants: {
size: "md",
},
compoundVariants: [
{
size: ["xs", "sm"],
class: "ring-1",
},
{
size: ["md", "lg", "xl", "2xl"],
class: "ring-2",
},
],
}),
image: cva("aspect-square h-full w-full", {
variants: {
withBorder: {
true: "border-1.5 border-white",
},
},
}),
fallback: cva("flex h-full w-full items-center justify-center rounded-full bg-muted", {
variants: {
size: {
xs: "text-xs",
sm: "text-sm",
md: "text-base",
lg: "text-lg",
xl: "text-xl",
},
},
defaultVariants: {
size: "md",
},
}),
};

const cvaMerge = extendTailwindMerge({extend: twMergeConfig});

// add tests
suite
.add("TV without slots & tw-merge (enabled)", function () {
Expand Down Expand Up @@ -360,6 +413,16 @@ suite
fallback();
image();
})
.add("CVA without slots & tw-merge (enabled)", function () {
cvaMerge(cvaNoMerge.avatar({size: "md"}));
cvaMerge(cvaNoMerge.fallback());
cvaMerge(cvaNoMerge.image());
})
.add("CVA without slots & tw-merge (disabled)", function () {
cvaNoMerge.avatar({size: "md"});
cvaNoMerge.fallback();
cvaNoMerge.image();
})

// add listeners
.on("cycle", function (event) {
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
"@typescript-eslint/eslint-plugin": "^7.3.1",
"@typescript-eslint/parser": "^7.3.1",
"benchmark": "2.1.4",
"class-variance-authority": "^0.7.0",
"clean-package": "2.1.1",
"eslint": "^8.57.0",
"eslint-config-prettier": "^9.1.0",
Expand Down
14 changes: 14 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit e4811f6

Please sign in to comment.