tailwind_rs_core/utilities/
interactivity.rs

1//! Interactivity utilities for Tailwind-RS
2//!
3//! This module provides utilities for handling interactive elements like hover, focus, and active states.
4
5use crate::css_generator::types::CssProperty;
6
7/// Parser for interactivity utilities
8#[derive(Debug, Clone)]
9pub struct InteractivityParser;
10
11impl Default for InteractivityParser {
12    fn default() -> Self {
13        Self::new()
14    }
15}
16
17impl InteractivityParser {
18    /// Create a new InteractivityParser
19    pub fn new() -> Self {
20        Self
21    }
22
23    /// Parse interactivity classes
24    pub fn parse_class(&self, class: &str) -> Option<Vec<CssProperty>> {
25        match class {
26            // Cursor utilities
27            "cursor-auto" => Some(vec![CssProperty {
28                name: "cursor".to_string(),
29                value: "auto".to_string(),
30                important: false,
31            }]),
32            "cursor-default" => Some(vec![CssProperty {
33                name: "cursor".to_string(),
34                value: "default".to_string(),
35                important: false,
36            }]),
37            "cursor-pointer" => Some(vec![CssProperty {
38                name: "cursor".to_string(),
39                value: "pointer".to_string(),
40                important: false,
41            }]),
42            "cursor-wait" => Some(vec![CssProperty {
43                name: "cursor".to_string(),
44                value: "wait".to_string(),
45                important: false,
46            }]),
47            "cursor-text" => Some(vec![CssProperty {
48                name: "cursor".to_string(),
49                value: "text".to_string(),
50                important: false,
51            }]),
52            "cursor-move" => Some(vec![CssProperty {
53                name: "cursor".to_string(),
54                value: "move".to_string(),
55                important: false,
56            }]),
57            "cursor-help" => Some(vec![CssProperty {
58                name: "cursor".to_string(),
59                value: "help".to_string(),
60                important: false,
61            }]),
62            "cursor-not-allowed" => Some(vec![CssProperty {
63                name: "cursor".to_string(),
64                value: "not-allowed".to_string(),
65                important: false,
66            }]),
67            "cursor-none" => Some(vec![CssProperty {
68                name: "cursor".to_string(),
69                value: "none".to_string(),
70                important: false,
71            }]),
72            "cursor-context-menu" => Some(vec![CssProperty {
73                name: "cursor".to_string(),
74                value: "context-menu".to_string(),
75                important: false,
76            }]),
77            "cursor-progress" => Some(vec![CssProperty {
78                name: "cursor".to_string(),
79                value: "progress".to_string(),
80                important: false,
81            }]),
82            "cursor-cell" => Some(vec![CssProperty {
83                name: "cursor".to_string(),
84                value: "cell".to_string(),
85                important: false,
86            }]),
87            "cursor-crosshair" => Some(vec![CssProperty {
88                name: "cursor".to_string(),
89                value: "crosshair".to_string(),
90                important: false,
91            }]),
92            "cursor-vertical-text" => Some(vec![CssProperty {
93                name: "cursor".to_string(),
94                value: "vertical-text".to_string(),
95                important: false,
96            }]),
97            "cursor-alias" => Some(vec![CssProperty {
98                name: "cursor".to_string(),
99                value: "alias".to_string(),
100                important: false,
101            }]),
102            "cursor-copy" => Some(vec![CssProperty {
103                name: "cursor".to_string(),
104                value: "copy".to_string(),
105                important: false,
106            }]),
107            "cursor-no-drop" => Some(vec![CssProperty {
108                name: "cursor".to_string(),
109                value: "no-drop".to_string(),
110                important: false,
111            }]),
112            "cursor-grab" => Some(vec![CssProperty {
113                name: "cursor".to_string(),
114                value: "grab".to_string(),
115                important: false,
116            }]),
117            "cursor-grabbing" => Some(vec![CssProperty {
118                name: "cursor".to_string(),
119                value: "grabbing".to_string(),
120                important: false,
121            }]),
122            "cursor-all-scroll" => Some(vec![CssProperty {
123                name: "cursor".to_string(),
124                value: "all-scroll".to_string(),
125                important: false,
126            }]),
127            "cursor-col-resize" => Some(vec![CssProperty {
128                name: "cursor".to_string(),
129                value: "col-resize".to_string(),
130                important: false,
131            }]),
132            "cursor-row-resize" => Some(vec![CssProperty {
133                name: "cursor".to_string(),
134                value: "row-resize".to_string(),
135                important: false,
136            }]),
137            "cursor-n-resize" => Some(vec![CssProperty {
138                name: "cursor".to_string(),
139                value: "n-resize".to_string(),
140                important: false,
141            }]),
142            "cursor-e-resize" => Some(vec![CssProperty {
143                name: "cursor".to_string(),
144                value: "e-resize".to_string(),
145                important: false,
146            }]),
147            "cursor-s-resize" => Some(vec![CssProperty {
148                name: "cursor".to_string(),
149                value: "s-resize".to_string(),
150                important: false,
151            }]),
152            "cursor-w-resize" => Some(vec![CssProperty {
153                name: "cursor".to_string(),
154                value: "w-resize".to_string(),
155                important: false,
156            }]),
157            "cursor-ne-resize" => Some(vec![CssProperty {
158                name: "cursor".to_string(),
159                value: "ne-resize".to_string(),
160                important: false,
161            }]),
162            "cursor-nw-resize" => Some(vec![CssProperty {
163                name: "cursor".to_string(),
164                value: "nw-resize".to_string(),
165                important: false,
166            }]),
167            "cursor-se-resize" => Some(vec![CssProperty {
168                name: "cursor".to_string(),
169                value: "se-resize".to_string(),
170                important: false,
171            }]),
172            "cursor-sw-resize" => Some(vec![CssProperty {
173                name: "cursor".to_string(),
174                value: "sw-resize".to_string(),
175                important: false,
176            }]),
177            "cursor-ew-resize" => Some(vec![CssProperty {
178                name: "cursor".to_string(),
179                value: "ew-resize".to_string(),
180                important: false,
181            }]),
182            "cursor-ns-resize" => Some(vec![CssProperty {
183                name: "cursor".to_string(),
184                value: "ns-resize".to_string(),
185                important: false,
186            }]),
187            "cursor-nesw-resize" => Some(vec![CssProperty {
188                name: "cursor".to_string(),
189                value: "nesw-resize".to_string(),
190                important: false,
191            }]),
192            "cursor-nwse-resize" => Some(vec![CssProperty {
193                name: "cursor".to_string(),
194                value: "nwse-resize".to_string(),
195                important: false,
196            }]),
197            "cursor-zoom-in" => Some(vec![CssProperty {
198                name: "cursor".to_string(),
199                value: "zoom-in".to_string(),
200                important: false,
201            }]),
202            "cursor-zoom-out" => Some(vec![CssProperty {
203                name: "cursor".to_string(),
204                value: "zoom-out".to_string(),
205                important: false,
206            }]),
207
208            // Resize utilities
209            "resize-none" => Some(vec![CssProperty {
210                name: "resize".to_string(),
211                value: "none".to_string(),
212                important: false,
213            }]),
214            "resize-y" => Some(vec![CssProperty {
215                name: "resize".to_string(),
216                value: "vertical".to_string(),
217                important: false,
218            }]),
219            "resize-x" => Some(vec![CssProperty {
220                name: "resize".to_string(),
221                value: "horizontal".to_string(),
222                important: false,
223            }]),
224            "resize" => Some(vec![CssProperty {
225                name: "resize".to_string(),
226                value: "both".to_string(),
227                important: false,
228            }]),
229
230            // User select utilities
231            "select-none" => Some(vec![CssProperty {
232                name: "user-select".to_string(),
233                value: "none".to_string(),
234                important: false,
235            }]),
236            "select-text" => Some(vec![CssProperty {
237                name: "user-select".to_string(),
238                value: "text".to_string(),
239                important: false,
240            }]),
241            "select-all" => Some(vec![CssProperty {
242                name: "user-select".to_string(),
243                value: "all".to_string(),
244                important: false,
245            }]),
246            "select-auto" => Some(vec![CssProperty {
247                name: "user-select".to_string(),
248                value: "auto".to_string(),
249                important: false,
250            }]),
251
252            // Scroll behavior utilities
253            "scroll-auto" => Some(vec![CssProperty {
254                name: "scroll-behavior".to_string(),
255                value: "auto".to_string(),
256                important: false,
257            }]),
258            "scroll-smooth" => Some(vec![CssProperty {
259                name: "scroll-behavior".to_string(),
260                value: "smooth".to_string(),
261                important: false,
262            }]),
263
264            // Touch action utilities
265            "touch-auto" => Some(vec![CssProperty {
266                name: "touch-action".to_string(),
267                value: "auto".to_string(),
268                important: false,
269            }]),
270            "touch-none" => Some(vec![CssProperty {
271                name: "touch-action".to_string(),
272                value: "none".to_string(),
273                important: false,
274            }]),
275            "touch-pan-x" => Some(vec![CssProperty {
276                name: "touch-action".to_string(),
277                value: "pan-x".to_string(),
278                important: false,
279            }]),
280            "touch-pan-left" => Some(vec![CssProperty {
281                name: "touch-action".to_string(),
282                value: "pan-left".to_string(),
283                important: false,
284            }]),
285            "touch-pan-right" => Some(vec![CssProperty {
286                name: "touch-action".to_string(),
287                value: "pan-right".to_string(),
288                important: false,
289            }]),
290            "touch-pan-y" => Some(vec![CssProperty {
291                name: "touch-action".to_string(),
292                value: "pan-y".to_string(),
293                important: false,
294            }]),
295            "touch-pan-up" => Some(vec![CssProperty {
296                name: "touch-action".to_string(),
297                value: "pan-up".to_string(),
298                important: false,
299            }]),
300            "touch-pan-down" => Some(vec![CssProperty {
301                name: "touch-action".to_string(),
302                value: "pan-down".to_string(),
303                important: false,
304            }]),
305            "touch-pinch-zoom" => Some(vec![CssProperty {
306                name: "touch-action".to_string(),
307                value: "pinch-zoom".to_string(),
308                important: false,
309            }]),
310            "touch-manipulation" => Some(vec![CssProperty {
311                name: "touch-action".to_string(),
312                value: "manipulation".to_string(),
313                important: false,
314            }]),
315
316            // Will change utilities
317            "will-change-auto" => Some(vec![CssProperty {
318                name: "will-change".to_string(),
319                value: "auto".to_string(),
320                important: false,
321            }]),
322            "will-change-scroll" => Some(vec![CssProperty {
323                name: "will-change".to_string(),
324                value: "scroll-position".to_string(),
325                important: false,
326            }]),
327            "will-change-contents" => Some(vec![CssProperty {
328                name: "will-change".to_string(),
329                value: "contents".to_string(),
330                important: false,
331            }]),
332            "will-change-transform" => Some(vec![CssProperty {
333                name: "will-change".to_string(),
334                value: "transform".to_string(),
335                important: false,
336            }]),
337
338            _ => None,
339        }
340    }
341}