mirror of
https://github.com/status-im/reagent.git
synced 2025-01-13 21:34:29 +00:00
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"]
|
[: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:
|
You can use one component inside another:
|
||||||
|
|
||||||
```clj
|
```clj
|
||||||
|
@ -91,12 +91,20 @@
|
|||||||
(str class " " old))))
|
(str class " " old))))
|
||||||
p)))
|
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]
|
(defn convert-props [props id-class]
|
||||||
(-> props
|
(-> props
|
||||||
|
stringify-class
|
||||||
convert-prop-value
|
convert-prop-value
|
||||||
(set-id-class id-class)))
|
(set-id-class id-class)))
|
||||||
|
|
||||||
|
|
||||||
;;; Specialization for input components
|
;;; Specialization for input components
|
||||||
|
|
||||||
;; This gets set from reagent.dom
|
;; This gets set from reagent.dom
|
||||||
|
@ -573,6 +573,16 @@
|
|||||||
(is (= (rstr [:div>p.bar.foo>a.foobar {:href "href"} "xy"])
|
(is (= (rstr [:div>p.bar.foo>a.foobar {:href "href"} "xy"])
|
||||||
(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
|
(deftest test-force-update
|
||||||
(let [v (atom {:v1 0
|
(let [v (atom {:v1 0
|
||||||
:v2 0})
|
:v2 0})
|
||||||
|
Loading…
x
Reference in New Issue
Block a user