TL;DR: I rewrote Name My Color to use Web Components instead of React!
My anti-web framework kick continues; after using Web Components for the baseball triple crown tracker, I’ve been hoping to start rewriting older projects in a more Web-native way. (honestly, at least part of this is to avoid those annoying GitHub dependabot emails warning me about vulnerabilities in my dependencies!)
The project is fairly straightforward (just a few hundred lines of JS), but I didn’t think I could do this because of the color picker. then I remembered seeing there’s an <input type=”color”>, and it’s well supported!
Of course the flip side is that instead of using a React component that looks the same everywhere, you’re depending on how different browsers implement things, so you have to be OK with the fact that your design isn’t going to be pixel perfect. Firefox’s color picker is platform-specific (the Linux one seems especially basic), although a nicer HTML-based one is coming!
An annoyance was reimplementing the feature that to allow clicking on a color to show the hex color (in case you’re on mobile and can’t see the tooltip). The old version did this in a typical React-ish way, where the component has an expanded boolean in its state, and clicking on it toggles that and shows the color. It hit me that this was really just the same as <details> and <summary> elements, and then I wouldn’t have to track the state! Which was true, except I couldn’t find a way to hide the triangle that opens on Safari, as for some reason it doesn’t support the ::marker pseudo element. I tried some solutions that were supposed to work on Safari but I just couldn’t get it to work and eventually gave up and embraced the “not pixel perfect” lifestyle 🙂 Edit: I did figure this out a few days later!
As I’ve been trying to do with my personal projects, I didn’t use any LLMs in doing this…except for a few things. One was figuring out how to import ESM modules from a CDN (it’s weirder than you think!) because I did want to reuse some libraries for doing the color calculations instead of writing JS like this to convert RGB to CIELAB. Another was getting tests working – I sort of followed this guide, but didn’t really want to test any DOM stuff, so I made it a little simpler then got hopelessly lost and ended up with this spaghetti code. But look at the slick tests page!
Honestly I’m not totally sure why I wrote this originally – I think the basic idea was that you could take a picture of something and then get a name for a color? Although I guess this would require the EyeDropper API and also displaying a picture? But regardless it’s kinda fun to play with, and sometimes the kids will play with it for a few minutes, and that’s good enough for me!
And it is awfully satisfying to have a commit with net -28000 lines 🙂
