tailwind-to-style 2.3.2 → 2.5.0
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/LICENSE +21 -0
- package/README.md +122 -3
- package/dist/index.d.ts +2 -0
- package/dist/index.esm.js +1013 -0
- package/index.js +895 -6397
- package/index.min.js +1 -1
- package/package.json +40 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 Bigetion
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
|
-
|
|
2
1
|
# tailwind-to-style
|
|
3
2
|
|
|
3
|
+
[](https://www.npmjs.com/package/tailwind-to-style)
|
|
4
|
+
[](https://github.com/Bigetion/tailwind-to-style/actions)
|
|
5
|
+
[](https://www.npmjs.com/package/tailwind-to-style)
|
|
6
|
+
[](https://github.com/Bigetion/tailwind-to-style/blob/main/LICENSE)
|
|
7
|
+
|
|
4
8
|
`tailwind-to-style` is a JavaScript library designed to convert Tailwind CSS utility classes into inline styles or JavaScript objects. This is especially useful when you need to dynamically apply styles to elements in frameworks like React, where inline styles or style objects are frequently used.
|
|
5
9
|
|
|
6
10
|
The library exposes two main functions:
|
|
@@ -71,7 +75,7 @@ This will apply the Tailwind classes directly as inline styles in the React comp
|
|
|
71
75
|
|
|
72
76
|
### 2. `twsx`
|
|
73
77
|
|
|
74
|
-
`twsx` is an advanced function that builds on `tws` by allowing you to define **nested styles** and more complex CSS structures. It supports **grouping**, **responsive variants**, **state variants**,
|
|
78
|
+
`twsx` is an advanced function that builds on `tws` by allowing you to define **nested styles** and more complex CSS structures. It supports **grouping**, **responsive variants**, **state variants**, **dynamic utilities**, and **direct CSS properties** via the `@css` directive, making it ideal for more advanced styling needs.
|
|
75
79
|
|
|
76
80
|
#### Features of `twsx`:
|
|
77
81
|
- Allows **nested styles** similar to SCSS, enabling more complex CSS structures.
|
|
@@ -79,6 +83,7 @@ This will apply the Tailwind classes directly as inline styles in the React comp
|
|
|
79
83
|
- Fully supports **responsive variants** (`sm`, `md`, `lg`, etc.).
|
|
80
84
|
- Handles **state variants** like `hover`, `focus`, and more.
|
|
81
85
|
- Supports **dynamic utilities** such as `w-[300px]`, `bg-[rgba(0,0,0,0.5)]`.
|
|
86
|
+
- **@css directive**: Apply custom CSS properties directly for more complex styles like transitions and animations.
|
|
82
87
|
|
|
83
88
|
#### Usage
|
|
84
89
|
|
|
@@ -227,9 +232,123 @@ console.log(styles);
|
|
|
227
232
|
}
|
|
228
233
|
```
|
|
229
234
|
|
|
235
|
+
#### `@css` Direct CSS Properties:
|
|
236
|
+
|
|
237
|
+
With the `@css` feature, you can directly add CSS properties that aren't available as Tailwind utilities or when you need more complex CSS values like transitions, animations, or custom properties.
|
|
238
|
+
|
|
239
|
+
There are several ways to use the `@css` feature:
|
|
240
|
+
|
|
241
|
+
1. **As a nested object inside selectors**:
|
|
242
|
+
|
|
243
|
+
```javascript
|
|
244
|
+
const styles = twsx({
|
|
245
|
+
".button": [
|
|
246
|
+
"bg-blue-500 text-white rounded-md",
|
|
247
|
+
{
|
|
248
|
+
"@css": {
|
|
249
|
+
transition: "all 0.3s ease-in-out",
|
|
250
|
+
"will-change": "transform, opacity"
|
|
251
|
+
},
|
|
252
|
+
"&:hover": "bg-blue-600"
|
|
253
|
+
}
|
|
254
|
+
]
|
|
255
|
+
});
|
|
256
|
+
```
|
|
257
|
+
|
|
258
|
+
**Output**:
|
|
259
|
+
```css
|
|
260
|
+
.button {
|
|
261
|
+
background-color: #3b82f6;
|
|
262
|
+
color: white;
|
|
263
|
+
border-radius: 0.375rem;
|
|
264
|
+
transition: all 0.3s ease-in-out;
|
|
265
|
+
will-change: transform, opacity;
|
|
266
|
+
}
|
|
267
|
+
.button:hover {
|
|
268
|
+
background-color: #2563eb;
|
|
269
|
+
}
|
|
270
|
+
```
|
|
271
|
+
|
|
272
|
+
2. **As a direct property in the selector**:
|
|
273
|
+
|
|
274
|
+
```javascript
|
|
275
|
+
const styles = twsx({
|
|
276
|
+
".button @css transition": "all 0.3s ease-in-out",
|
|
277
|
+
".button": "bg-blue-500 text-white rounded-md",
|
|
278
|
+
".button:hover": "bg-blue-600"
|
|
279
|
+
});
|
|
280
|
+
```
|
|
281
|
+
|
|
282
|
+
This syntax is especially useful when you need to add just a single CSS property that isn't available in Tailwind.
|
|
283
|
+
|
|
284
|
+
The `@css` feature is particularly helpful for properties that require complex values with spaces (like transitions, animations, and transforms) which can't be represented with standard Tailwind utility classes.
|
|
285
|
+
|
|
286
|
+
#### Advanced `@css` Examples:
|
|
287
|
+
|
|
288
|
+
You can combine `@css` with responsive and state variants:
|
|
289
|
+
|
|
290
|
+
```javascript
|
|
291
|
+
const styles = twsx({
|
|
292
|
+
".modal": [
|
|
293
|
+
"bg-white rounded-lg shadow-xl",
|
|
294
|
+
{
|
|
295
|
+
"@css": {
|
|
296
|
+
transform: "translateY(0)",
|
|
297
|
+
transition: "transform 0.3s ease-out, opacity 0.2s ease-in-out",
|
|
298
|
+
"will-change": "transform, opacity"
|
|
299
|
+
},
|
|
300
|
+
"&.hidden": [
|
|
301
|
+
"opacity-0",
|
|
302
|
+
{
|
|
303
|
+
"@css": {
|
|
304
|
+
transform: "translateY(-20px)"
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
],
|
|
308
|
+
"md:@css width": "500px",
|
|
309
|
+
"lg:@css width": "700px"
|
|
310
|
+
}
|
|
311
|
+
]
|
|
312
|
+
});
|
|
313
|
+
```
|
|
314
|
+
|
|
315
|
+
**Output**:
|
|
316
|
+
```css
|
|
317
|
+
.modal {
|
|
318
|
+
background-color: white;
|
|
319
|
+
border-radius: 0.5rem;
|
|
320
|
+
box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
|
|
321
|
+
transform: translateY(0);
|
|
322
|
+
transition: transform 0.3s ease-out, opacity 0.2s ease-in-out;
|
|
323
|
+
will-change: transform, opacity;
|
|
324
|
+
}
|
|
325
|
+
.modal.hidden {
|
|
326
|
+
opacity: 0;
|
|
327
|
+
transform: translateY(-20px);
|
|
328
|
+
}
|
|
329
|
+
@media (min-width: 768px) {
|
|
330
|
+
.modal {
|
|
331
|
+
width: 500px;
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
@media (min-width: 1024px) {
|
|
335
|
+
.modal {
|
|
336
|
+
width: 700px;
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
```
|
|
340
|
+
|
|
341
|
+
The `@css` feature provides a powerful way to bridge the gap between Tailwind's utility classes and custom CSS when needed, without leaving the `twsx` syntax.
|
|
342
|
+
|
|
343
|
+
## License
|
|
344
|
+
|
|
345
|
+
## Contributing
|
|
346
|
+
|
|
347
|
+
Contributions are welcome! Please see our [Contributing Guide](CONTRIBUTING.md) for more details.
|
|
348
|
+
|
|
230
349
|
## License
|
|
231
350
|
|
|
232
|
-
This
|
|
351
|
+
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
|
|
233
352
|
|
|
234
353
|
---
|
|
235
354
|
|
package/dist/index.d.ts
ADDED