Hey guys, I am trying to introduce the power of types to TailwindCSS, and so far this is what it looks like:
<button
className={tailwind(
~flex=makeFlex(~flexDirection=Flex.Column, ()),
~backgroundColor=Background.CongluGreen,
~dropShadow=Filters.DropShadowButton,
~height=Sizing.Height60,
~textColor=Text.White,
~width=Sizing.Width316,
~darkMode=true
(),
)}>
Benefits:
- We can have type checking on the tailwind classes
- Which means we can have class name validation
- Avoiding duplicate classes
- Contradictory classes (margin, and margin-top, for instance)
Cons that aim to eliminate:
- The generated code looks something like this, it clearly doesn’t have zero cost bindings:
TailwindCSS.tailwind(undefined, undefined, undefined, undefined, undefined,
undefined, /* CongluGreen */ 1, undefined, undefined, /* RoundedFull */ 0,
undefined, undefined, undefined, undefined, undefined,
/* DropShadowButton */ 0, undefined, undefined, undefined, undefined,
undefined, undefined, undefined, undefined, undefined, undefined,
undefined, undefined, undefined, undefined, undefined, undefined,
undefined, undefined, undefined, undefined, undefined, /* White */ 8,
undefined, undefined, undefined, /* Height60 */ 11, undefined,
/* Width316 */ 15, undefined, undefined)
- The way webpack Tailwind works, we have to include all the TW classes we are using into the payload (if we want to create a general purpose TW library), because the tailwind compiler does not understand which rescript classes we’re using.
The only solution I can think of to bypass these constraints is to write a PPX, but I want to figure out if there’s non-PPX way to reduce some of the pain points while keeping the benefits.
Any feedback is welcome