-
-
Notifications
You must be signed in to change notification settings - Fork 38
Description
Somewhat like the introduction of function helpers like TW.{backgroundColor,opacity,…}
, I'm wondering if it might make sense to apply a similar pattern to variants. This could address the limitation where one can only use tailwindcss-classnames with one modifier like T.backgroundColor('active:bg-red-500')
, where something with more modifiers like T.backgroundColor('active:hover:bg-red-500
)` would not typecheck.
Moreover, it might help reduce the amount of types overall. I'm not sure if this would improve TS performance but it seems like it might?
Example of API:
import { TW, M } from "tailwindcss-classnames";
const classname = classnames(
TW.backgroundColor(M("active", "hover", "active:hover:bg-red-500"))
);
However, it seems a bit unnecessarily to duplicate the active
and hover
in the final argument, so perhaps its worth considering that the M function could apply those for the end-user:
M("active", "hover", "bg-red-500")
would produce a string like active:hover:bg-red-500
Or perhaps a purely type-based approach:
const classname = classnames(
TW.backgroundColor<'active', 'hover'>("active:hover:bg-red-500")
);
Would love to hear your thoughts.