Skip to content

Commit

Permalink
provide class-name prop also as class
Browse files Browse the repository at this point in the history
  • Loading branch information
lilactown committed Feb 26, 2019
1 parent 93c43b8 commit 4198ae2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
10 changes: 10 additions & 0 deletions examples/workshop/core.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -154,3 +154,13 @@
[PostCond {:age 19}]]
[ErrorBoundary
[PostCond {:age 42}]]]))

(hx/defnc ClassNameProp [{:keys [class class-name]}]
[:<>
[:ul
[:li "class: \"" class "\""]
[:li "class-name: \"" class-name "\""]]
(str (= class class-name))])

(dc/defcard class-name-prop
(hx/f [ClassNameProp {:class "foo"}]))
7 changes: 4 additions & 3 deletions src/hx/react.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
ret (gensym "return_value")]
;; maybe-ref for react/forwardRef support
`(defn ~name [props# maybe-ref#]
(let [~props-bindings (hx.react/props->clj props# maybe-ref#)]
(let [~props-bindings [(hx.react/props->clj props#) maybe-ref#]]
;; pre-conditions
~@(when (and opts-map? (:pre (first body)))
(map (fn [x] `(assert ~x)) (:pre (first body))))
Expand Down Expand Up @@ -78,9 +78,10 @@
args)))


#?(:cljs (defn props->clj [props maybe-ref]
#?(:cljs (defn props->clj [props]
(let [props (utils/shallow-js->clj props :keywordize-keys true)]
[props maybe-ref])))
;; provide `:class-name` property also as `:class`
(assoc props :class (:class-name props)))))

#?(:clj (defn $ [el & args]
nil)
Expand Down

0 comments on commit 4198ae2

Please sign in to comment.