madvas / cljs-react-material-ui

Clojurescript library for using material-ui.com
Eclipse Public License 1.0
205 stars 32 forks source link

Support for Rum? #8

Closed kennyjwilli closed 8 years ago

kennyjwilli commented 8 years ago

Mostly works in Rum.. Just one annoyance, you cannot pass hiccup to a mui component. It would be nice if you could. Example

;; not working
(ui/tabs
     (ui/tab {:label "One"} [:div "content"])
     (ui/tab {:label "Two"} [:div "content2"]))

;; working 
(rum/defc thing1
  []
  [:div "content1"])

(rum/defc thing2
  []
  [:div "content2"])

(ui/tabs
     (ui/tab {:label "One"} (thing1))
     (ui/tab {:label "Two"} (thing2)))
kennyjwilli commented 8 years ago

Here is a hack to make it work:

(defmacro elem
  [n & args]
  (let [n (name n)
        [opts children] (if (map? (first args))
                          [(first args) (rest args)]
                          [{} args])
        type (first children)
        s (symbol (str "cljs-react-material-ui.core/" n))]
    `(let [component# (cond
                        ~(nil? type) (~s ~opts)
                        ~(vector? type) (let [c# (rum/defc ~(gensym (name n)) [] ~(last children))]
                                          (~s ~opts (c#)))
                        ~(seq? type) (~s ~opts ~@children))]
       component#)))

(mui/elem :tabs
               (mui/elem :tab {:label "One"} [:div "content1"])
               (mui/elem :tab {:label "Two"} [:div "content2"]))
madvas commented 8 years ago

Thank you, I added Rum support, please see Readme