tailwind-to-style 3.0.0 → 3.1.1
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 +74 -0
- package/dist/index.cjs +679 -38
- package/dist/index.d.ts +101 -0
- package/dist/index.esm.js +679 -39
- package/dist/index.min.js +1 -1
- package/dist/index.min.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -156,6 +156,80 @@ const formatted = twsx(styles, { format: 'pretty' })
|
|
|
156
156
|
- `'.nested'` - Descendants
|
|
157
157
|
- `'@media ...'` - Media queries (root level only)
|
|
158
158
|
|
|
159
|
+
### `twsxVariants(className, config)`
|
|
160
|
+
|
|
161
|
+
Create variant-based component styles with automatic CSS generation. Similar to `tailwind-variants` but with auto-injection.
|
|
162
|
+
|
|
163
|
+
```javascript
|
|
164
|
+
import { twsxVariants } from 'tailwind-to-style'
|
|
165
|
+
|
|
166
|
+
const btn = twsxVariants('.btn', {
|
|
167
|
+
base: 'px-4 py-2 rounded-lg font-medium transition-all',
|
|
168
|
+
variants: {
|
|
169
|
+
variant: {
|
|
170
|
+
solid: 'border-transparent',
|
|
171
|
+
outline: 'bg-transparent border-2',
|
|
172
|
+
ghost: 'bg-transparent',
|
|
173
|
+
},
|
|
174
|
+
color: {
|
|
175
|
+
primary: 'bg-blue-500 text-white hover:bg-blue-600',
|
|
176
|
+
danger: 'bg-red-500 text-white hover:bg-red-600',
|
|
177
|
+
},
|
|
178
|
+
size: {
|
|
179
|
+
sm: 'px-3 py-1.5 text-sm',
|
|
180
|
+
md: 'px-4 py-2 text-base',
|
|
181
|
+
lg: 'px-6 py-3 text-lg',
|
|
182
|
+
},
|
|
183
|
+
},
|
|
184
|
+
compoundVariants: [
|
|
185
|
+
{ variant: 'outline', color: 'primary', class: 'border-blue-500 text-blue-600' },
|
|
186
|
+
{ variant: 'outline', color: 'danger', class: 'border-red-500 text-red-600' },
|
|
187
|
+
],
|
|
188
|
+
defaultVariants: { variant: 'solid', color: 'primary', size: 'md' }
|
|
189
|
+
})
|
|
190
|
+
|
|
191
|
+
// Usage - returns class name string
|
|
192
|
+
btn() // "btn"
|
|
193
|
+
btn({ color: 'danger' }) // "btn btn-danger"
|
|
194
|
+
btn({ variant: 'outline', size: 'lg' }) // "btn btn-outline-lg"
|
|
195
|
+
|
|
196
|
+
// In React
|
|
197
|
+
const Button = ({ variant, color, size, children, ...props }) => (
|
|
198
|
+
<button className={btn({ variant, color, size })} {...props}>
|
|
199
|
+
{children}
|
|
200
|
+
</button>
|
|
201
|
+
)
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
**Nested Selectors** - Style child elements:
|
|
205
|
+
|
|
206
|
+
```javascript
|
|
207
|
+
const alert = twsxVariants('.alert', {
|
|
208
|
+
base: 'p-4 rounded-lg border flex gap-3',
|
|
209
|
+
variants: {
|
|
210
|
+
status: {
|
|
211
|
+
info: 'bg-blue-50 text-blue-800',
|
|
212
|
+
error: 'bg-red-50 text-red-800',
|
|
213
|
+
},
|
|
214
|
+
},
|
|
215
|
+
defaultVariants: { status: 'info' },
|
|
216
|
+
nested: {
|
|
217
|
+
'.alert-icon': 'flex-shrink-0 mt-0.5',
|
|
218
|
+
'.alert-content': 'flex-1',
|
|
219
|
+
'.alert-dismiss': 'p-1 rounded hover:bg-black/10',
|
|
220
|
+
}
|
|
221
|
+
})
|
|
222
|
+
|
|
223
|
+
// Generates CSS:
|
|
224
|
+
// .alert .alert-icon { ... }
|
|
225
|
+
// .alert .alert-content { ... }
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
**Class Naming Convention:**
|
|
229
|
+
- `.btn` = all defaults
|
|
230
|
+
- `.btn-outline` = outline variant (non-default)
|
|
231
|
+
- `.btn-outline-danger-lg` = multiple non-defaults
|
|
232
|
+
|
|
159
233
|
### `configure(config)`
|
|
160
234
|
|
|
161
235
|
Customize theme with your colors, spacing, fonts, and more.
|