1 points · by encodeincode · 2y ago · 2 comments
Writing conditional styles can also be a hassle.
That’s why I created this lightweight and simple library.
It makes your TailwindCSS code cleaner and easier to manage.
Try it out, and feel free to share your feedback anytime!
const styles = tw({
base: "p-4 rounded-lg shadow-md",
dark: { if: isDarkMode, classes: "bg-gray-800 text-white" },
light: { if: !isDarkMode, classes: "bg-white text-black" },
});
can be written as const styles = classNames("p-4 rounded-lg shadow-md", {
"bg-gray-800 text-white": isDarkMode,
"bg-white text-black": !isDarkMode,
});
which requires less boilerplate and arguably looks a bit cleaner.