weavejester / hiccup

Fast library for rendering HTML in Clojure
http://weavejester.github.io/hiccup
Eclipse Public License 1.0
2.68k stars 174 forks source link

Add possibility to set CSS classes using vector #132

Closed vincent-dm closed 7 years ago

vincent-dm commented 8 years ago

CSS classes are often conditional, based on some application logic.

Currently, it seems like you need to concatenate the :css string manually.

I tried passing a vector of CSS classes, but unfortunately they are concatenated using commas instead of spaces.

If this concatenation would happen with spaces, it would be an elegant way to assemble classes.

For example:

[div {:css ["label" (if selected "label-primary" "label-default")]} "Lorem ipsum"]
unitof commented 7 years ago

I would love this as well. I'm training myself on Clojure having come from JavaScript, which has the very handle element.classList, which returns element's current classes as a JS array. Then there are the related classList.add, classList.remove, and classList.toggle` methods, which are superduper for doing logic-based application of classes.

Something like those in Hiccup & Clojure vectors would be amazing.

zerg000000 commented 7 years ago

139 seems also added this feature.

weavejester commented 7 years ago

Fixed by #139.