-
Notifications
You must be signed in to change notification settings - Fork 555
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
Dynamic fragments in a class name #45
Comments
Hi Pickled-plugins I'm looking for the exact same in a project, that i'm working on. So yes - there's interest in such a feature, at least from me :-) Other than that, i'm very pleased with classNames, so thanks to the author for a nice piece of work. |
Why not just classnames({
'help': true,
`help--${props.position}`: !!props.position
}) This would already work in ES6 AFAIK. |
Might be a possibility - however i'm currently using JSX with watch-compiler but not ES6. I'm still new to React, so maybe i'm trying to use the wrong tool for this operation, or maybe i just doesn't use it right. But if i try your suggestion, my JSX watch task gives me following error: Parse Error: Line xxx: Unexpected token { If i wrap the category slug ref in quotes, it obviously just treats my var ref as a string. |
@rbsmidt you can read up on template string and have |
Closing, this is easily solved by just using ES6. No point special casing this library just for this. |
@dcousens thank you for the tip. I did not know that interpolation worked for object keys, which makes your solution the best way to go. |
On a project I am currently working on, I encounter some situations where a class name is built up dynamically based some variable, for example:
'help help--' + props.position
, resulting inhelp help--left
,help help--top
,help help--right
. This library would make this code much more expressive if it supported a syntax such as the following:The character 0 inside the syntax notation would indicate that the 0th (first) element of the array should be used.
To improve performance, this behavior can be switched off by not setting the
interpolate
option to true (no interpolation by default).Is there an interest to have a feature like this in the library (if so, I am happy to implement it)? Any ideas for a better syntax?
The text was updated successfully, but these errors were encountered: