Using the CSS `::part` Selector for Stateful Styling of Web Components
If you're a web component developer, you know that you can use the css ::part
pseudoelement to
give external developers permission to style, well, parts of your component. But did you know that
you can use ::part
to selectively style those parts based on the state of the component?
I'll show you how you can declare parts dynamically and serially, just as if they were child selectors, and use that dynamism to allow developers to style your component differently if it's disabled, or readonly, or "successful!" This example will use Lit, but it should work with raw web components or with any other library like Svelte, Ornament, or Minze.