styled-cva
A typesafe, class-variance-authority-based, styled-components-like library for authoring React, Solid, Vue, and ReScript components.
import from "@styled-cva/react";
// Intrinsic CVA shorthand with typed variant inference
export const = .(
"inline-flex items-center justify-center rounded-md font-medium transition-colors",
{
: {
: {
: "bg-blue-600 text-white hover:bg-blue-700",
: "bg-slate-100 text-slate-900 hover:bg-slate-200",
},
: {
: "h-8 px-3 text-xs",
: "h-10 px-4 text-sm",
},
},
: {
: "primary",
: "md",
},
},
);
// Full autocompletion on $variant and $size props:
export const = () => (
< ="primary" ="md">
Click me
</>
);
import from "next/link";
import from "@styled-cva/react";
export const = .(
"inline-flex items-center justify-center rounded-md px-4 py-2 font-medium",
{
: {
: {
: "bg-blue-600 text-white",
: "bg-transparent text-slate-700",
},
},
},
);
// $as swaps the element or custom component while keeping variant typings
export const = () => (
< ="flex gap-2">
< ="a" ="https://github.com/alanrsoares/styled-cva">
GitHub
</>
< ={} ="/docs" ="primary">
Documentation
</>
</>
);
import from "@styled-cva/react";
// Tagged template syntax with Tailwind CSS utilities
export const = .`
rounded-xl border border-slate-200 bg-white p-6 shadow-sm
transition-shadow hover:shadow-md
`;
export const = .`
text-lg font-semibold text-slate-900
`;
export const = .`
mt-1 text-sm text-slate-500
`;
Type-Safe CVA Variants
First-class TypeScript inference for variant props, default variants, and compound variants without boilerplate.
Intrinsic CVA Shorthand
Author components directly with tw.button(base, config) — clean, concise, and familiar styled syntax.
Multi-Framework & Polymorphic
Available for React, Solid, Vue, and ReScript. Polymorphic $as prop support to easily swap elements or custom components.
Dedicated Tooling
Official ESLint, Prettier, and Biome plugins to enforce clean Tailwind class strings and auto-extract styled components.