Skip to content

add semantic adaptation guide and demo for usage-aware-component-variations#803

Open
castastrophe wants to merge 5 commits into
mainfrom
usage-aware-component-variations-169
Open

add semantic adaptation guide and demo for usage-aware-component-variations#803
castastrophe wants to merge 5 commits into
mainfrom
usage-aware-component-variations-169

Conversation

@castastrophe

@castastrophe castastrophe commented May 13, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Refactored guide.md to focus on Semantic Component Adaptation, a more appropriate use case for style queries than size-based layout density.
  • Updated demo.html to demonstrate a CTA Card adapting its visual logic (button style, badge visibility) based on a inherited --priority flag.
  • Ensured the implementation uses logical properties (inset-block-start, min-block-size) and provides robust fallback strategies.
  • Verified that this use case is distinct from the density-focused design-token-reactivity.

Test plan

  • Manually reviewed the demo.html to ensure style queries correctly trigger variations on a Chromium-based browser (Limited Availability).
  • Verified that the guide.md correctly identifies when to use style queries vs. size queries via a new decision matrix.

@google-cla

This comment was marked as resolved.

@castastrophe
castastrophe force-pushed the usage-aware-component-variations-169 branch from cd593a0 to b93ce85 Compare May 13, 2026 17:51
@castastrophe
castastrophe marked this pull request as draft May 13, 2026 17:53
@castastrophe
castastrophe force-pushed the usage-aware-component-variations-169 branch 3 times, most recently from a1c9484 to 85b8616 Compare May 13, 2026 19:05
@castastrophe
castastrophe marked this pull request as ready for review May 13, 2026 19:06
@castastrophe
castastrophe force-pushed the usage-aware-component-variations-169 branch from 85b8616 to 8a065c6 Compare May 13, 2026 19:09

