Skip to content
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-cascade-6] reusable named scopes #10336

Open
mayank99 opened this issue May 15, 2024 · 3 comments
Open

[css-cascade-6] reusable named scopes #10336

mayank99 opened this issue May 15, 2024 · 3 comments

Comments

@mayank99
Copy link

mayank99 commented May 15, 2024

(This was originally posted in #9742 (comment) but moved to its own issue later.)

Proposal:

A scope statement, similar to a layer statement, could be used to create a reusable named scope. For example:

@scope foo (.start) to (.end);

A reusable named scope can then be used without specifying <scope-start>/<scope-end>:

@scope foo {
  p { color: red; }
}

The main thing this enables is avoiding the need to repeat selectors for every use.


Open questions:

  • how do we handle duplicate scope names?
  • how do we differentiate between named scopes and reusable named scopes? (different syntax?)
@romainmenke
Copy link
Member

For @media this same feature is currently specified as @custom-media : https://drafts.csswg.org/mediaqueries-5/#custom-mq

@custom-media --modern (color), (hover);

@media (--modern) and (width > 1024px) {
  .a { color: green; }
}

This separates declaring a scope and using a scope.

@mayank99
Copy link
Author

@romainmenke good point, I wonder if there should be a common primitive for "defining" things.

Example syntax (bikesheddable):

@define(scope) --foo (.start) to (.end);
@define(media) --modern (color), (hover);

@romainmenke
Copy link
Member

@custom-* can be the common primitive :)

A benefit of a dedicated at-rule is that things can be different without causing conflicts.

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

No branches or pull requests

2 participants