css-variants 2.3.2 → 2.3.3

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 +147 -0
  2. package/package.json +1 -1
package/README.md ADDED
@@ -0,0 +1,147 @@
1
+ <div align="center">
2
+
3
+ # css-variants
4
+
5
+ **Zero-dependency, type-safe CSS variant composition for modern JavaScript**
6
+
7
+ Build powerful, flexible component style systems with variants.<br/>
8
+ Perfect for Tailwind CSS, vanilla CSS, or any CSS-in-JS solution.
9
+
10
+ [![test](https://github.com/timphandev/css-variants/actions/workflows/packages.css-variants.test.yml/badge.svg)](https://github.com/timphandev/css-variants/actions/workflows/packages.css-variants.test.yml)
11
+ [![npm version](https://img.shields.io/npm/v/css-variants.svg)](https://www.npmjs.com/package/css-variants)
12
+ [![Bundle Size](https://img.shields.io/bundlephobia/minzip/css-variants)](https://bundlephobia.com/package/css-variants)
13
+ [![TypeScript](https://img.shields.io/badge/TypeScript-100%25-blue)](https://www.typescriptlang.org/)
14
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
15
+
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
+ ---
21
+
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 |
30
+
31
+ ## Installation
32
+
33
+ ```bash
34
+ npm install css-variants
35
+ ```
36
+
37
+ ## Quick Start
38
+
39
+ ### Single-Element Variants (`cv`)
40
+
41
+ ```typescript
42
+ import { cv } from 'css-variants'
43
+
44
+ const button = cv({
45
+ base: 'font-semibold rounded-lg transition-colors',
46
+ variants: {
47
+ color: {
48
+ primary: 'bg-blue-600 text-white hover:bg-blue-700',
49
+ secondary: 'bg-gray-200 text-gray-900 hover:bg-gray-300',
50
+ },
51
+ size: {
52
+ sm: 'px-3 py-1.5 text-sm',
53
+ lg: 'px-6 py-3 text-lg',
54
+ },
55
+ },
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
+ },
82
+ },
83
+ })
84
+
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'
88
+ ```
89
+
90
+ ### Compound Variants
91
+
92
+ Apply styles when multiple variants match:
93
+
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
+ ```
105
+
106
+ ### Style Variants (`sv`)
107
+
108
+ For inline styles instead of class names:
109
+
110
+ ```typescript
111
+ import { sv } from 'css-variants'
112
+
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' }
124
+ ```
125
+
126
+ ## Performance
127
+
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 css-variants test && yarn css-variants build
143
+ ```
144
+
145
+ ## License
146
+
147
+ MIT © [Tim Phan](https://github.com/timphandev)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "css-variants",
3
- "version": "2.3.2",
3
+ "version": "2.3.3",
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
5
  "homepage": "https://css-variants.vercel.app",
6
6
  "type": "module",