-
Notifications
You must be signed in to change notification settings - Fork 668
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[css-shadow-parts] Limited ::theme selector #3507
Comments
I think there's still a little missing from this. Imagine you had an outer component with 2 somewhat deep and complex inner components from different sources. This inner ones support themes but one uses We could support renaming themes in exportparts or we could support wild-card renaming in exportparts. |
@fergald The main thinking behind this is to have a way to compose multiple "child" components from a variety of sources into a single custom component but avoid the need to have deeply nested This thought was to avoid having a massive wrecking ball that could reach anywhere and make it more of a small strategic hammer. Wildcards would still require What are your thoughts on a potential solution for this? Would you please illustrate it with example markup? |
Edit- I see this is referenced in #3467! And the syntax there seems to be a better direction. I suppose my question is now, what is the status of ::theme? |
The spec became a spec for part only to narrow the focus and get one thing agreed and implemented. Theme is not off the table, it should come back at some point, probably as a separate spec. |
Speculation: Wouldn’t I often see authors put stylistic attributes on custom elements (such as Example/* inside shadow DOM */
:host {
--background: var(--button-background, ivory);
--color: var(--button-color, rebeccapurple);
--color-disabled: var(--button-color-disabled, thistle);
}
:theme(danger) {
--background: var(--button-bakground-danger, mistyrose);
--color: var(--button-color-danger, firebrick);
}
button {
background: var(--background);
border: 2px solid currentcolor;
color: var(--color);
padding: 0.5ex 1em;
}
button:disabled {
--background: var(--background-disabled);
--color: var(--color-disabled);
}
:theme(slim) button {
background: transparent;
border: none;
padding: 0;
text-decoration: underline;
}
:theme(strong) button {
background: var(--color);
border-color: var(--color);
color: white;
} Then a consumer can write: table my-button {
theme: slim;
}
.danger-zone my-button {
theme: danger;
}
dialog my-button[type="submit"] {
theme: strong primary;
} Why not
|
+1 to the idea of allowing support for wildcards inside |
@runarberg You raise an interesting suggestion. At Red Hat, we've approached this in our web component project using data attributes as a means of opting into "variants".
Perhaps what you describe could be a new idea under a different name such as |
Indeed what I’m suggesting is a little more powerful version of a mixin that is limited to the shadow root. But I feel like In my opinion what we now call |
@runarberg I can see the perspective that the label theme might be a misnomer. I do like the idea of |
The approach @runarberg proposes is pretty much the same thing as we at Vaadin tried early on (vaadin/vaadin-themable-mixin#12 (comment)) as a way to control theme variant propagation and as a way for style sheet authors to have control over them instead of the HTML markup. I would very much like that to be the case, that it would be possible to choose predefined variants using a style sheet. Unfortunately, our implementation ended up being terrible for performance and we moved back to the HTML attribute based solution. This also reminds me of the idea @justinfagnani surfaced in another related discussion about theming shadow roots (WICG/webcomponents#864 (comment)). I see it as basically the same idea, but with a slightly different API. The API proposed here feels like it would be easier to author. I don’t know if Justin had thoughts how the author defines the mapping between the “logical properties” and the final properties it is expanded into? Comparing the two, from a consumer perspective: mwc-card {
--material-elevation: 2;
} mwc-card {
theme: material-elevation-2;
} From the author perspective (shadow root of mwc-card): :host {
/* Not sure how --material-elevation would be processed? */
} :theme(material-elevation-2) {
box-shadow: var(--material-elevation-2-box-shadow);
} |
(Split from issue #3467, reported by @stefsullrew)
The current description of the ::theme selector is perhaps a bit too broad for real world usage. However the ability to access any ::part within the context of a component, without elaborate
exportparts=
chains would be much easier to work with in the context of a design system.In the example below, a theme context is defined for
**x-foo**
with the prefix of “foo-
”. This would grant access to all child parts that match the name within the declared theme's context. This scoping limits the reach of ::theme while avoiding the potentially complex exportparts= chains. Particularly when there's deep composition of components not owned by a single team.The text was updated successfully, but these errors were encountered: