Open LeaVerou opened 3 weeks ago
Committed a first pass at the generic <boolean>
grammar
Committed a first pass at the generic
<boolean>
grammar
Thanks! I think the ergonomics will become more clear once we edit specs to reference it too.
Btw if we call it <boolean>
that sort of implies we also have constants like true
and false
. If we don’t want that, perhaps <condition>
is more clear.
This came up when I went to implement the resolution from #10064 and spec my
if()
proposal.Currently, we have several specs using one or more types of conditionals, and in every case, this is defined inline. This means the boolean operators (
and
,or
,not
) are also defined inline, which is awkward, error-prone, and easy to forget.Some examples:
Media Queries 5:
@supports
:CSS Conditional 4 adds…:
[CSS Conditional 5 adds…](https://drafts.csswg.org/css-conditional/#at-supports-ext
@container
:@import
:Tab’s
@when
proposal:In fact, there is an inline issue right there proposing a lighter form of what I’m arguing for here:
Proposal
I propose we introduce a new
<boolean>
or<condition>
value type that other specs can reference. It will include both the grammar for the boolean algebra, as well as bare and functional forms for each conditional. Each conditional type should also include metadata like:Not all condition types need to be defined in values, we could extend the
<condition>
token in other specs, as we often do with value types. E.g. size queries may be a better fit in css-contain, since they are not valid anywhere else.The prose should explain that specs using
<condition>
should specify:To make this more concrete, this is the state of the current specs with conditionals with this framing:
supports()
media()
size()
style()
@container
@supports
@media
@import
if()
@if
/@when
While this change is editorial, I think it will pave the way for a lot of quick DX wins involving mixing and matching conditions (e.g.
supports()
in@media
.It could also allow creating JS APIs that handle conditions generically, avoiding the current issue of e.g. having
matchMedia()
for media queries, but no way to detect when a container query matches or not.