Skip to content

Instantly share code, notes, and snippets.

@ajchemist
Forked from currentoor/material-ui-wrapper.cljs
Last active August 29, 2015 14:27
Show Gist options
  • Save ajchemist/01c8d811a8534146dbaf to your computer and use it in GitHub Desktop.
Save ajchemist/01c8d811a8534146dbaf to your computer and use it in GitHub Desktop.
(defn ->kebab [s]
(str/join "-" (map str/lower-case (re-seq #"\w[a-z]+" s))))
(def components '[Card AppBar LeftNav CardTitle])
(defn gen-wrapper [component]
`(defmacro ~(symbol (->kebab (str component))) [& args#]
(let [[opts# & [children#]] (if (-> args# first map?)
[(first args#) (rest args#)]
[nil args#])]
`(js/React.createElement
~(symbol "js" (str "window.MaterialUI." (name '~component)))
(cljs.core/clj->js ~opts#)
~@children#))))
(defmacro gen-wrappers []
`(do
~@(clojure.core/map gen-wrapper components)))
(gen-wrappers)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment