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

> > `if([cond ? iftrue : iffalse ]+)`
> 
> I guess, it should have the `#` with the comma-semicolon thing we decided earlier? (`+` will be repeating it with space, `#` with commas, see [drafts.csswg.org/css-values-4/#component-multipliers](https://drafts.csswg.org/css-values-4/#component-multipliers))

No, because there are no commas. The separators are `?` and `:`.

> Overall, I like the `if(a ? b : c)` syntax, as the ternaries are common, and we can't use it without the wrapping `if()` due to the `:` being significant in CSS syntax.

Also because then we wouldn’t know where the condition ends. I suppose both could be addressed with parens, but once you’re adding parens you may as well add two more characters and make this a lot more understandable.

> That said, I wonder if we could do this similarly with `calc()`, where we could allow using the ternaries in some other contexts without using the wrapping `if()`? Like we can use calculations without `calc()` inside things like `clamp()` and `round()`, we could allow using ternaries inside `calc()` and anything similar.

I like the idea, but it’s not part of the MVP. Open a new issue, possibly once we settle the syntax and spec an initial version? But that is another reason to use `?` and `:` so thanks for bring it up.

> Re: empty value, I think we should allow just omitting the value with optional whitespace to follow how the `--foo:;` and `var(--foo,)` work now: so the `if(a?b:)` and `if(a?:b)` should work fine.

That makes sense iff the default value is _not_ the empty value. If it is, we should just be able to not include a `:` at all. 



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


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

Received on Tuesday, 18 June 2024 15:47:27 UTC