
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
styled-cva
Advanced tools
A typesafe, class-variance-authority-based, styled-components-like library for authoring React components
⚠️ styled-cva 0.4.x only supports React 19.x. If you're on React 18, use the latest 0.3.x ⚠️
A typesafe, class-variance-authority-based, styled-components-like library for authoring React components
npm
npm i --save styled-cva
pnpm
pnpm add styled-cva
bun
bun add styled-cva
basic
import tw from "styled-cva";
const StaticButton = tw.button`
bg-primary rounded-xl cursor-pointer
`;
// ...
<StaticButton>Click Me</StaticButton>;
variants
import tw from "styled-cva";
const VariantButton = tw.button.cva("btn-base-class", {
variants: {
// smart disappearing props:
// variant keys starting with $ will not be sent to the DOM,
// this avoids extraneous props warning
$variant: {
primary: "btn-primary-class",
secondary: "btn-secondary-class",
},
},
});
// ...
// $variant is infered to 'primary' | 'secondary'
<VariantButton $variant="primary">Click Me</VariantButton>;
// actual element in the dom will be:
// <button class="btn-primary-class">Click Me</button>
withProps
const StyledButton = tw.button
.cva("btn-base", {
variants: {
$variant: {
primary: "btn-primary",
secondary: "btn-secondary",
},
},
})
.withProps({
"data-testid": "my-button",
type: "button",
$variant: "primary", // Valid variant value
});
// The component now has default props applied
<StyledButton>Click Me</StyledButton>;
// User props override defaults
<StyledButton $variant="secondary" type="submit">
Submit
</StyledButton>;
proxy
import Link from "next/link";
const Button = tw.button.cva("btn", {
variants: {
$variant: {
primary: "btn-primary",
secondary: "btn-secondary",
},
},
});
// ...
// works with known jsx elements
<Button $as="a" href="/some/url">
I'm a link that looks like a button
</Button>;
// also with custom components
<Button $as={Link} href="/some/url">
I'm a link that looks like a button
</Button>;
For tailwindcss extension support, add this to your vscode settings.json
// tailwindcss intelisense settings
"tailwindCSS.emmetCompletions": true,
"tailwindCSS.includeLanguages": {
"typescript": "javascript", // if you are using typescript
"typescriptreact": "javascript" // if you are using typescript with react
},
"tailwindCSS.experimental.classRegex": [
"tw`([^`]*)", // tw`...`
"tw\\.[^`]+`([^`]*)`", // tw.xxx<xxx>`...`
"tw\\(.*?\\).*?`([^`]*)", // tw(Component)<xxx>`...`
["cva\\(([^)]*)\\)", "[\"'`]([^\"'`]*).*?[\"'`]"]
],
"editor.quickSuggestions": {
"strings": true // forces VS Code to trigger completions when editing "string" content
},
License - Apache-2.0
FAQs
A typesafe, class-variance-authority-based, styled-components-like library for authoring React components
We found that styled-cva 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
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.