[csswg-drafts] [css-properties-values-api-1] Providing a way for @property to be opinionated about its usage (#9300)

JamesIves has just created a new issue for https://github.com/w3c/csswg-drafts:

== [css-properties-values-api-1] Providing a way for @property to be opinionated about its usage ==
https://drafts.css-houdini.org/css-properties-values-api-1/#custom-property-registration

I've been using the `@property` syntax over the last few weeks and to this point I've found it quite useful. I keep however finding myself wondering if it could be even more robust.

In a design system, it's common for specific properties to be used for specific purposes, for example, you might have a `--background-primary` value which is used specifically for backgrounds, likewise for things such as spacing, `--space-xl` could be intended for  `margin` or `padding` values, but it may not be intended to be used for font sizes.

Take the following example, this color can be universally used:

```css
@property --color-surface-primary {
  syntax: '<color>';
  inherits: false;
  initial-value: #ff0000;
}
```

Having a way to provide a list of valid use cases would make this much more self-documenting to the consumer while making things less error prone:

```css
@property --color-surface-primary {
  syntax: '<color>';
  inherits: false;
  initial-value: #ff0000;
  
  valid-properties: 'background-color'
}
```

If you wanted it valid for multiple use-cases, a list could be provided:

```css
@property --color-surface-primary {
  syntax: '<color>';
  inherits: false;
  initial-value: #ff0000;

  valid-properties: 'background-color, color'
}
```

With something like this it would allow design systems to be more opinionated about the usage of the properties they provide by enforcing that they are used in the intended ways.




Please view or discuss this issue at https://github.com/w3c/csswg-drafts/issues/9300 using your GitHub account


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

Received on Sunday, 3 September 2023 22:12:19 UTC