tailwind-to-style 2.10.0-beta.1 → 2.10.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.
package/README.md CHANGED
@@ -15,15 +15,14 @@ The library exposes two main functions and a CLI tool:
15
15
  2. **`twsx`**: A more advanced function that allows you to define nested and complex styles similar to SCSS, including support for responsive design, state variants, grouping, and enhanced CSS capabilities.
16
16
  3. **`twsx-cli`**: A command-line tool for generating CSS files from `twsx.*.js` files with watch mode support.
17
17
 
18
- ## ✨ What's New in v2.12.0
18
+ ## ✨ What's New in v2.10.2
19
19
 
20
- - 🎬 **Animation Support**: Full support for `animate-spin`, `animate-pulse`, `animate-bounce`, `animate-ping`!
21
- - 🔄 **Transition Utilities**: Complete transition system with `duration`, `delay`, `ease`, and property control
22
- - ⏱️ **Keyframes**: Built-in keyframes with support for custom animations via `configure()`
23
- - 🎨 **Custom Animations**: Create your own animations through theme extension or plugin API
24
- - 📝 **Examples**: New comprehensive animation examples
25
-
26
- Now you can create smooth transitions and eye-catching animations like Tailwind CSS!
20
+ - **⚛️ React Integration**: Built-in React hooks and provider for seamless integration
21
+ - **🎬 Enhanced Animations**: Complete animation system with custom keyframes support
22
+ - **🔄 Improved Transitions**: Full transition utilities with duration, delay, and easing
23
+ - **🎨 Advanced Theming**: More flexible theme customization and plugin system
24
+ - **⚡ Performance Boost**: Better caching and optimized CSS generation
25
+ - **📱 Responsive Selector Syntax**: New intuitive `'md:.title': 'text-lg'` format
27
26
 
28
27
  ## ✨ What's New in v2.11.0
29
28
 
@@ -58,18 +57,233 @@ All changes are **backward compatible** - your existing code continues to work!
58
57
 
59
58
  ## Installation
60
59
 
61
- To use `tailwind-to-style`, install the library using either npm or yarn:
62
-
63
- ### Using npm
64
-
65
60
  ```bash
66
61
  npm install tailwind-to-style
67
62
  ```
68
63
 
69
- ### Using yarn
64
+ ## React Integration
70
65
 
