by Rodeoclash · 3y ago · 0 comments
We have a bunch of sites written in different frameworks (React, Rails + Hotwire, Phoenix + Liveview) that we'd like to have a shared set visual components between them. Think things like:
- Buttons - Text spacing - Layout cards - Headers
Pretty low level stuff, the most dynamic behaviour might be something like showing / hiding content in an FAQ.
Web Components seems like a reasonable fit to encapsulate the design elements and reuse them across all these different frameworks (probably coupled with Tailwind CSS on each site to enforce consistent colours + spacing).
IMHO you probably want to look at design tokens or other ways to centralize your visual styles--it's really more of a workflow problem and not just something to throw more javascript at with web components.
I think what gp wants is css!
This is false. Use <template> and <slot>. First-class progressive enhancement.
I'm truly skeptical there is much to be gleaned accessibility-wise from templates if JS is disabled. There's no way to know how and where the template was meant to be instantiated in the DOM and accessibility tree without JS.
Web components are superficially similar to React/Angular/Vue, but very different in practice. Different strengths. Different use cases. Different opportunities. Like the post says, the web components community has been terrible at articulating and marketing these differences.
Say you have a component that does something with titles (h1 etc.), then you would wrap the semantic element with a web component.
You do the same with buttons, text or input fields etc.
This way you 100% retain the semantic structure (before loading JS). And it’s possible to progressively enhance the DOM if that is a goal.