```css
/* Fallback for browsers without style query support */
@supports not (container-type: inline-size) {

@knowler knowler May 13, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if it would be better to layer on style queries as a progressive enhancement in the fallback since container-type: inline-size wouldn’t have complete overlap with style queries (i.e. it would go back much farther and would match situations that don’t support style queries). For example, these could be the defaults that the style queries then overrides. Could use :where(section.promo) + order of appearance to ensure the style query wins.

/* Default styles */
.button {}

/* Contextual styles (wide support) */
:where(section.promo) .button {
  background: var(--brand-accent);
  color: white;
}

/* Style query aided contextual styles (limited support) */
@container style(--priority: high) {
  .button {
    /* Automatic switch to Filled promotional style */
    background: var(--brand-accent);
    color: white;
    border: none;
  }
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 to what @knowler said. And sadly we don't have a container-type: style to query.

And if you want to apply CSS when style CQs are supported without querying any particular property, you can do something like this: https://codepen.io/leaverou/pen/qEqqZQq

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, +1. I have an update I'll push, would love your thoughts on it.

@jamesnw jamesnw left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few questions and tweaks, but it looks good!

Comment thread guides/css-layout/usage-aware-component-variations/guide.md
Comment thread guides/user-experience/usage-aware-component-variations/guide.md Outdated
Comment thread guides/user-experience/usage-aware-component-variations/guide.md Outdated
Comment thread guides/user-experience/usage-aware-component-variations/expectations.md Outdated
Comment thread guides/user-experience/usage-aware-component-variations/guide.md Outdated
Comment thread guides/user-experience/usage-aware-component-variations/guide.md Outdated
@LeaVerou

LeaVerou commented May 14, 2026

Copy link
Copy Markdown
Collaborator

Just a quick note that I have seen the review request and plan to take a proper look at this once I'm done with the dark mode rewrite.
Very excited about this use case!

@castastrophe
castastrophe force-pushed the usage-aware-component-variations-169 branch from 8a065c6 to f602dd2 Compare May 14, 2026 17:22

Use style queries (`@container style()`) to trigger component variations based on inherited semantic context flags rather than viewport or container dimensions. This replaces deep descendant selectors (e.g., `.sidebar .card`) and improves component encapsulation.

In the context of design system components, style queries become invaluable in allowing styles to respond to their containers without the need for style-specific APIs that need to be pushed down to every descendant.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand what you mean, but I think this is hard to understand without a lot of context. Perhaps an example would make it clearer?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll update with some more concrete examples. Let me know what you think.

@LeaVerou LeaVerou left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left some comments, but on a high level I think it's still unclear (to me at least!) what use cases are part of this and which ones are part of design-token-reactivity.

E.g. I'd expect that a --priority property would be a high-level property that affects multiple design tokens, and that elements it's applied on themselves need to adapt to it themselves (e.g. a button with --priority would need a different border, background, text color etc). But also I wouldn't expect --priority: promo and I have no idea whether that's higher or lower than --priority: high. Looking at the expectations, button variant also seems more design token-y.

The description does a good job at drawing a clear distinction between the two, so I think it just needs a different example that's closer to real-world usage and clearly distinct from design tokens. I can't think of one offhand, but will try to brainstorm a few examples as well.

A more practical caveat I have discovered when using style queries: there is no way to match the actual element the property was specified on, so if you want to apply any styling that shouldn't be inherited (e.g. add a shadow) in a style query, one way to do that without applying it to every element in that subtree is to register the custom property as non-inheritable. Then it will only match direct children and you can use descendant selectors inside it if needed. You can even set a regular property in that rule, so that you have an inherited and a non-inherited version to query. Happy to expand on this if it comes up, just dropping it here so that if you encounter it while working on these you know it has a solution.

@rviscomi

Copy link
Copy Markdown
Member

@castastrophe is this ready for another look?

@jamesnw jamesnw linked an issue May 19, 2026 that may be closed by this pull request
7 tasks
@castastrophe

Copy link
Copy Markdown
Contributor Author

@rviscomi Not ready yet - it needs Lea's updates applied as well.

@LeaVerou

Copy link
Copy Markdown
Collaborator

@rviscomi Not ready yet - it needs Lea's updates applied as well.

You mean updates to things mentioned in my review or updates by me? 👀 Fine either way, just asking to make sure it doesn't fall off my radar if it's the latter!

@castastrophe

Copy link
Copy Markdown
Contributor Author

@rviscomi Not ready yet - it needs Lea's updates applied as well.

You mean updates to things mentioned in my review or updates by me? 👀 Fine either way, just asking to make sure it doesn't fall off my radar if it's the latter!

Haha updates by me based on your already provided feedback. Cheers!

@castastrophe
castastrophe force-pushed the usage-aware-component-variations-169 branch from e2b408a to 89e857d Compare May 26, 2026 18:06
@castastrophe

Copy link
Copy Markdown
Contributor Author

@LeaVerou

A more practical caveat I have discovered when using style queries: there is no way to match the actual element the property was specified on, so if you want to apply any styling that shouldn't be inherited (e.g. add a shadow) in a style query, one way to do that without applying it to every element in that subtree is to register the custom property as non-inheritable. Then it will only match direct children and you can use descendant selectors inside it if needed. You can even set a regular property in that rule, so that you have an inherited and a non-inherited version to query. Happy to expand on this if it comes up, just dropping it here so that if you encounter it while working on these you know it has a solution.

I think this is a really great approach to a more advanced concern than the use-case is covering. If I put on my design systems cap, those style queries are equivalent to design language "promo", "priority", etc. and when components are in that context, designers want certain things applied. Spectrum was filled with concepts like this throughout the system and I tried to pull out just one small example for this documentation. I think we could honestly go into much more use-case detail if the use-case expected more of a black-box implementation where the developer doesn't necessarily know where these assets will be used.

tldr; I didn't want to bloat this with too much nuance or detail. I love the idea of digging into it in the future though.

@castastrophe
castastrophe force-pushed the usage-aware-component-variations-169 branch from e867e49 to 800b4e6 Compare May 31, 2026 18:54
@rviscomi

Copy link
Copy Markdown
Member

@castastrophe is this ready for re-review?

@castastrophe
castastrophe force-pushed the usage-aware-component-variations-169 branch from 800b4e6 to ba16442 Compare June 16, 2026 16:20
@castastrophe

Copy link
Copy Markdown
Contributor Author

@rviscomi Yes, this is updated and should now address all review feedback.

@castastrophe
castastrophe force-pushed the usage-aware-component-variations-169 branch from ba16442 to 10b510f Compare June 24, 2026 16:56

@LeaVerou LeaVerou left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Much better, see comments!

Comment thread guides/user-experience/usage-aware-component-variations/guide.md Outdated
Comment thread guides/user-experience/usage-aware-component-variations/guide.md Outdated
Comment thread guides/user-experience/usage-aware-component-variations/guide.md Outdated
Comment thread guides/user-experience/usage-aware-component-variations/guide.md Outdated
@castastrophe
castastrophe force-pushed the usage-aware-component-variations-169 branch from 10b510f to 88990e5 Compare June 26, 2026 15:09
@castastrophe
castastrophe requested a review from LeaVerou June 26, 2026 15:38
@castastrophe

Copy link
Copy Markdown
Contributor Author

@LeaVerou Updates applied, looking forward to your thoughts!

@LeaVerou LeaVerou left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I love what you did with the framing/routing sections! It kept the essence of what I suggested, but a lot tighter! 😍

Btw, custom states can sometimes serve as another way to decouple context. E.g. any component can set :state(featured) and other elements can react to it. Of course that's much more limited (it only works when the context is set on a WC, and there is no way to decouple the descendant), but I wonder if it may be worth mentioning in the fallback section. Not sure.

Anyhow, this LGTM! Great guide!

@castastrophe
castastrophe force-pushed the usage-aware-component-variations-169 branch from 9dde2ff to e88f1ad Compare June 29, 2026 17:07
@castastrophe

Copy link
Copy Markdown
Contributor Author

Btw, custom states can sometimes serve as another way to decouple context. E.g. any component can set :state(featured) and other elements can react to it. Of course that's much more limited (it only works when the context is set on a WC, and there is no way to decouple the descendant), but I wonder if it may be worth mentioning in the fallback section. Not sure.

Great point, custom states are a nice tool for reading context. I'm going to hold off for now though since, as a fallback, it doesn't broaden support (:state() and container style queries reached interop around the same time), and it only decouples the producer side — the reactor still needs a descendant selector (:host(:state(featured)) .badge). In addition, that it requires a web component is a bigger prerequisite than the rest of this guide assumes. I love it as a follow-up for the WC skill though and I know we were having discussions about that spec there too. Thanks for the thorough reviews on this one! 🙏

@castastrophe

Copy link
Copy Markdown
Contributor Author

@rviscomi @malchata This one looks to be approved and ready for review!

@jamesnw jamesnw left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@rviscomi rviscomi left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Heads up that this guide was moved under css-layout in #909

castastrophe and others added 5 commits July 15, 2026 11:03
Refactors the guide and demo to focus on semantic component variations
using style queries. Replaced size-dependent layout examples with a
contextual priority pattern (standard vs. promo) better suited for
@container style() logic.
Co-authored-by: James Stuckey Weber <james@oddbird.net>
@castastrophe
castastrophe force-pushed the usage-aware-component-variations-169 branch from e88f1ad to 71cb356 Compare July 15, 2026 15:03
@castastrophe

Copy link
Copy Markdown
Contributor Author

@rviscomi I've updated the location and rebased against the latest from main. Should be good to go now 💃

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Create guide and evals for the usage-aware-component-variations use case

6 participants