mirror of https://github.com/status-im/reagent.git
Merge pull request #154 from zoldar/master
Added support for collections in :class property
This commit is contained in:
commit
b86adddec9
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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})
|
||||
|
|
Loading…
Reference in New Issue