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

classnames-like dynamic css classes handling #305

Closed
YurySolovyov opened this issue Jul 2, 2017 · 8 comments
Closed

classnames-like dynamic css classes handling #305

YurySolovyov opened this issue Jul 2, 2017 · 8 comments

Comments

@YurySolovyov
Copy link

In react world, classnames is a standard library for handing dynamic css classes.
I didn't find the alternative solution, and I didn't want to use special object syntax to interop with classnames, so I've created class-names-cljs to perform this task.

I thought it might be cool to try to bring such functionality to reagent so people coming from react can use familiar tools, also it seems more robust than just using inline (str ...) + ifs.

@pesterhazy
Copy link
Contributor

I like this.

We could even add this to reagent proper so that this works:

[:div {:class ["foo" "bar" :baz]}]

If the class (or classNames?) prop is a seq?, we could use Yury's classnames function to generate a space-separated string.

@danielcompton
Copy link
Contributor

Relates to #154.

@YurySolovyov
Copy link
Author

And #138 I guess

@saevarb
Copy link

saevarb commented Jul 29, 2017

Something alone these lines or #154 would be really nice. II was also thinking it could be cool to be able to do something like:

[:div 
  {:class 
    {:some-class (is-thing?) 
     :other-class (is-another-thing?)}}]

which would then evaluate the boolean predicates and generate class="some-class other-class" in the case where both predicates return true, etc.

@Deraen
Copy link
Member

Deraen commented Oct 20, 2017

Reagent now supports collections of strings for :class: #154

@YurySolovyov
Copy link
Author

But still no maps support, right?

@Deraen
Copy link
Member

Deraen commented Oct 20, 2017

No.

I'm a bit conflicted about adding support for maps. Implementation wise it would be really simple thing. API wise it would add another way to do the same thing. How much benefit would this have? Is is enough to outweigh the additional complexity of API. Think about how would you explain this thing to a new Reagent user:

This property might be a string... or symbol, keyword, or collection of those... or map of keywords with values deciding if the key is used as classname....
When should I use which?
\o/

[:div.always
  {:class [:always2
           (if (is-thing?) :some-class)
           (if (is-another-thing?) :other-class)]}]

[:div.always
  {:class 
    {:always2
     :some-class (is-thing?) 
     :other-class (is-another-thing?)}}]

Using vector is 5 characters more per class (two parenthesis and if ). But using vector it is simpler to add classes which are used always, though that can of course also be done with element name shorthand. Hmmh...

@YurySolovyov
Copy link
Author

I agree. At the point where it is not

just using inline (str ...) + ifs.

I have no intention of pushing maps support anymore.
If I really want maps, I'll just use my package.

@Deraen Deraen closed this as completed May 4, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants