css-variants 2.2.1 → 2.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +95 -39
  2. package/package.json +2 -1
package/README.md CHANGED
@@ -1,35 +1,42 @@
1
+ <div align="center">
2
+
1
3
  # css-variants
2
4
 
3
- > **Zero-dependency, type-safe CSS variant composition for modern JavaScript**
5
+ **Zero-dependency, type-safe CSS variant composition for modern JavaScript**
4
6
 
5
- Build powerful, flexible component style systems with variants. Perfect for Tailwind CSS, vanilla CSS, or any CSS-in-JS solution.
7
+ Build powerful, flexible component style systems with variants.<br/>
8
+ Perfect for Tailwind CSS, vanilla CSS, or any CSS-in-JS solution.
6
9
 
7
10
  [![test](https://github.com/timphandev/css-variants/actions/workflows/ci.yml/badge.svg)](https://github.com/timphandev/css-variants/actions/workflows/ci.yml)
8
11
  [![npm version](https://img.shields.io/npm/v/css-variants.svg)](https://www.npmjs.com/package/css-variants)
9
12
  [![Bundle Size](https://img.shields.io/bundlephobia/minzip/css-variants)](https://bundlephobia.com/package/css-variants)
10
13
  [![TypeScript](https://img.shields.io/badge/TypeScript-100%25-blue)](https://www.typescriptlang.org/)
11
14
  [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
12
- [![Give a Star](https://img.shields.io/badge/⭐️%20Give%20a%20Star-support%20the%20project-ffcc00)](https://github.com/timphandev/css-variants)
13
15
 
14
- ## Features
16
+ [Documentation](https://css-variants.vercel.app/) · [Getting Started](https://css-variants.vercel.app/getting-started/introduction/) · [API Reference](https://css-variants.vercel.app/api/cv/)
17
+
18
+ </div>
19
+
20
+ ---
15
21
 
16
- - **Tiny & Fast** — Zero dependencies, ~1KB minified+gzipped
17
- - 🔒 **Type-Safe** — First-class TypeScript support with complete type inference
18
- - 🧩 **Flexible** — Works with Tailwind, CSS modules, vanilla CSS, or inline styles
19
- - 👨‍💻 **Developer-Friendly** — Intuitive API inspired by CVA and Panda CSS
20
- - 🚀 **Production-Ready**Battle-tested, fully tested, dual CJS/ESM builds
22
+ ## Why css-variants?
23
+
24
+ | | Feature |
25
+ |---|---------|
26
+ | | **~1KB** — Zero dependencies, tree-shakeable |
27
+ | 🔒 | **Type-Safe** — Full TypeScript inference for variants & props |
28
+ | 🧩 | **Flexible** — Works with Tailwind, CSS Modules, vanilla CSS, inline styles |
29
+ | 🚀 | **Fast** — Up to 10x faster than alternatives in complex scenarios |
21
30
 
22
31
  ## Installation
23
32
 
24
33
  ```bash
25
34
  npm install css-variants
26
- # or
27
- yarn add css-variants
28
- # or
29
- pnpm add css-variants
30
35
  ```
31
36
 
32
- ## Quick Example
37
+ ## Quick Start
38
+
39
+ ### Single-Element Variants (`cv`)
33
40
 
34
41
  ```typescript
35
42
  import { cv } from 'css-variants'
@@ -43,49 +50,98 @@ const button = cv({
43
50
  },
44
51
  size: {
45
52
  sm: 'px-3 py-1.5 text-sm',
46
- md: 'px-4 py-2 text-base',
47
53
  lg: 'px-6 py-3 text-lg',
48
54
  },
49
55
  },
50
- defaultVariants: {
51
- color: 'primary',
52
- size: 'md',
56
+ defaultVariants: { color: 'primary', size: 'sm' },
57
+ })
58
+
59
+ button() // Primary + Small (defaults)
60
+ button({ color: 'secondary' }) // Secondary + Small
61
+ button({ size: 'lg', className: 'w-full' }) // Primary + Large + custom class
62
+ ```
63
+
64
+ ### Multi-Element Components (`scv`)
65
+
66
+ ```typescript
67
+ import { scv } from 'css-variants'
68
+
69
+ const card = scv({
70
+ slots: ['root', 'header', 'body', 'footer'],
71
+ base: {
72
+ root: 'rounded-xl border shadow-sm',
73
+ header: 'px-6 py-4 border-b',
74
+ body: 'px-6 py-4',
75
+ footer: 'px-6 py-3 bg-gray-50',
76
+ },
77
+ variants: {
78
+ variant: {
79
+ default: { root: 'bg-white border-gray-200' },
80
+ danger: { root: 'bg-red-50 border-red-200', header: 'text-red-900' },
81
+ },
53
82
  },
54
83
  })
55
84
 
56
- button() // => 'font-semibold rounded-lg ... bg-blue-600 text-white ... px-4 py-2 text-base'
57
- button({ color: 'secondary', size: 'lg' }) // => '... bg-gray-200 text-gray-900 ... px-6 py-3 text-lg'
85
+ const styles = card({ variant: 'danger' })
86
+ // styles.root → 'rounded-xl border shadow-sm bg-red-50 border-red-200'
87
+ // styles.header → 'px-6 py-4 border-b text-red-900'
58
88
  ```
59
89
 
60
- ## Documentation
90
+ ### Compound Variants
61
91
 
62
- **[View full documentation →](https://css-variants.vercel.app/)**
92
+ Apply styles when multiple variants match:
63
93
 
64
- - [Getting Started](https://css-variants.vercel.app/getting-started/introduction/)
65
- - [Core Concepts](https://css-variants.vercel.app/core-concepts/variants/)
66
- - [API Reference](https://css-variants.vercel.app/api/cv/)
67
- - [Tailwind CSS Integration](https://css-variants.vercel.app/guides/tailwind/)
94
+ ```typescript
95
+ const button = cv({
96
+ variants: {
97
+ color: { primary: '...', danger: '...' },
98
+ size: { sm: '...', lg: '...' },
99
+ },
100
+ compoundVariants: [
101
+ { color: 'danger', size: 'lg', className: 'font-bold uppercase' },
102
+ ],
103
+ })
104
+ ```
68
105
 
69
- ## Contributing
106
+ ### Style Variants (`sv`)
70
107
 
71
- Contributions are welcome! Please read our [contributing guidelines](CONTRIBUTING.md) before submitting PRs.
108
+ For inline styles instead of class names:
72
109
 
73
- **Development Setup:**
110
+ ```typescript
111
+ import { sv } from 'css-variants'
74
112
 
75
- ```bash
76
- git clone https://github.com/timphandev/css-variants.git
77
- cd css-variants
78
- yarn install
79
- yarn test
80
- yarn build
113
+ const box = sv({
114
+ base: { display: 'flex', borderRadius: '8px' },
115
+ variants: {
116
+ size: {
117
+ sm: { padding: '8px' },
118
+ lg: { padding: '24px' },
119
+ },
120
+ },
121
+ })
122
+
123
+ box({ size: 'lg' }) // => { display: 'flex', borderRadius: '8px', padding: '24px' }
81
124
  ```
82
125
 
83
- ## ⭐ Like it? Star it!
126
+ ## Performance
84
127
 
85
- If this library saves you time, a **⭐ on GitHub** means a lot. Thank you! 🚀
128
+ | vs cva | vs tailwind-variants |
129
+ |:------:|:--------------------:|
130
+ | 3-4x faster (compound variants) | 5-6x faster (compound variants) |
131
+ | 4-9x faster (complex components) | 10-11x faster (complex components) |
132
+
133
+ ## Documentation
134
+
135
+ **[Full documentation →](https://css-variants.vercel.app/)**
136
+
137
+ ## Contributing
138
+
139
+ ```bash
140
+ git clone https://github.com/timphandev/css-variants.git
141
+ cd css-variants && yarn install
142
+ yarn test && yarn build
143
+ ```
86
144
 
87
145
  ## License
88
146
 
89
147
  MIT © [Tim Phan](https://github.com/timphandev)
90
-
91
- **Made with ❤️ by developers, for developers**
package/package.json CHANGED
@@ -1,7 +1,8 @@
1
1
  {
2
2
  "name": "css-variants",
3
- "version": "2.2.1",
3
+ "version": "2.2.2",
4
4
  "description": "Lightweight helpers to compose class names and inline styles using variants. Zero runtime deps, small bundle, and first-class TypeScript support.",
5
+ "homepage": "https://css-variants.vercel.app",
5
6
  "main": "dist/cjs/index.js",
6
7
  "module": "dist/esm/index.js",
7
8
  "types": "dist/esm/index.d.ts",