In this post, we're going to build three components, each of which demonstrates how to follow different parts of the TAC CSS methodology. If you haven't read about the TAC CSS methodology you can still follow along, but to fully understand some of th...
Markdown supported · ⌘↵ to post
These are really great examples. I am a big fan of everything you've written about TAC, I am certainly inspired. I am incorporating this philosophy where possible on the things I work on. One potential issue I have come across is by not using classes you lose the flexibility to use different builtin elements for the main component wrapper. For example using an <article> for a card. I wonder if it makes sense to use custom attributes in more cases instead of a separate tag (like your ord button example -- as you can also apply it to a tags if someone wants a big call to action link). I've also been considering the discussion on registered custom attributes as an alternative to builtin extends with is="".
In the site-header example, would it instead make sense to do <x-siteheader role="header"> and then not need the inner <header>? What if someone wants to have a <x-card> but to show a blog excerpt where it may make sense to use <article>? I suppose you can nest it like article > x-card.
I am not sure what the right mix of custom tags, slots, attributes, classes, etc. is in some cases, when trying to build a library that may be used in ways I am not expecting. I don't want to confuse people either by having some components be tags, others as attributes or classes but I guess as long as it's clearly documented. Maybe I'm overthinking it, and if a <footer> or whatever is needed then it can just be nested. Or maybe I am still a bit too much in the mindset of how I used to build things with BEM haha
One other question: I notice in your modal dialog example you use
slot. Is there ever a situation where it makes sense to usepartinstead ofslot? Without a shadow DOM both of those won't do anything functionally but can be used for style selectors. I feel thatslotmakes sense for a lot of cases where you want to treat the inner content as optional or something that an author wants to place as a child of your custom element, butpartmakes sense if you have a nested element that is a "required" child element that isn't really considered as content being placed in the component.I guess the downside is that styling would be confusing as you would do
[part="something"]instead of::part(something)like you would do with a real shadow DOM. I wonder if shadow DOM will be more widespread now that it can be declarative, albeit without shared templates yet.