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

Normalize variant given to config #258

Closed
LeBenLeBen opened this issue Sep 6, 2022 · 0 comments · Fixed by #277
Closed

Normalize variant given to config #258

LeBenLeBen opened this issue Sep 6, 2022 · 0 comments · Fixed by #277
Labels
feature New feature to be implemented

Comments

@LeBenLeBen
Copy link
Collaborator

Currently the variant prop is provided to the config class property as is, without any transformation. It means it can be an array or a string or whatever the user want it to be. I’m not sure this flexibility provides any added value. I personally like the simplicity of strings, but when you want to combine variants, it forces to end up with “complicated” tests to apply classes conditionally.

I usually use String.prototype.includes to test if a variant is present, but it’s fragile:

  1. The variant might not exists, forcing to use a condition, the simplest being an optional chaining variant?.includes('something'), which I forget to add by default too often
  2. This will match any occurrence of something, not only purple but also rebeccapurple for example. A behavior that is undesired most of the time if you split multiple variants with a space like I do

I feel like we should normalize this prop to always be a string and make it behave similarly to how the native class works: split by spaces and provide an API to access every property in a simple way. A Proxy could be great solution to return false by default and true when a variant is present; avoiding the necessity for conditional checks while keeping the syntax very short.

@LeBenLeBen LeBenLeBen added the feature New feature to be implemented label Sep 6, 2022
LeBenLeBen added a commit that referenced this issue Nov 20, 2022
…fig class, close #258

BREAKING CHANGE: The `variant` prop of all components must be a string, array is not supported anymore. This same `variant` value is now splitted by spaces and transformed into an object of type `{ [variant]: boolean }` before being passed to the component config `class` method. See « Styling components » guide for updated usage.
LeBenLeBen added a commit that referenced this issue Nov 20, 2022
…fig class, close #258

BREAKING CHANGE: The `variant` prop of all components must be a string, array is not supported anymore. This same `variant` value is now splitted by spaces and transformed into an object of type `{ [variant]: boolean }` before being passed to the component config `class` method. See « Styling components » guide for updated usage.
LeBenLeBen added a commit that referenced this issue Nov 21, 2022
…fig class, close #258

BREAKING CHANGE: The `variant` prop of all components must be a string, array is not supported anymore. This same `variant` value is now splitted by spaces and transformed into an object of type `{ [variant]: boolean }` before being passed to the component config `class` method. See « Styling components » guide for updated usage.
LeBenLeBen added a commit that referenced this issue Nov 27, 2022
…fig class, close #258

BREAKING CHANGE: The `variant` prop value of all components is now normalized into an object of type `{ [variant]: boolean }` before being given to the component config `class` method. See « Styling components » guide for updated usage.
LeBenLeBen added a commit that referenced this issue Nov 27, 2022
…fig class, close #258

BREAKING CHANGE: The `variant` prop value of all components is now normalized into an object of type `{ [variant]: boolean }` before being given to the component config `class` method. See « Styling components » guide for updated usage.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature to be implemented
Projects
None yet
1 participant