71
- ```bash
72
- yarn add tailwind-to-style
66
+ ### Quick Start with React
67
+
68
+ ```javascript
69
+ import { useTwsx, TwsxProvider } from 'tailwind-to-style'
70
+
71
+ // Theme configuration
72
+ const config = {
73
+ theme: {
74
+ extend: {
75
+ colors: {
76
+ brand: { 500: '#3b82f6', 600: '#2563eb' }
77
+ }
78
+ }
79
+ }
80
+ }
81
+
82
+ function App() {
83
+ return (
84
+ <TwsxProvider config={config}>
85
+ <MyComponent />
86
+ </TwsxProvider>
87
+ )
88
+ }
89
+
90
+ function MyComponent() {
91
+ // Auto-inject CSS into document head
92
+ useTwsx({
93
+ '.card': [
94
+ 'bg-brand-500 text-white p-6 rounded-lg',
95
+ {
96
+ '&:hover': 'bg-brand-600 transform scale-105',
97
+ '.title': 'text-xl font-bold mb-2'
98
+ }
99
+ ]
100
+ })
101
+
102
+ return (
103
+ <div className="card">
104
+ <h2 className="title">Interactive Card</h2>
105
+ <p>Hover me to see the effect!</p>
106
+ </div>
107
+ )
108
+ }
109
+ ```
110
+
111
+ ### Import Options
112
+
113
+ ```javascript
114
+ // Import from main package (recommended)
115
+ import { useTwsx, TwsxProvider } from 'tailwind-to-style'
116
+
117
+ // Or from React subpath
118
+ import { useTwsx, TwsxProvider } from 'tailwind-to-style/react'
119
+ ```
120
+
121
+ ### `useTwsx()` Hook
122
+
123
+ The main React hook for component styling:
124
+
125
+ ```javascript
126
+ import { useTwsx } from 'tailwind-to-style'
127
+
128
+ function MyComponent() {
129
+ // Auto-inject CSS (default behavior)
130
+ useTwsx({
131
+ '.button': [
132
+ 'bg-blue-500 text-white px-6 py-3 rounded-lg font-medium',
133
+ {
134
+ '&:hover': 'bg-blue-600 transform scale-105',
135
+ '&:active': 'bg-blue-700 scale-95',
136
+ '&:disabled': 'bg-gray-400 cursor-not-allowed'
137
+ }
138
+ ]
139
+ })
140
+
141
+ // Get CSS without injection
142
+ const css = useTwsx({
143
+ '.card': 'bg-white p-6 rounded-lg shadow-md'
144
+ }, { inject: false })
145
+
146
+ return (
147
+ <>
148
+ <style>{css}</style>
149
+ <div className="card">
150
+ <button className="button">Click me</button>
151
+ </div>
152
+ </>
153
+ )
154
+ }
155
+ ```
156
+
157
+ ### `TwsxProvider` - Theme Configuration
158
+
159
+ Provide global theme configuration and custom colors:
160
+
161
+ ```javascript
162
+ import { TwsxProvider, useTwsx } from 'tailwind-to-style'
163
+
164
+ const themeConfig = {
165
+ theme: {
166
+ extend: {
167
+ colors: {
168
+ brand: {
169
+ 50: '#eff6ff',
170
+ 500: '#3b82f6',
171
+ 600: '#2563eb',
172
+ 900: '#1e3a8a'
173
+ },
174
+ accent: '#f59e0b'
175
+ },
176
+ spacing: {
177
+ '128': '32rem',
178
+ '144': '36rem'
179
+ }
180
+ }
181
+ }
182
+ }
183
+
184
+ function App() {
185
+ return (
186
+ <TwsxProvider config={themeConfig}>
187
+ <Header />
188
+ <Main />
189
+ <Footer />
190
+ </TwsxProvider>
191
+ )
192
+ }
193
+
194
+ function Header() {
195
+ useTwsx({
196
+ '.header': [
197
+ 'bg-brand-500 text-white p-128', // Uses custom spacing
198
+ {
199
+ '.logo': 'text-accent font-bold text-2xl', // Uses custom color
200
+ '&:hover': 'bg-brand-600'
201
+ }
202
+ ]
203
+ })
204
+
205
+ return (
206
+ <header className="header">
207
+ <div className="logo">My Brand</div>
208
+ </header>
209
+ )
210
+ }
211
+ ```
212
+
213
+ ### Dynamic Styling with State
214
+
215
+ Create dynamic styles that respond to component state:
216
+
217
+ ```javascript
218
+ import { useTwsx } from 'tailwind-to-style'
219
+ import { useState } from 'react'
220
+
221
+ function ThemeToggle() {
222
+ const [theme, setTheme] = useState('light')
223
+
224
+ useTwsx({
225
+ '.theme-container': [
226
+ `bg-${theme === 'dark' ? 'gray-900' : 'white'} p-6 rounded-lg transition-all duration-300`,
227
+ {
228
+ [`&.${theme}`]: theme === 'dark'
229
+ ? 'text-white border-gray-700'
230
+ : 'text-gray-900 border-gray-200',
231
+ '.theme-title': 'text-2xl font-bold mb-4',
232
+ '.theme-button': [
233
+ 'px-4 py-2 rounded-lg font-medium transition-colors',
234
+ theme === 'dark'
235
+ ? 'bg-yellow-500 text-gray-900 hover:bg-yellow-400'
236
+ : 'bg-gray-800 text-white hover:bg-gray-700'
237
+ ]
238
+ }
239
+ ]
240
+ })
241
+
242
+ return (
243
+ <div className={`theme-container ${theme}`}>
244
+ <h2 className="theme-title">🌓 Dynamic Theme</h2>
245
+ <button
246
+ className="theme-button"
247
+ onClick={() => setTheme(theme === 'light' ? 'dark' : 'light')}
248
+ >
249
+ Switch to {theme === 'light' ? 'Dark' : 'Light'} Mode
250
+ </button>
251
+ </div>
252
+ )
253
+ }
254
+ ```
255
+
256
+ ### Available React Hooks
257
+
258
+ ```javascript
259
+ import {
260
+ useTwsx, // Main hook for styling
261
+ TwsxProvider, // Context provider
262
+ useTwsxContext, // Access provider context
263
+ useTwsxConfig, // Get current config
264
+ useUpdateTwsxConfig // Update config
265
+ } from 'tailwind-to-style'
266
+
267
+ // Example usage
268
+ function ConfigAwareComponent() {
269
+ const { config, isConfigured } = useTwsxConfig()
270
+ const updateConfig = useUpdateTwsxConfig()
271
+
272
+ if (!isConfigured) {
273
+ return <div>Loading theme...</div>
274
+ }
275
+
276
+ return (
277
+ <div>
278
+ <p>Current theme: {config.theme?.extend?.colors?.brand ? 'Custom' : 'Default'}</p>
279
+ <button onClick={() => updateConfig({
280
+ theme: { extend: { colors: { brand: { 500: '#ef4444' } } } }
281
+ })}>
282
+ Change Brand Color
283
+ </button>
284
+ </div>
285
+ )
286
+ }
73
287
  ```
74
288
 
75
289
  ## Core Functions