-
Notifications
You must be signed in to change notification settings - Fork 669
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] Shorthand for custom property declaration #7523
Comments
Cool idea! I do agree that it can clutter up a file to declare many properties, and that some shorthand could be beneficial. Not sure about the syntax as it can look a little unclear (my first thought was "custom media query" but that's not the syntax), however I could see something like: @property --header-color: '<color>', blue;
@property --corner-radius: '<length-percentage>'; (where lengths have an implicit default of It stays compact while still being an explicit "hey I'm defining --prop" and uses the same syntax. (syntax would have to always be first in case you had a custom ident that looked like a syntax data type) Might even be able to follow the @property --header-color, --header-background-color, --header-border-color: '<color>'; |
For color format write, please write as this code. @chriskirknielsen @property --header-color: '<color>', blue;
@property --corner-radius: '<length-percentage>'; |
Somewhat related regarding multiple declarations: w3c/css-houdini-drafts#1058 I strongly agree with @chriskirknielsen that if such a shorthand is introduced, it still needs to be based on the Regarding the rest of the syntax, I think the colon isn't necessary. Though there's an issue with the comma used to separate the descriptors or multiple property declarations because that's already allowed in the initial value syntax. Generally speaking, any tokens that can be part of a Sebastian |
If the colon is a problem, perhaps a keyword like @property --foo, --bar as '<integer>'; You'd then still be able to have commas on either side to identify a list of property names vs values. I am however not familiar with parsing rules so maybe it just introduces another issue. Lea's proposal with the wildcard is also a nice way to do it if you follow a convention like |
And what prevents in styles from using the word PROPERY? @--foo: color;
@--bar: color; dovy dashes are written. The presence of double dashes will show that this is a property that will not be a problem in the future for media expressions --foo: brown;
--bar: brown; div.breadcrambs{
@--foo: color brown;
--bar: red;
} Very similar div.breadcrambs{
--foo: brown color ;
--bar: red color ;
--big: initial color ;
--ben: initial color ;
} |
@chriskirknielsen @SebastianZ @jonleighton @hober What do you think of syntax without dogs at all? div.breadcrambs{
--foo: brown color ;
--bar: red color ;
--big: initial color ;
--ben: initial color ;
} |
I am not privy to the parsing but it seems you want to declare scoped custom properties, per selector, and I am not sure that's possible with the Additionally, in your proposed form, the browser has no way to know the difference between a custom property value and custom property registration, since That is also a bit different from your initial proposal in some ways so I am not sure it's viable in its latest form, but still believe the one-line syntax |
@chriskirknielsen I did not know that such a syntax is acceptable. div.breadcrambs{
--foo: brown ;
--bar: red ;
} Help you create idea out how to insert typization into this format. |
+1
What about @property --min --max --avg number 0; |
I don't want to shove the existing descriptors into an unlabeled prelude space; that's hostile to future expansion, as we'd have to make sure the descriptor syntaxes either work together, or have an alternate form when in the prelude. However, generally the repetitive part comes from repeating the So, since custom properties are grammatically distinct from normal descriptors, we can do the defaults and the name/initial pairs together, like so:
Hm, this isn't even more verbose than the current |
Just brainstorming:
Maybe we can allow And/or allow the
Then we could say that the old form |
This syntax works well for grouping multiple property definitions that share features, but I think it's missing some attention to larger issues in how authors and browsers think about property registration and definitions. I would really like to see a more comprehensive plan for author-ergonomic 'design token' management. In my experience, authors currently use the Initial values are required to be 'computationally independent' when there is a defined In some ways, this is the distinction we also have between spec-defined 'initial' values, and browser-defined 'default' values – which are defined in distinct places, for distinct reasons. And for some author-origin use-cases that will make sense. A shared design system or framework can register properties with computationally independent 'initial' values, and the consuming stylesheets can apply selector-based 'default' values. But in many cases, authors have no reason to distinguish between the two. Most authors don't even know that the distinction exists in CSS. For the majority of design-token use-cases, authors will want initial and default values to match – and in many of those cases, variable-reference and responsive units are essential. I don't know if it's possible to remove the limitation from initial values? But if not, it would be nice to have a way of setting root/global default values in the same place where registration happens. I think this will also be essential for #2627, since authors will expect to have responsive units in global environment variables. (Root vs global selectors are used by authors as a shorthand for toggling inheritance without formal registration) |
How would |
@Loirooriol the behavior of From the author perspective at least, we don't need a universal answer outside the contexts where length values are allowed. But more to the point, and as Tab has mentioned elsewhere: authors won't always want to distinguish in advance between global-only constants and element-only variables. Ideally, we'd want to define a name and initial value (available globally or locally), and then also have the option to override that value on specific elements in the cascade. The distinction could instead be made in how we access those values: using e.g. |
I'll say it again since we're discussing the same thing in multiple issues: this idea is not compatible with the other goal (stated here or a related issue) of making "global" custom properties even more global for performance/memory reasons. In fact it makes it much worse. Currently, if the computed value of a custom property is the initial value, we can represent that (per-element) as not storing it on the element, and instead looking up the (per-document) initial value. With this new idea, we'd actually have to add the initial value(s) to the cascade for each element, duplicating the whole set of custom properties for each element (in the worst case). But "unfortunately" it makes a lot of sense from an author perspective, and together with the |
Quick aside about the "computationally independent" - the reason for that restriction is to avoid authors having to think about what lengths like And yeah, I think being able to address the "performance" issue is pretty important, so we do need a way to declare that a custom property will not be changeable per-element, so we can avoid tracking the property in per-element data structures entirely. My objection was to forcing authors to switch their definition and referencing syntax based on whether it's global or not; ideally we can keep these close. So, proposal:
We'll need to carefully define cycle handling in global variables, of course. Assuming we want @Property registrations to be changeable based on MQs (for swapping colors based on color-scheme, for example), we'll need to add some dependency edges based on use in MQs you're nested in. I don't think this is very hard, but it's definitely new code to determine and track these dependencies. (Alternatively, we don't allow them to be nested, and instead rely on solving this in the property-value space; see recent discussions on |
Hm, we do expose the two types of |
@tabatkins "Global" you say, but what do you think about @mirisuzanne "real" ask here, which is that initial values of registered custom properties can exist in an unabsolutized (but typed) form? To be specific: @property --x {
syntax: "<length>";
inherits: false;
initial-value: 10em;
}
/* --x is a <length>, can interpolate as <length>, has a type in computedStyleMap(), etc. */
#div1 { font-size: 10px; } /* => gCS(div1)['--x'] => 100px */
#div2 { font-size: 20px; } /* => gCS(div2)['--x'] => 200px */ |
The problem is that ems (and similar) have rules for when they evaluate - you'll never see an em in a property you've inherited, in any property, custom or not. This ties into the similar request for a way to delay substitution of a So that's a separate issue. ^_^ |
FWIW |
The CSS language should be simple. And the syntax of the new properties and styles should be intuitive. A person should not memorize the syntax of a single property. This is a mockery of a person. Life is complicated enough as it is. |
Shorthand properties/syntaxes like the one proposed here are not simple and often add unnecessary complexity to the language. One clear case of this is the Shorthands may look simple, but the DX surrounding shorthand is not great. Some shorthands like @--variable name: <syntax> <initial-value> <inherits> <access-level> <global-scoping> <...>; |
You're right, but that doesn't mean it's a bad idea. It's a good idea. I just need to optimize my offer. @property --color {
syntax: '<color>';
initial-value: red;
inherits: false;
} we have 5 lines But the same thing can be written like this @--color: <syntax>;
--color: <initial-value>; We just define the value in the usual way. But we also know that redefining a variable deep down is inherited. Which does not break compatibility. |
@korenevskiy You're right. It's not a bad idea, and your new suggested approach is already much better in my opinion. If we assume that in most "simple" situations, the @--name: '<syntax>' inherits / initial-value; Using the slash delimiter here is valuable to distinguish between the /* not great ❌ */
@--active: '<boolean>' true false;
/* better ✅ */
@--active: '<boolean>' true / false;
/* is equivalent to: */
@property --active {
syntax: '<boolean>';
inherits: true;
initial-value: false;
} This also has the added benefit of allowing exclusion of the @--active: '<boolean>' / false;
/* is equivalent to: */
@property --active {
syntax: '<boolean>';
inherits: true;
initial-value: false;
} Removing the slash changes the meaning of the boolean value—in this case—to be the @--active: '<boolean>' false;
/* is equivalent to: */
@property --active {
syntax: '<boolean>';
inherits: false;
} |
I made a big mistake, CSS should not turn into a programming language. and also the properties themselves should mean what they say. I.e. I want to say that you can't write TRUE and FALSE to denote inheritance, you have to write the word inheritance and not inheritance. Perhaps this will allow you to mix values without a slash. There are a lot of such properties in other styles. for example, a border or font or background. @--color: 'color' inherit red; or @--color: 'color' red inherit; |
@--font: 'font-famaly' inherit 'Arial'; or @--font: 'font-famaly' 'Arial' inherit; And it is also desirable that you do not have to put quotation marks. @--color: color red unherit; |
I agree that avoiding a boolean value for Maybe we do introduce a different keyword for that though, like |
I just don't know English well, I write through a translator. But, I wanted to convey the meaning. Thanks for the clarification. But the keyword " |
@brandonmcconnell Thank you for your participation, we would not have improved the new typing format. |
Yes, I considered a non-hyphenated Weighing the readability of |
I agree that they will not arise. I also considered readability. Brevity won out in my head. I'm worried that it's very stressful to hit a hyphen with your finger while typing. Perhaps enterprising craftsmen will print like this: |
Or maybe you can see the first letters of |
A case-insensitive |
and what is more correct: |
do I need me to put our new ideas with you in the main description at the top of the PR? |
I'm not even sure what Not having proper separation between the initial value and other parameters seems like a huge mistake. |
Do you mean the slash? @--color: color inherit;
--color: red; |
Delimiters, as well as hyphens, create stress on the brain. We just remember the general syntax of all CSS properties, but then it turns out that some of them are written with a comma, some with a slash, some with a space. it is necessary to study each case separately, for those who do not print every day or those who remember but do not use, you have to look for reference books to remember the format of the string. |
@Loirooriol What are your thoughts then on an approach to Could you provide feedback on this message specifically?:
Maybe we just assume that if you use the shorthand, you are opting into |
I completely agree, the default value must be. I just thought that other than that we were discussing the meaning for explicit indication. I still don't understand why the value of the |
why do you write angle brackets around the color? My Option. @--my-color: color;
@--my-color: color blue;
@--my-color: color inherit;
@--my-color: color inherit blue; |
@korenevskiy I'm evaluating this from the point of view of the language, not just the parser. I will probably object against things that might seem to improve readability/writing if they don't mix well into the language. How do you represent that in CSSOM? What happens if @brandonmcconnell My thoughts are that, if we add some kind of shortcut to register custom properties, it should probably be along these lines: #7523 (comment) Using |
Well, writing without the default value will be bad, but then let's think about the errors. How the browser will behave when it reads an error variable without specifying the default color. This is an obvious mistake, but it was written by the developer. What should the browser do then? @Loirooriol I also rate in terms of readability and writing. but I may not know the concept of the language well. Moreover, I did not offer anything that violates readability and writing. |
I suggest the default color value is transparent. moreover, the short form of types should be short, maybe the master does not need inheritance, he needs to define the color in the configuration. If he wants, let him redefine the color values or not define them in variables. The font-family type will have the default value that the browser has for the font.otherwise, it turns out that the font is not loaded, and the base font of the browser does not match the one that is set by default for the font type. The browser also has its own default values for each type. Anyway. There are always default property values that have their own default values. |
Let's create an abbreviated form of writing properties and variables.
When there are variables in the amount of 1000 pieces, then this is a heavy code.
It was:
Will be:
It would be convenient to have an abbreviated spelling :
Example:
In the writing of 2 dashes they will show that this is a property.
Use default values for each type:
Short write propertis without default value:
The text was updated successfully, but these errors were encountered: