-
Notifications
You must be signed in to change notification settings - Fork 554
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
Support a prefix for classes instead of just leaving them out #17
Comments
Interesting idea, I think there may be a cleaner way to achieve this though; something that preprocesses objects beforehand. If you've got |
That would match with what I meant. I really don't think that the main modules public interface should be adjusted but that an additional function could be available who maps to the I am not sure what would be the nicest function interface for this one though ... the one described initially would then just return a function which just maps over it's arguments and adds a prefixed version for each unprefixed key and then feeds the result into |
What about another type of prefixing that's not a falsey prefix. For example:
This would be an extremely useful use case for me in react-bootstrap. react-bootstrap/react-bootstrap#404 is one example. Note that I have applied a rather crude means to accomplish this here. |
That seems a nice use case too. Unconditional prefixing. We need more names :-). Maybe we could generalize this into a formatting option for the list and integrate with some formatting options available (maybe someone wants prefixing ... someone wants suffixing ...) |
@mtscout6 if the classnames would be available as a list rather than a string, wouldn't the prefixing be trivial by mapping over it? |
@rmoorman we used an Array in previous versions but string concatenation provided an incredible improvement to execution speed. I'm normally all for flexibility in my packages but this one has become the de facto replacement for React's classnames utility and as such I'm being very careful to preserve performance. Also, you're likely to see a considerable number of executions in your app, so it has to scale. @mtscout6 I get where you're coming from with classes in react-bootstrap. What if we added two methods, like this:
var classNames = require('classnames');
var prefix = require('classnames/prefix');
var c = { a: true, b: false };
classNames(prefix(c, 'pre-')); // "pre-a"
classNames(prefix.falsy(c, 'not-')); // "a not-b"
classNames(prefix(c, 'is-', 'not-')); // "is-a not-b" Sounds like this would meet all the requirements I've heard without impacting the performance of complexity of Thoughts? |
@JedWatson I can see where you are coming from wrt. execution performance. As far as flexibility is concerned, the proposed solution could indeed provide a lot of it (also for suffixing, general formatting). It looks like the var classNames = require('classnames');
var prefix = require('classnames/prefix');
var c = { a: true, b: false };
classNames(prefix("pre-"), c); // "pre-a"
classNames(prefix.falsy("not-"), c); // "a not-b"
classNames(prefix("is-", "not-"), c); // "is-a not-b" The prefix function (or formatter for that matter) then just needs to receive the current item of the Or maybe a little cleaner to implement, preserving the current public interface of var classNames = require('classnames');
var classNamesFormat = require('classnames/format');
var prefix = require('classnames/prefix');
var c = { a: true, b: false };
classNames(c); // "a"
classNamesFormat(prefix("pre-"), c); // "pre-a"
classNamesFormat(prefix.falsy("not-"), c); // "a not-b"
classNamesFormat(prefix("is-", "not-"), c); // "is-a not-b" edit: add example for not changing interface of the |
Perhaps it might be easier to make |
This is something that can be done by the user. |
Hello there,
I would like to suggest a small addition to the functionality of this library. It would be handy IMHO if there would be a way to add a prefix (such as "no-") instead of just leaving the class out of the generated class string.
so that next to this:
the something like the following would also be possible:
Best regards,
Rico Moorman
The text was updated successfully, but these errors were encountered: