Merge pull request #154 from zoldar/master

Added support for collections in :class property
This commit is contained in:
Juho Teperi 2017-10-20 10:08:43 +03:00 committed by GitHub
commit b86adddec9
3 changed files with 25 additions and 1 deletions

View File

@ -70,6 +70,12 @@ can be written as:
[:div>p>b "Nested Element"]
```
The `:class` attribute can accept either a collection or a string.
```clj
[:div {:class ["a-class" (when active? "active") "b-class"]}]
```
You can use one component inside another:
```clj

View File

@ -91,12 +91,20 @@
(str class " " old))))
p)))
(defn stringify-class [{:keys [class] :as props}]
(if (coll? class)
(->> class
(filter identity)
(string/join " ")
(assoc props :class))
props))
(defn convert-props [props id-class]
(-> props
stringify-class
convert-prop-value
(set-id-class id-class)))
;;; Specialization for input components
;; This gets set from reagent.dom

View File

@ -573,6 +573,16 @@
(is (= (rstr [:div>p.bar.foo>a.foobar {:href "href"} "xy"])
(rstr [:div [:p.bar.foo [:a.foobar {:href "href"} "xy"]]]))))
(deftest test-class-from-collection
(is (= (rstr [:p {:class ["a" "b" "c" "d"]}])
(rstr [:p {:class "a b c d"}])))
(is (= (rstr [:p {:class ["a" nil "b" false "c" nil]}])
(rstr [:p {:class "a b c"}])))
(is (= (rstr [:p {:class '("a" "b" "c")}])
(rstr [:p {:class "a b c"}])))
(is (= (rstr [:p {:class #{"a" "b" "c"}}])
(rstr [:p {:class "a b c"}]))))
(deftest test-force-update
(let [v (atom {:v1 0
:v2 0})