Skip to content

Commit e4811f6

Browse files
authored
docs: add cva to benchmarks (#178)
1 parent 9effc2a commit e4811f6

File tree

3 files changed

+78
-0
lines changed

3 files changed

+78
-0
lines changed

benchmark.js

+63
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
/* eslint-disable no-console */
22
import Benchmark from "benchmark";
3+
import {cva} from "class-variance-authority";
4+
import {extendTailwindMerge} from "tailwind-merge";
35

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

@@ -322,6 +324,57 @@ export const avatarWithCustomConfig = tv(
322324
},
323325
);
324326

327+
// CVA without tw-merge config
328+
const cvaNoMerge = {
329+
avatar: cva("relative flex shrink-0 overflow-hidden rounded-full", {
330+
variants: {
331+
size: {
332+
xs: "h-6 w-6",
333+
sm: "h-8 w-8",
334+
md: "h-10 w-10",
335+
lg: "h-12 w-12",
336+
xl: "h-14 w-14",
337+
},
338+
},
339+
defaultVariants: {
340+
size: "md",
341+
},
342+
compoundVariants: [
343+
{
344+
size: ["xs", "sm"],
345+
class: "ring-1",
346+
},
347+
{
348+
size: ["md", "lg", "xl", "2xl"],
349+
class: "ring-2",
350+
},
351+
],
352+
}),
353+
image: cva("aspect-square h-full w-full", {
354+
variants: {
355+
withBorder: {
356+
true: "border-1.5 border-white",
357+
},
358+
},
359+
}),
360+
fallback: cva("flex h-full w-full items-center justify-center rounded-full bg-muted", {
361+
variants: {
362+
size: {
363+
xs: "text-xs",
364+
sm: "text-sm",
365+
md: "text-base",
366+
lg: "text-lg",
367+
xl: "text-xl",
368+
},
369+
},
370+
defaultVariants: {
371+
size: "md",
372+
},
373+
}),
374+
};
375+
376+
const cvaMerge = extendTailwindMerge({extend: twMergeConfig});
377+
325378
// add tests
326379
suite
327380
.add("TV without slots & tw-merge (enabled)", function () {
@@ -360,6 +413,16 @@ suite
360413
fallback();
361414
image();
362415
})
416+
.add("CVA without slots & tw-merge (enabled)", function () {
417+
cvaMerge(cvaNoMerge.avatar({size: "md"}));
418+
cvaMerge(cvaNoMerge.fallback());
419+
cvaMerge(cvaNoMerge.image());
420+
})
421+
.add("CVA without slots & tw-merge (disabled)", function () {
422+
cvaNoMerge.avatar({size: "md"});
423+
cvaNoMerge.fallback();
424+
cvaNoMerge.image();
425+
})
363426

364427
// add listeners
365428
.on("cycle", function (event) {

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
"@typescript-eslint/eslint-plugin": "^7.3.1",
5353
"@typescript-eslint/parser": "^7.3.1",
5454
"benchmark": "2.1.4",
55+
"class-variance-authority": "^0.7.0",
5556
"clean-package": "2.1.1",
5657
"eslint": "^8.57.0",
5758
"eslint-config-prettier": "^9.1.0",

pnpm-lock.yaml

+14
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)