-
Notifications
You must be signed in to change notification settings - Fork 27
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
Multiple defaults for CSS Custom Properties #80
Comments
Should we consider fallback values to be "default"? I would expect a default value to be something that is explicitly set: :host {
--my-color: red;
} That being said I suppose you could have the same problem here: :host {
--my-color: red;
color: var(--my-color);
}
@media (prefers-color-scheme: dark) {
:host {
--my-color: blue;
}
} One might argue that |
the spec language refers to those as it's an interesting point you make, but I'm more concerned here with the 'multiple' part than the 'default' part |
that will prevent users to providing So it's actually not a "valid" example I would say |
Oh interesting! I did not know it considered those defaults. Good to know 👍 .
Not sure how the spec defines this, but in practice my example does work and users can override the I can't think of a syntax that would elegantly express all of the possible defaults and what criteria makes each value become active. It might be useful to wait and see how developers are using CEM first before making a decision on this. Right now I think this feature would requires us to make assumptions about how developers are structuring their CSS, and I am not sure we have all the required information to make an informed decision on this. For additional context, Stencil does not list the default values for CSS Variables in its docs output: https://github.com/ionic-team/stencil/blob/45388e95edb46ef357eb9ae37cd32bbb5bc1ed23/src/declarations/stencil-public-docs.ts#L101-L105. |
The open-wc analyzer, for it's part, does accept a default value in |
I guess the thing that trips me up here is that I have always considered a "default" value to be a single value that is explicitly set (such as Ionic Framework applies themes based upon light vs. dark mode as well as platform mode ( I would be interested to see if others have successfully documented variables with multiple defaults. |
Edit: Included what it would look to take example code and include within the manifest. Hey there! Long time listener, first time caller. I do certainly see value in adding a "conditional" concept on certain marked up CSS variables. Something that could take in something to the effect of With the example:
If a processor wants to automatically infer based on the wrapped media query, they can do so. After processing, the manifest could then look like:
Risk here is bloat to the file afaik. But I can see some helpful documentation coming out around this feature. |
But what would it look like in the manifest? |
Updated my comment above to be a little more cohesive |
interesting - it behaves differently when using constructible stylesheets 🙈 e.g. with inline styles a selector on the main document like html {
--my-color: blue;
} still applies. When using using constructible stylesheets then it won't 🤔 |
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: "cssProperties": [{
"name": "--my-color",
"description": "Change the color of the button",
"default": "blue",
"contexts": [{
"description": "Dark mode button color",
"default": "red",
"condition": "@media (prefers-color-scheme: dark)"
}]
}] |
Something to consider: if i.e. a tool like storybook or propertyContext.condition === '@media(prefers-color-scheme: dark)' Or, it might perform a regexp check that allows for whichever whitespace rules that condition's language allows. |
@bennypowers Do you envision condition being an object with pre-defined types perhaps? Conditions can be component or browser-centric. Some possibilities:
|
tricky on the one hand we'd prefer to keep our own enum right? makes it easier for consumers My 'gut reaction' is to keep it open as a string condition and have tools fight it out. I think there's precedent for that in |
Another complication here is that @media (min-width: 2px) {
@media (min-width: 1px) {
@supports (--a: b) {
@supports (display: flex) {
body {
background: pink;
}
}
}
}
} If a custom property was defined at some inner level I have no idea how you'd represent it in the manifest or in an e.g. |
Consider this case
Should I get
Or
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
The text was updated successfully, but these errors were encountered: