Re: [csswg-drafts] [css-values?] What is the MVP for inline conditionals on custom properties? (#10064)

The CSS Working Group just discussed `[css-values?] What is the MVP for inline conditionals on custom properties?`.

<details><summary>The full IRC log of that discussion</summary>
&lt;astearns> zakim, open queue<br>
&lt;Zakim> ok, astearns, the speaker queue is open<br>
&lt;fantasai> leaverou: Motivating use cases<br>
&lt;fantasai> leaverou: right now web components libraries introduce tons of presentational attributes<br>
&lt;fantasai> leaverou: because custom properties include parts of values<br>
&lt;fantasai> leaverou: you can transform numeric values using calc() but keywords not possible<br>
&lt;fantasai> leaverou: Canonical example is changing background-color based on a `--variant` property<br>
&lt;fantasai> leaverou: These are examples for why I started shoelace library now called WebAwesome<br>
&lt;fantasai> leaverou: [lists many examples of utility classes]<br>
&lt;fantasai> leaverou: Style queries get us a lot of the way there, but because they only work on descendants<br>
&lt;fantasai> leaverou: that doesn't let us get all the way there<br>
&lt;fantasai> leaverou: so these remain presentational attributes<br>
&lt;fantasai> leaverou: but needing to branch on a condition is very common in CSS<br>
&lt;fantasai> leaverou: several issues last few years about how can we do this<br>
&lt;fantasai> leaverou: either as a block conditional<br>
&lt;fantasai> leaverou: or inline<br>
&lt;fantasai> leaverou: there are some extremely hacky workarounds that authors use<br>
&lt;fantasai> leaverou: e.g. stting custom property to an empty token string so it gets a value or falls back. Very very hacky things<br>
&lt;fantasai> leaverou: Despite huge demand there's no progress<br>
&lt;fantasai> leaverou: I opened this issue to explore what is still useful, but still easy for implementers<br>
&lt;fantasai> leaverou: Anders said if we re-use the conditional from container queries, that let's you compare values<br>
&lt;fantasai> leaverou: and even media and supports queries<br>
&lt;fantasai> leaverou: re-use that part and then declaration values chosen based on conditional<br>
&lt;fantasai> leaverou: said it was pretty easy<br>
&lt;fantasai> leaverou: For many of these use cases, instead of having one or two values, you could have a series of subsequent conditionals<br>
&lt;fantasai> leaverou: that's nice to hvae<br>
&lt;fantasai> leaverou: but main thing is single test, can always nest<br>
&lt;fantasai> leaverou: ideally we want a block conditional that applies when matches<br>
&lt;fantasai> leaverou: but that seems to be hard, so let's do inline first<br>
&lt;fantasai> leaverou: because we need it anyway<br>
&lt;fantasai> leaverou: if it can be implemented quickly, would be an easy win<br>
&lt;TabAtkins> q+<br>
&lt;kizu> q+<br>
&lt;fantasai> TabAtkins: This sounds good.<br>
&lt;astearns> ack TabAtkins<br>
&lt;TabAtkins> https://github.com/w3c/csswg-drafts/issues/5009#issuecomment-626072319<br>
&lt;fantasai> TabAtkins: going back to previous thread, this comments lists out 3 variants of conditionals<br>
&lt;fantasai> TabAtkins: This is a variant of item 3<br>
&lt;fantasai> TabAtkins: one important part is these shouldn't be a boolean (true/false), it should be multi-valued so you can provide more than one test<br>
&lt;fantasai> TabAtkins: in simplest case that's true or false, just omit last test<br>
&lt;leaverou2> q+<br>
&lt;leaverou2> q++<br>
&lt;fantasai> TabAtkins: but I want to make sure you can sequence tests<br>
&lt;leaverou2> qq+<br>
&lt;leaverou2> q-<br>
&lt;fantasai> leaverou: it's the second grammar<br>
&lt;emilio> q- +<br>
&lt;fantasai> TabAtkins: sgtm<br>
&lt;astearns> ack fantasai<br>
&lt;astearns> ack leaverou<br>
&lt;TabAtkins> fantasai: I think that the IACVT behavior is not amazing<br>
&lt;TabAtkins> fantasai: so i dont' want us to have authors rely on it all the time bc there's no alt<br>
&lt;leaverou2> q+<br>
&lt;TabAtkins> fantasai: to the extent taht people want to switch on a custom prop, can't we do that with some sort of conditional...<br>
&lt;TabAtkins> fantasai: if you just switch basics based on conditionals you can avoid cycles easily that way<br>
&lt;fantasai> leaverou: Would be useful, but this is orthogonal<br>
&lt;TabAtkins> leaverou: a block conditional *would* be useful, but it's orthogonal<br>
&lt;TabAtkins> leaverou2: same as in JS<br>
&lt;TabAtkins> fantasai: not orthogonal from ux perspective. whether someone uses block or inline conditional is somewhat based on availability<br>
&lt;TabAtkins> fantasai: if you have both you'll use both, but if you have only one you'll shoehorn<br>
&lt;TabAtkins> fantasai: i think we should do both if we can<br>
&lt;fantasai> TabAtkins: isnt' the block version just style queries and media queries?<br>
&lt;fantasai> leaverou: Style queries only work on descendants<br>
&lt;TabAtkins> TabAtkins: getting a style query block *on the element* *requires* IACVT<br>
&lt;andruud> q+<br>
&lt;fantasai> fantasai: Shouldn't be a problem if you have standard properties set based on custom properties<br>
&lt;fantasai> TabAtkins: If you restrit it only to standard properties, that's substantially restrictive<br>
&lt;fantasai> TabAtkins: a lot of cases will want to set more variables<br>
&lt;miriam> q+<br>
&lt;fantasai> TabAtkins: Those will then need to use inline version, because that's a requirement of inline<br>
&lt;fantasai> s/because/which uses IACVT because/<br>
&lt;fantasai> TabAtkins: IACVT triggers if you write something wrong<br>
&lt;astearns> ack kizu<br>
&lt;fantasai> kizu: Wanted to show some worse things<br>
&lt;fantasai> kizu: In October 2016, I was using custom properties to switch between values using calculations<br>
&lt;fantasai> kizu: today you can use comparisons with calculations, if length is bigger or smaller use different value -- only for lengths<br>
&lt;fantasai> kizu: ?? made it possible to use values with custom properties<br>
&lt;fantasai> kizu: using type griding<br>
&lt;fantasai> kizu: a very long chain of fallbacks to registered custom property<br>
&lt;fantasai> kizu: and that let's you get any value back<br>
&lt;miriam> s/??/Jane Ori/<br>
&lt;kizu> https://github.com/w3c/csswg-drafts/issues/10064#issuecomment-2161742249<br>
&lt;fantasai> kizu: The code is very complicated<br>
&lt;fantasai> kizu: authors can now do this<br>
&lt;astearns> q?<br>
&lt;fantasai> kizu: recent article where using layers and [missed]<br>
&lt;fantasai> kizu: taking advantage of revert-layer<br>
&lt;fantasai> kizu: The need for this from authors is very high<br>
&lt;leaverou2> fantasai note that all the workarounds involve var(). So all workarounds ALREADY invoke IACVT. This is just about making the API and ergonomics infinitely nicer<br>
&lt;fantasai> kizu: Also wanted to mention, how could we use registered custom properties to avoid some issues with IACVT<br>
&lt;fantasai> kizu: For those we know what types they can accept, what they can return, might make it more simple<br>
&lt;astearns> ack leaverou2<br>
&lt;astearns> ack leaverou<br>
&lt;fantasai> leaverou2, Yeah. My point is I don't want authors to need to use this MORE because it'll be so much easier, simply because don't have a better alternative<br>
&lt;fantasai> fantasai: I don't think we should be trying to encourage authors to use a bad behavior, rather than trying to make something that works better with the cascade<br>
&lt;fantasai> fantasai: Like we should try to make it work the right way rather than settling for IACVT<br>
&lt;astearns> ack andruud<br>
&lt;fantasai> kizu: Using animations to do this is worse<br>
&lt;fantasai> andruud: For block version, if your conditional contains a registered custom property and you try to style the font size with em units, you'll get a cycle<br>
&lt;astearns> ack miriam<br>
&lt;fantasai> andruud: so we'll still run into cycle problems with block version<br>
&lt;fantasai> miriam: Do those cycles make th whole thing impossible, or do they just mean font-size is invalid and we do the condition<br>
&lt;leaverou2> ;?<br>
&lt;fantasai> andruud: for the block conditional?<br>
&lt;leaverou2> q?<br>
&lt;leaverou2> q+<br>
&lt;fantasai> andruud: I guess we could handle those cases 1 by 1<br>
&lt;fantasai> TabAtkins: dependencies will crop up over time, so hard to block ad-hoc<br>
&lt;astearns> ack leaverou<br>
&lt;fantasai> leaverou2: The block version will be inherently limited, because some values will only make sense on a single property<br>
&lt;fantasai> leaverou2: e.g. em/auto/normal<br>
&lt;fantasai> leaverou2: even if we have block version, still need inline version<br>
&lt;fantasai> leaverou2: Also you can assign conditions to a variable and then use that variable in a function, including media test<br>
&lt;fantasai> leaverou2: so handle breakpoints more easily<br>
&lt;fantasai> astearns: Lots of acknowledgement that this is important to work on<br>
&lt;fantasai> astearns: but also some concern about increasing the IACVT behavior on the web<br>
&lt;fantasai> TabAtkins: I don't believe we can solve anything in this space without IACVT<br>
&lt;fantasai> TabAtkins: so unless we can avoid cycles with some new idea, then we need to move forward with IACVT<br>
&lt;TabAtkins> fantasai: i don't object<br>
&lt;TabAtkins> fantasai: lea, can you outline the proposed syntax?<br>
&lt;leaverou2> border-radius: if(style(--button-shape: pill), infinity);<br>
&lt;ydaniv> Is this something that could later be speced to replace IACVT into a proper behavior?<br>
&lt;leaverou2> Longer example: background-color: if(<br>
&lt;leaverou2>  style(--variant: success), var(--color-success-60),<br>
&lt;leaverou2>  style(--variant: warning), var(--color-warning-60),<br>
&lt;leaverou2>  style(--variant: danger), var(--color-danger-60),<br>
&lt;leaverou2>  style(--variant: primary), var(--color-primary)<br>
&lt;leaverou2> );<br>
&lt;fantasai> fantasai: I think it would be better if the comma wasn't used both to separate conditional and value, as well as separate sets of conditionals<br>
&lt;TabAtkins> use a colon!<br>
&lt;florian> q+<br>
&lt;fantasai> leaverou2: seems reasonable. Could maybe use a slash<br>
&lt;bkardell_> +1 TabAtkins<br>
&lt;astearns> ack florian<br>
&lt;fantasai> leaverou2: could even use a ? and be more like JS<br>
&lt;lwarlow> q+<br>
&lt;TabAtkins> suggest we take that syntax question to the issue<br>
&lt;fantasai> florian: suggest using switch() for multiple cases, like JS<br>
&lt;fantasai> leaverou2: The conditionals here chain like else-if<br>
&lt;fantasai> leaverou2: but this expands to ranges, etc.<br>
&lt;TabAtkins> yeah, this is an if/elif/elif/else chain<br>
&lt;astearns> ack lwarlow<br>
&lt;fantasai> s/chain like else-if/chain like else-if, you have to provide the conditional each time/<br>
&lt;fantasai> lwarlow: agree with not using comma for both places<br>
&lt;fantasai> lwarlow: slash would read better<br>
&lt;leaverou2> Just noticed all examples above have no else value. This is another example: `border-radius: if(style(--button-shape: pill), infinity, .2em);`<br>
&lt;fantasai> PROPOSED: Add this to css-values-5<br>
&lt;lwarlow> +1<br>
&lt;fantasai> astearns: any objections?<br>
&lt;leaverou2> +1<br>
&lt;bkardell_> https://www.irccloud.com/pastebin/nrStwApc/<br>
&lt;fantasai> RESOVLED: Add if() to css-values-5<br>
</details>


-- 
GitHub Notification of comment by css-meeting-bot
Please view or discuss this issue at https://github.com/w3c/csswg-drafts/issues/10064#issuecomment-2165157958 using your GitHub account


-- 
Sent via github-notify-ml as configured in https://github.com/w3c/github-notify-ml-config

Received on Thursday, 13 June 2024 09:47:11 UTC