Re: [csswg-drafts] [css-variables-2] Custom shorthands with `@property` (#7879)

> However, defining the syntax of the shorthand like this could be problematic as it can create disambiguation issues that are not present in the individual shorthands. E.g. consider property a with a syntax <length>{0,4} and property b with a syntax <length>{0,4}. 

Agreed.

The only way to make it not ambiguous is by not allowing multipliers in the syntax definitions. This creates a fixed number of values that can be declared. (ignoring multi-token values like `<ratio>` for now)

We trade in some flexibility and gain some composability.
Authors have control over how far they want to take it.

---------

> It is also quite a burden on authors to have to match CSS property syntax. What if they don't need the entire possible range of syntaxes? It is also an impossible feat: even if they matched it when they wrote the rule, what happens when the syntax changes?

Being able to reference properties might help, but this again opens up the door to ambiguous value lists when a shorthand property is referenced.

- `<'color'>` vs `<color>`
- `<'padding'>` vs '<length>'

Aside from that I think this is mostly fine.
If the syntax defined in the custom shorthand doesn't allow your preferred value, you can use the original property yourself.

Being able to pass individual values to the shorthand is also just another escape hatch.
It can even be stripped entirely from this proposal.
But I do think it enables some nice patterns.

--------

> I think instead we should have syntax that somehow destructures the shorthand value into constituent custom properties that we then feed into CSS properties in the definition, without the author having the burden of duplicating existing CSS property syntax.

That is actually exactly what this proposal does, minus that last bit.
Following what already exists for `@property` made the most sense to me.

This also has the benefit of making these fully self documenting allowing editors and other tools to provide auto complete, linting, hover text, ...

--------

The main feature I think is the `values` property.
It is the "public surface" of the "API".

I expect most users of a defined custom shorthand to just use one of the "preset" value lists.

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


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

Received on Friday, 14 October 2022 21:00:31 UTC