Tailwind classes in OCaml
1type direction = 2 | All 3 | X 4 | Y 5 | Top 6 | Right 7 | Bottom 8 | Left 9 | Start 10 | End 11 12type t = { 13 property: string; 14 direction: string; 15 size: string; 16} 17 18let direction_to_string = function 19 | All -> "" 20 | X -> "x" 21 | Y -> "y" 22 | Top -> "t" 23 | Right -> "r" 24 | Bottom -> "b" 25 | Left -> "l" 26 | Start -> "s" 27 | End -> "e" 28 29let make_spacing property direction size = 30 let dir_str = direction_to_string direction in 31 let size_str = Size.to_string size in 32 { property; direction = dir_str; size = size_str } 33 34let padding direction size = make_spacing "p" direction size 35 36let margin direction size = make_spacing "m" direction size 37 38let gap gap_type size = 39 let property = match gap_type with 40 | `All -> "gap" 41 | `X -> "gap-x" 42 | `Y -> "gap-y" 43 in 44 let size_str = Size.to_string size in 45 { property; direction = ""; size = size_str } 46 47let space space_type size = 48 let property = match space_type with 49 | `X -> "space-x" 50 | `Y -> "space-y" 51 in 52 let size_str = Size.to_string size in 53 { property; direction = ""; size = size_str } 54 55let to_class t = 56 let class_name = 57 if t.direction = "" then Printf.sprintf "%s-%s" t.property t.size 58 else Printf.sprintf "%s%s-%s" t.property t.direction t.size 59 in 60 Css.make class_name 61 62(* Shorthand constructors *) 63let p size = padding All size 64let px size = padding X size 65let py size = padding Y size 66let pt size = padding Top size 67let pr size = padding Right size 68let pb size = padding Bottom size 69let pl size = padding Left size 70 71let m size = margin All size 72let mx size = margin X size 73let my size = margin Y size 74let mt size = margin Top size 75let mr size = margin Right size 76let mb size = margin Bottom size 77let ml size = margin Left size