Multiple defaults for CSS Custom Properties
See original GitHub issueConsider this case
class MyElement extends HTMLElement {
constructor() {
super().attachShadow({ mode: 'open' }).innerHTML = `
<style>
:host { color: var(--my-color, red); }
@media (prefers-color-scheme: dark) {
:host { color: var(--my-color, blue); }
}
</style>
`;
}
}
Should I get
"cssProperties": [
{
"name": "--my-color",
"default": "red"
}
]
Or
"cssProperties": [
{
"name": "--my-color",
"default": "blue"
}
]
And if I get either, that’s not really correct is it?
We should add a schema facility for declaring multiple defaults and their conditions
Issue Analytics
- State:
- Created 2 years ago
- Comments:15 (5 by maintainers)
Top Results From Across the Web
Using CSS custom properties (variables) - MDN Web Docs
Custom property fallback values Using the var() function, you can define multiple fallback values when the given variable is not yet defined; ...
Read more >Custom properties with defaults: 3+1 strategies - Lea Verou
We want to support a --color custom property for creating color variations by setting multiple things internally:
Read more >A Complete Guide to Custom Properties | CSS-Tricks
Custom properties can make code easier to maintain because you can update one value and have it reflected in multiple places.
Read more >A Strategy Guide To CSS Custom Properties
CSS Custom Properties are by default locally scoped to the specific selectors we apply them to. So they are kinda like local variables....
Read more >CSS Custom Properties | 12 Days of Web
To define a custom property, use the name of your choice preceded by two dashes, for example: --my-property . Then you can use...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Something to consider: if
condition
orconditions
is meant to be machine-readable, then the values should be strictly identicali.e. a tool like storybook or
<api-viewer>
might check a css property’s contexts like so:Or, it might perform a regexp check that allows for whichever whitespace rules that condition’s language allows.
I see these as variations or contexts. They’re still defaults for the same CSS property but they are dependent upon certain conditions. What about defining these contexts in connection to the primary definition like this: