Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[css-properties-values-api] Providing a way for @property to be opinionated about its usage #1108

Open
JamesIves opened this issue Sep 5, 2023 · 0 comments

Comments

@JamesIves
Copy link

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 strictly for certain 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 despite there being overlap in the value type.

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

@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. In the following example I've added a valid-properties key that corresponds with the CSS properties the defined variable can be used in:

@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. If a @property is incorrectly used, it could fall back to whatever the default value is.

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

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

Enforcing specific properties may be somewhat too cumbersome, but some degree of grouping may be better similar to how Figma handles variable scoping, where you can selectively restrict how a variable is used across a design file.

Screenshot 2023-09-04 at 8 47 19 AM

Something like this, 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. This would make things much more adjacent to type-safety checks in TypeScript which would be awesome.

First time making a suggestion here. Please go easy on me, apologies if this has been talked about before. 😂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant