Tailwind classes in OCaml
1type opacity = 2 | Alpha of int 3 | Fraction of int * int 4 5type variant = 6 | V50 | V100 | V200 | V300 | V400 | V500 7 | V600 | V700 | V800 | V900 | V950 8 9type base = 10 | Slate | Gray | Zinc | Neutral | Stone 11 | Red | Orange | Amber | Yellow | Lime | Green 12 | Emerald | Teal | Cyan | Sky | Blue | Indigo 13 | Violet | Purple | Fuchsia | Pink | Rose 14 | Black | White | Transparent | Current | Inherit 15 16type t = { 17 base: base; 18 variant: variant option; 19 opacity: opacity option; 20} 21 22let make base ?variant ?opacity () = { base; variant; opacity } 23 24let base_to_string = function 25 | Slate -> "slate" 26 | Gray -> "gray" 27 | Zinc -> "zinc" 28 | Neutral -> "neutral" 29 | Stone -> "stone" 30 | Red -> "red" 31 | Orange -> "orange" 32 | Amber -> "amber" 33 | Yellow -> "yellow" 34 | Lime -> "lime" 35 | Green -> "green" 36 | Emerald -> "emerald" 37 | Teal -> "teal" 38 | Cyan -> "cyan" 39 | Sky -> "sky" 40 | Blue -> "blue" 41 | Indigo -> "indigo" 42 | Violet -> "violet" 43 | Purple -> "purple" 44 | Fuchsia -> "fuchsia" 45 | Pink -> "pink" 46 | Rose -> "rose" 47 | Black -> "black" 48 | White -> "white" 49 | Transparent -> "transparent" 50 | Current -> "current" 51 | Inherit -> "inherit" 52 53let variant_to_string = function 54 | V50 -> "50" 55 | V100 -> "100" 56 | V200 -> "200" 57 | V300 -> "300" 58 | V400 -> "400" 59 | V500 -> "500" 60 | V600 -> "600" 61 | V700 -> "700" 62 | V800 -> "800" 63 | V900 -> "900" 64 | V950 -> "950" 65 66let opacity_to_string = function 67 | Alpha n -> string_of_int n 68 | Fraction (n, d) -> Printf.sprintf "%d/%d" n d 69 70let color_to_string prefix color = 71 let base_str = base_to_string color.base in 72 let color_part = match color.variant with 73 | None -> base_str 74 | Some v -> Printf.sprintf "%s-%s" base_str (variant_to_string v) 75 in 76 let class_name = match color.opacity with 77 | None -> Printf.sprintf "%s-%s" prefix color_part 78 | Some op -> Printf.sprintf "%s-%s/%s" prefix color_part (opacity_to_string op) 79 in 80 Css.make class_name 81 82let text t = color_to_string "text" t 83let bg t = color_to_string "bg" t 84let border t = color_to_string "border" t 85let ring t = color_to_string "ring" t 86let outline t = color_to_string "outline" t 87let fill t = color_to_string "fill" t 88let stroke t = color_to_string "stroke" t 89 90let black = make Black () 91let white = make White () 92let transparent = make Transparent () 93let current = make Current ()