css-variants 2.0.7 → 2.0.8
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.
- package/README.md +79 -10
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-

|
|
2
|
-
|
|
3
1
|
[](https://github.com/timphandev/css-variants/actions/workflows/ci.yml)
|
|
4
2
|
[](https://github.com/timphandev/css-variants/blob/main/LICENSE)
|
|
5
3
|
[](https://npmjs.com/package/css-variants)
|
|
@@ -38,12 +36,13 @@ pnpm add css-variants
|
|
|
38
36
|
|
|
39
37
|
css-variants provides four main utilities:
|
|
40
38
|
|
|
41
|
-
- [cv](
|
|
42
|
-
- [sv](
|
|
43
|
-
- [scv](
|
|
44
|
-
- [ssv](
|
|
39
|
+
- [cv](#class-variants-cv) - Class Variants for managing single component class names
|
|
40
|
+
- [sv](#style-variants-sv) - Style Variants for managing single component inline styles
|
|
41
|
+
- [scv](#slot-class-variants-scv) - Slot Class Variants for managing multiple slot class names
|
|
42
|
+
- [ssv](#slot-style-variants-ssv) - Slot Style Variants for managing multiple slot inline styles
|
|
43
|
+
- [cx](#class-merger-cx) - Utility for composing class names conditionally.
|
|
45
44
|
|
|
46
|
-
### Class Variants (cv)
|
|
45
|
+
### Class Variants ([cv](./src/cv.ts))
|
|
47
46
|
For managing class names for a single component:
|
|
48
47
|
|
|
49
48
|
```ts
|
|
@@ -76,10 +75,13 @@ const button = cv({
|
|
|
76
75
|
|
|
77
76
|
// Usage
|
|
78
77
|
button() // => 'font-bold rounded-lg bg-blue-500 text-white text-sm px-2 py-1'
|
|
78
|
+
|
|
79
79
|
button({ size: 'lg' }) // => 'font-bold rounded-lg bg-blue-500 text-white text-lg px-4 py-2 uppercase'
|
|
80
|
+
|
|
81
|
+
button({ size: 'lg', className: 'custom' }) // => 'font-bold rounded-lg bg-blue-500 text-white text-lg px-4 py-2 uppercase custom'
|
|
80
82
|
```
|
|
81
83
|
|
|
82
|
-
### Style Variants (sv)
|
|
84
|
+
### Style Variants ([sv](./src/sv.ts))
|
|
83
85
|
|
|
84
86
|
For managing inline styles:
|
|
85
87
|
|
|
@@ -105,11 +107,18 @@ const button = sv({
|
|
|
105
107
|
}
|
|
106
108
|
})
|
|
107
109
|
|
|
110
|
+
// Usage
|
|
108
111
|
button({ color: 'primary' })
|
|
109
112
|
// => { fontWeight: 'bold', borderRadius: '8px', backgroundColor: 'blue', color: 'white' }
|
|
113
|
+
|
|
114
|
+
button({
|
|
115
|
+
color: 'secondary',
|
|
116
|
+
style: { padding: '4px' },
|
|
117
|
+
})
|
|
118
|
+
// => { fontWeight: 'bold', borderRadius: '8px', backgroundColor: 'gray', color: 'white', padding: '4px' }
|
|
110
119
|
```
|
|
111
120
|
|
|
112
|
-
### Slot Class Variants (scv)
|
|
121
|
+
### Slot Class Variants ([scv](./src/scv.ts))
|
|
113
122
|
|
|
114
123
|
For managing class names across multiple slots/elements:
|
|
115
124
|
|
|
@@ -144,9 +153,21 @@ card({ size: 'sm' })
|
|
|
144
153
|
// title: 'text-xl font-bold text-base',
|
|
145
154
|
// content: 'mt-2'
|
|
146
155
|
// }
|
|
156
|
+
|
|
157
|
+
card({
|
|
158
|
+
size: 'lg',
|
|
159
|
+
classNames: {
|
|
160
|
+
content: 'custom',
|
|
161
|
+
},
|
|
162
|
+
})
|
|
163
|
+
// => {
|
|
164
|
+
// root: 'rounded-lg shadow p-6',
|
|
165
|
+
// title: 'text-xl font-bold text-2xl',
|
|
166
|
+
// content: 'mt-2 custom'
|
|
167
|
+
// }
|
|
147
168
|
```
|
|
148
169
|
|
|
149
|
-
### Slot Style Variants (ssv)
|
|
170
|
+
### Slot Style Variants ([ssv](./src/ssv.ts))
|
|
150
171
|
|
|
151
172
|
For managing inline styles across multiple slots:
|
|
152
173
|
|
|
@@ -173,11 +194,57 @@ const card = ssv({
|
|
|
173
194
|
}
|
|
174
195
|
})
|
|
175
196
|
|
|
197
|
+
// Usage
|
|
176
198
|
card({ size: 'sm' })
|
|
177
199
|
// => {
|
|
178
200
|
// root: { padding: '1rem', maxWidth: '300px' },
|
|
179
201
|
// title: { fontWeight: 'bold', fontSize: '14px' }
|
|
180
202
|
// }
|
|
203
|
+
|
|
204
|
+
card({
|
|
205
|
+
size: 'lg',
|
|
206
|
+
styles: {
|
|
207
|
+
title: {
|
|
208
|
+
color: 'red',
|
|
209
|
+
},
|
|
210
|
+
},
|
|
211
|
+
})
|
|
212
|
+
// => {
|
|
213
|
+
// root: { padding: '1rem', maxWidth: '600px' },
|
|
214
|
+
// title: { fontWeight: 'bold', fontSize: '18px', color: 'red' }
|
|
215
|
+
// }
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
### Class Merger ([cx](./src/cx.ts))
|
|
219
|
+
|
|
220
|
+
Similar to `clsx/classnames` but with better TypeScript support.
|
|
221
|
+
|
|
222
|
+
```tsx
|
|
223
|
+
import { cx } from 'css-variants'
|
|
224
|
+
|
|
225
|
+
// Basic usage
|
|
226
|
+
cx('foo', 'bar') // => 'foo bar'
|
|
227
|
+
|
|
228
|
+
// With conditions
|
|
229
|
+
cx('foo', {
|
|
230
|
+
'bar': true,
|
|
231
|
+
'baz': false
|
|
232
|
+
}) // => 'foo bar'
|
|
233
|
+
|
|
234
|
+
// With arrays
|
|
235
|
+
cx('foo', ['bar', 'baz']) // => 'foo bar baz'
|
|
236
|
+
|
|
237
|
+
// With nested structures
|
|
238
|
+
cx('foo', {
|
|
239
|
+
bar: true,
|
|
240
|
+
baz: [
|
|
241
|
+
'qux',
|
|
242
|
+
{ quux: true }
|
|
243
|
+
]
|
|
244
|
+
}) // => 'foo bar qux quux'
|
|
245
|
+
|
|
246
|
+
// With falsy values (they're ignored)
|
|
247
|
+
cx('foo', null, undefined, false, 0, '') // => 'foo'
|
|
181
248
|
```
|
|
182
249
|
|
|
183
250
|
## Advanced Features
|
|
@@ -226,6 +293,8 @@ const button = cv({
|
|
|
226
293
|
}
|
|
227
294
|
]
|
|
228
295
|
})
|
|
296
|
+
|
|
297
|
+
button({ color: 'danger', size: 'lg' }) // => 'bg-red-500 text-lg animate-pulse'
|
|
229
298
|
```
|
|
230
299
|
|
|
231
300
|
### Default Variants
|