-
Notifications
You must be signed in to change notification settings - Fork 690
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-properties-values-api] A compact syntax for registering global constants/custom properties #9206
Comments
Possibly related #7523 |
Yeah, I'd rather solve custom at-rules this way than adding
If this does exactly the same as
That should be doable as long as the new prelude doesn't start with |
Currently, the rules for property registration severely limit the initial value of any property with non-universal syntax – requiring them to be 'computationally independent'. For example, a property with I don't know the original purpose of that restriction, but it would be a potential blocker here. The goal would be for authors to use this in place of setting all custom properties on root. But many custom property use-cases rely on relative units and relationships between variables. If those things aren't allowed in the registration syntax, then authors will still be forced to define custom properties in two places. |
This issue is doing two separate things: mass registrations and making things "global". We should keep those topics separate; mass registration is already in #7523. (And I've just dropped a syntax suggestion over there that I quite like, modulo the rule name.) For "global" things, there are two possible behaviors you could be invoking:
Calling back to my env() comment, I think we can cleanly achieve 1 without even having to do anything by just letting For 2, this could just be a new descriptor in the registration block. Dunno what a good name is, tho. |
I'm not sure what you meant by this, @andruud. |
I was in fact invoking behavior 1, and mentioned I'm open to closing this as a duplicate of:
But the reason I opened this issue in the first place is to capture where they overlap in terms of author use-case and needs. Because they do. Currently For example, the limitation I mentioned above is a likely issue for both proposals. Initial values restricted in that way will not cover the use-case for global values, and will also not act as a replacement for defining custom properties on the root element. (I linked |
I think we probably already rely on initial values being in absolute/cononical-unit form, but assuming it's possible, it could be very bad for performance. In the worst case, it will be as if you specify all your "global" custom properties with
But maybe we can allow
That actually sounds very nice? And using
Yeah, I meant that if you can substitute arbitrary stuff into |
The current @custom-media --foo only screen and (min-width: 300px);
@media (prefers-color-scheme: dark) and (--foo) {} Can the same be achieved with CSS authors really like being able to write |
There's a few variable management issues getting attacked here! Love to see it 😍 from #9206 (comment)
from #9206 (comment)
what about @property {
syntax: "<length>";
inherits: false;
immutable: true;
initial-value: 2147483647px;
--width: initial; /* 2147483647px */
--height: initial; /* 2147483647px */
--depth: 0px;
} That covers:
Missed?
Seems like we still need |
But I think I prefer It can also make sense adding the other option described by Tab: static props accross the tree. I can imagine wanting to change some color props depending on a media query checking |
I agree with @tabatkins that mass registration and global variables are separate issues. It would be good to support a way of declaring global declarations that doesn't just center around custom properties, to address the needs for things like An important requirement for these globals is that they need to be able to express values that depend on other globals, otherwise their utility for things like design systems will be limited. For example, consider: --color-magenta-h: 335;
--color-magenta-s: 90%;
--color-magenta-l: 50%;
--color-magenta: hsl(var(--color-magenta-h) var(--color-magenta-s) var(--color-magenta-l));
--color-accent: var(--color-magenta);
--color-accent-lighter: hsl(from var(--color-accent) h s calc(l * 1.2));
/* etc etc */ (sure, wider adoption of CSS Color 5 will reduce the need to specify components separately, but the rest still applies...) Would the |
Yes, that's why I think the issues are related. From an authoring perspective, the way design tokens are often managed, I want that same ability to create related tokens in both local Design tokens in practice do not fall into neat 'global-and-independent' vs 'local-and-relational' categories. If we are providing both a way to make tokens globally available, and a way to define tokens in bulk, those two features are fundamentally part of a the same author use-cases. We can certainly implement them separately, but they have to play well together as part of a shared design-token-management work flow. |
@mirisuzanne so to make sure I understand: |
@LeaVerou Yes, that's what I had in mind. |
I think that would be great, if it's implementable. |
To clarify this a bit more: I would have |
The handful of issues have gotten entirely mixed up and cross-talking, so I'll just link to my comment in #7523 about why it's still important to have immutability as a (perf-oriented) feature. |
As an author, I would really-really want almost everything proposed in this issue and the comments below. In 2020 I did propose to make some of the fields in Maybe this issue could lead to us having a better way to define both custom properties, and global immutable tokens in a much more convenient way. One thing I want to add/ask: does someone know of any benchmarks/research on how the inheritance of the custom properties impacts performance? What could be potential gains from a situation where we, let's say, convert a thousand of design-tokens from a |
Quick question. What about non global constants? |
There has been discussion in several issues recently about providing a
::document
selector, or@document
/@global
/@env
rule that would allow authors a quick way to register globally available constants (as custom properties or environment variables) - without a full@property
rule describing each individually. See, for example:@font-palette-values
#6931(Hopefully this issue is useful as a way of combining several discussions, and not just a duplicate)
Those first two issues have more specific concerns that could be (or have been) addressed in specific ways - but mention the possibility we might still want a more generic solution for registering global properties. Custom media queries (
@custom-media
) have similarly been solved as a specific case, but not yet implemented – and there's an open issue for adding@custom-container
. Those use-cases could also be solved by a well-defined global parameter registry.There are two primary overlapping concerns here:
@property
rule is a very bulky way to register them one-at-a-time.var()
would not be possible to resolve.I tend to agree with @tabatkins that:
I like the proposed solution of allowing global reference to the initial values of registered custom properties, but think we need to make that registration simpler for it to work. I don't know the right syntax for that, but if we're able to come up with something compact, it could also be useful for defining parameters in declarative custom functions and (someday, maybe) mixins.
The
@property
rule can register a custom propertyname
with three associated descriptors:syntax
: the CSS type/grammar(s) used to validate and interpolate values (often but not always a single type like "<color>
" or "<length>
"'inherits
: a boolean to set if the property inherits or not (this would not be needed in function/mixin parameters)initial-value
: the initial value of the propertyAuthors often skip this registration for most properties, and only define the
name
along with an un-registered not-technically-'initial' value on the root element. Then some authors add the@property
registration for specific properties - often to define asyntax
for the sake of interpolation, but occasionally to set inheritance or a more formal initial value.Things I would expect from a syntax:
syntax
The main complexity that I see with defining a compact syntax is that custom property values (including initial values) are very permissive. It will be difficult to combine
initial-value
with anything else on the right side of a standardproperty:value;
format – though it should be possible using either the!
delim-token, or wrapping()
/{}
/[]
of some kind. The other thought I had was to put some of the definition on the left side. Some rough ideas:The an all-in-one syntax is more appropriate for reuse in function parameter definitions, while the grouped syntax helps with defining a whole set of related variables in a single place.
On the other end, when calling custom properties, a
env()
orglobal()
function could give access to the initial registered value anywhere in the document, whilevar()
returns only the cascaded value. I prefer this to a context-dependent resolution ofvar()
, since it provides more clarity on what value to expect, and makes both available wherevar()
is already supported:This is far from a complete proposal, and mostly a request that we consider these use-cases together. Happy for thoughts, and willing to merge this into the
env()
conversation if it belongs there.The text was updated successfully, but these errors were encountered: