
Security News
Axios Supply Chain Attack Reaches OpenAI macOS Signing Pipeline, Forces Certificate Rotation
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.
@gentleduck/variants
Advanced tools
A package for creating variants of components, providing a simple and efficient way to create variants of components.
@gentleduck/variantsA lightweight utility for generating class names based on variant configurations. Inspired by Tailwind and class-variance-authority, @gentleduck/variants helps you manage and compose class names in a flexible, type-safe, and declarative way.
At gentleduck, we believe that developer tools should be fast, reliable, and actively maintained — not abandoned. While class-variance-authority initially inspired the idea of variant-based class management, its situation has become unacceptable:
despite having over 6 million weekly downloads, the project has been left poorly maintained for more than 6 months, with important pull requests and bug fixes sitting untouched.
Leaving a critical utility like this in a broken or half-maintained state is unacceptable to us at gentleduck.
So, we took action: we rewrote the library from scratch with our own vision and philosophy — making it more modern, more reliable, and up to 7× faster.
Our goal with @gentleduck/variants is simple:
to offer the community a serious, well-maintained, and future-proof alternative — one that developers can trust today and for the years to come.
@gentleduck/variants?@gentleduck/variants: ~7x faster than [class-variance-authority](https://www.npmjs.com/package/class-variance-authority)

npm install @gentleduck/variants
# or
yarn add @gentleduck/variants
# or
bun add @gentleduck/variants
@gentleduck/variants lets you declare your style variants once and get back a function that produces perfectly composed class names, complete with defaults, compounds, nested arrays, and conditional objects.
import { cva } from '@gentleduck/variants'
const button = cva('btn', {
variants: {
size: {
sm: 'px-2 py-1 text-sm',
md: 'px-4 py-2 text-base',
lg: 'px-6 py-3 text-lg',
},
color: {
primary: 'bg-blue-500 text-white',
secondary: 'bg-gray-100 text-gray-800',
},
},
defaultVariants: {
size: 'md',
color: 'primary',
},
compoundVariants: [
{ size: 'lg', color: 'primary', className: 'uppercase font-bold' },
],
})
button()
// => 'btn px-4 py-2 text-base bg-blue-500 text-white uppercase font-bold'
button({ size: 'sm', class: ['rounded', 'shadow'] })
// => 'btn px-2 py-1 text-sm bg-blue-500 text-white rounded shadow'
You can supply arrays of classes or nested arrays for fine-grained control:
const badge = cva('badge', {
variants: {
size: {
sm: ['badge-sm', 'text-xs'],
lg: ['badge-lg', 'text-lg'],
},
tone: {
muted: ['opacity-50', ['italic']],
loud: ['opacity-100', { 'font-bold': true }],
},
},
defaultVariants: {
size: 'sm',
tone: 'muted',
},
})
badge({ size: 'lg', tone: 'loud' })
// => 'badge badge-lg text-lg opacity-100 font-bold'
Apply extra classes when multiple variant values match:
const card = cva('card', {
variants: {
size: { small: 'card-sm', large: 'card-lg' },
color: { primary: 'card-primary', secondary: 'card-secondary' },
},
defaultVariants: { size: 'small', color: 'primary' },
compoundVariants: [
{ size: 'large', color: 'primary', class: 'shadow-xl' },
{ size: 'small', color: ['secondary', 'primary'], className: 'border-dashed' },
],
})
card({ size: 'large', color: 'primary' })
// => 'card card-lg card-primary shadow-xl'
Built from the ground up with TypeScript:
VariantProps<> to extract only variant-related propsconst alert = cva('alert', {
variants: {
severity: {
info: 'alert-info',
error: 'alert-error',
},
},
defaultVariants: {
severity: 'info',
},
})
// OK
alert({ severity: 'error' })
// TS Error: 'warning' is not a valid severity
alert({ severity: 'warning' })
Compose one CVA function with another, or extend defaults:
const baseButton = cva('btn', {
variants: { size: { sm: 'btn-sm', lg: 'btn-lg' } },
defaultVariants: { size: 'sm' },
})
const largePrimary = cva(baseButton, {
defaultVariants: { size: 'lg' },
})
largePrimary({ className: 'mx-2' })
// => 'btn btn-lg mx-2'
You can also simply concatenate:
const icon = cva('icon', { variants: { type: { arrow: 'icon-arrow' } } })
`${button()} ${icon({ type: 'arrow' })}`
// => 'btn px-4 py-2 text-base bg-blue-500 text-white uppercase font-bold icon icon-arrow'
cva(base, options) / cva(optionsWithBase)Creates your CVA function:
type CvaFn<T> = (
props?: VariantProps<T> & {
class?: ClassValue
className?: ClassValue
}
) => string
base: string — always-included classesvariants — map of variant names -> (value -> class/string[])defaultVariants? — fallback valuescompoundVariants? — apply extra classes when multiple values matchOverloads:
// Two-arg form
const fn = cva('base', { variants, defaultVariants, compoundVariants })
// Single-arg form
const fn = cva({ base: 'base', variants, defaultVariants, compoundVariants })
MIT © gentleduck
FAQs
A package for creating variants of components, providing a simple and efficient way to create variants of components.
We found that @gentleduck/variants demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.

Security News
Open source is under attack because of how much value it creates. It has been the foundation of every major software innovation for the last three decades. This is not the time to walk away from it.

Security News
Socket CEO Feross Aboukhadijeh breaks down how North Korea hijacked Axios and what it means for the future of software supply chain security.