Fork me on GitHub
#biff
<
2023-01-30
>
Epidiah Ravachol20:01:14

Anyone here have experience using the class-tools extension for htmx? https://htmx.org/extensions/class-tools/ On paper, it looks like a great and simple fit with Tailwind classes, but I've encountered a few twists in my explorations, and I wouldn't mind comparing notes.

👀 2
Epidiah Ravachol20:01:17

Here are the 2 rough edges I stumbled upon, which I think I have solutions for, but I'm not convinced they're the best solutions. Let's say I want to make a <div> that blushes when its first added to the DOM. It changes its background color briefly, to draw the eye. It seems I could do that with something like this: [:div {:class "ease-in-out transition-colors duration-1000" :classes "add bg-rose-400, remove bg-rose-400:2s"} "I'm new here!"] The first peril is this: https://github.com/bigskysoftware/htmx/issues/917 Currently, it doesn't look like class-tools handles a series of operations all that well. Fortunately the source code for class-tools is small and straight-forward enough that even with my meager JS skills I was able to implement the changes suggested in the issue with a local copy. I essentially replaced a bunch of vars with lets and pulled all the setTimeouts out into their own functions and it all seems to work. The second issue, I suspect, has to do with how Tailwind searches the code for the presence of Tailwind classes. If I'm not using bg-rose-400 anywhere else in my code, it won't appear in the stylesheet that Tailwind prepares. class-tools needs things to be written exactly this way "add bg-rose-400, remove bg-rose-400:2s" where that , immediately follows the first bg-rose-400 and the :2s immediately follows the second. No spaces. And I'm wondering if that's throwing Tailwind off the scent.

Epidiah Ravachol21:01:02

:thinking_face: Might explore a hyperscript solution to this instead.

Jacob O'Bryant02:01:49

Sounds like @1cg would be down for a pull request if you wanted to submit the changes you already implemented! https://github.com/bigskysoftware/htmx/issues/917#issuecomment-1139131300

🤯 2
Epidiah Ravachol14:01:39

I've never done a pull request before! A new adventure! Time to read up on how that works. I was thinking about using Tailwind's safelist feature. Especially since it's a color property and I'm already considering adding a bunch of those to the safelist to allow for user customization. Inspired by the advice to use a map given https://tailwindcss.com/docs/content-configuration#dynamic-class-names, I've also been considering writing some Clojure that collects all the classes I want along with how I want them added, removed, or toggled, and then writes the class-tools runs for me.