Tailwind classes in OCaml
1type pseudo = Hover | Focus | Focus_within | Focus_visible | Active | Visited | Target
2 | Disabled | Enabled | Checked | Indeterminate | Default | Required | Valid | Invalid
3 | In_range | Out_of_range | Placeholder_shown | Autofill | Read_only
4
5type pseudo_element = Before | After | First_line | First_letter | Marker | Selection | File | Backdrop | Placeholder
6
7type structural = First | Last | Only | Odd | Even | First_of_type | Last_of_type | Only_of_type | Empty | Root | Nth of int | Nth_last of int
8
9type group = Group of pseudo | Peer of pseudo
10
11type special = Not of pseudo | Has of string | Where of string | Is of string | Starting_style | Inert | Open | In of string
12
13type t =
14 | Pseudo of pseudo * Css.t
15 | Pseudo_element of pseudo_element * Css.t
16 | Structural of structural * Css.t
17 | Group of group * Css.t
18 | Special of special * Css.t
19
20let pseudo_to_string = function
21 | Hover -> "hover"
22 | Focus -> "focus"
23 | Focus_within -> "focus-within"
24 | Focus_visible -> "focus-visible"
25 | Active -> "active"
26 | Visited -> "visited"
27 | Target -> "target"
28 | Disabled -> "disabled"
29 | Enabled -> "enabled"
30 | Checked -> "checked"
31 | Indeterminate -> "indeterminate"
32 | Default -> "default"
33 | Required -> "required"
34 | Valid -> "valid"
35 | Invalid -> "invalid"
36 | In_range -> "in-range"
37 | Out_of_range -> "out-of-range"
38 | Placeholder_shown -> "placeholder-shown"
39 | Autofill -> "autofill"
40 | Read_only -> "read-only"
41
42let to_class = function
43 | Pseudo (pseudo, classes) ->
44 let prefix = pseudo_to_string pseudo in
45 Css.make (prefix ^ ":" ^ Css.to_string classes)
46 | Pseudo_element (Before, classes) -> Css.make ("before:" ^ Css.to_string classes)
47 | Pseudo_element (After, classes) -> Css.make ("after:" ^ Css.to_string classes)
48 | Pseudo_element (First_line, classes) -> Css.make ("first-line:" ^ Css.to_string classes)
49 | Pseudo_element (First_letter, classes) -> Css.make ("first-letter:" ^ Css.to_string classes)
50 | Pseudo_element (Marker, classes) -> Css.make ("marker:" ^ Css.to_string classes)
51 | Pseudo_element (Selection, classes) -> Css.make ("selection:" ^ Css.to_string classes)
52 | Pseudo_element (File, classes) -> Css.make ("file:" ^ Css.to_string classes)
53 | Pseudo_element (Backdrop, classes) -> Css.make ("backdrop:" ^ Css.to_string classes)
54 | Pseudo_element (Placeholder, classes) -> Css.make ("placeholder:" ^ Css.to_string classes)
55 | Structural (First, classes) -> Css.make ("first:" ^ Css.to_string classes)
56 | Structural (Last, classes) -> Css.make ("last:" ^ Css.to_string classes)
57 | Structural (Only, classes) -> Css.make ("only:" ^ Css.to_string classes)
58 | Structural (Odd, classes) -> Css.make ("odd:" ^ Css.to_string classes)
59 | Structural (Even, classes) -> Css.make ("even:" ^ Css.to_string classes)
60 | Structural (First_of_type, classes) -> Css.make ("first-of-type:" ^ Css.to_string classes)
61 | Structural (Last_of_type, classes) -> Css.make ("last-of-type:" ^ Css.to_string classes)
62 | Structural (Only_of_type, classes) -> Css.make ("only-of-type:" ^ Css.to_string classes)
63 | Structural (Empty, classes) -> Css.make ("empty:" ^ Css.to_string classes)
64 | Structural (Root, classes) -> Css.make ("root:" ^ Css.to_string classes)
65 | Structural (Nth n, classes) -> Css.make (Printf.sprintf "nth-child(%d):" n ^ Css.to_string classes)
66 | Structural (Nth_last n, classes) -> Css.make (Printf.sprintf "nth-last-child(%d):" n ^ Css.to_string classes)
67 | Group (Group pseudo, classes) ->
68 let prefix = pseudo_to_string pseudo in
69 Css.make ("group-" ^ prefix ^ ":" ^ Css.to_string classes)
70 | Group (Peer pseudo, classes) ->
71 let prefix = pseudo_to_string pseudo in
72 Css.make ("peer-" ^ prefix ^ ":" ^ Css.to_string classes)
73 | Special (Not pseudo, classes) ->
74 let prefix = pseudo_to_string pseudo in
75 Css.make ("not-" ^ prefix ^ ":" ^ Css.to_string classes)
76 | Special (Has selector, classes) -> Css.make ("has-[" ^ selector ^ "]:" ^ Css.to_string classes)
77 | Special (Where selector, classes) -> Css.make ("where-[" ^ selector ^ "]:" ^ Css.to_string classes)
78 | Special (Is selector, classes) -> Css.make ("is-[" ^ selector ^ "]:" ^ Css.to_string classes)
79 | Special (Starting_style, classes) -> Css.make ("@starting-style:" ^ Css.to_string classes)
80 | Special (Inert, classes) -> Css.make ("inert:" ^ Css.to_string classes)
81 | Special (Open, classes) -> Css.make ("open:" ^ Css.to_string classes)
82 | Special (In variant, classes) -> Css.make ("in-" ^ variant ^ ":" ^ Css.to_string classes)
83
84let pseudo p classes = Pseudo (p, classes)
85let pseudo_element pe classes = Pseudo_element (pe, classes)
86let structural s classes = Structural (s, classes)
87let group g classes = Group (g, classes)
88let special s classes = Special (s, classes)
89
90let apply variant_t classes =
91 Css.combine (to_class variant_t) classes
92
93let hover classes = Css.make ("hover:" ^ Css.to_string classes)
94let focus classes = Css.make ("focus:" ^ Css.to_string classes)
95let active classes = Css.make ("active:" ^ Css.to_string classes)
96let disabled classes = Css.make ("disabled:" ^ Css.to_string classes)
97let first classes = Css.make ("first:" ^ Css.to_string classes)
98let last classes = Css.make ("last:" ^ Css.to_string classes)
99let odd classes = Css.make ("odd:" ^ Css.to_string classes)
100let even classes = Css.make ("even:" ^ Css.to_string classes)