Skip to content

Instantly share code, notes, and snippets.

@jaen

jaen/kek.cljs Secret

Created February 5, 2016 22:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jaen/7123aa5f7e15dccbed28 to your computer and use it in GitHub Desktop.
Save jaen/7123aa5f7e15dccbed28 to your computer and use it in GitHub Desktop.
(defn dropdown [{:keys [value] :as options} choices]
(reagent/create-class
{:component-did-mount
(fn [component]
(let [dom-node (reagent/dom-node component)]
(.dropdown (js/$ dom-node) #js {:match "text"
:onChange (fn [new-value]
(reset! value new-value))})))
:component-did-update
(fn [component]
(let [dom-node (reagent/dom-node component)]
(.dropdown (js/$ dom-node) "set selected" @value)
(.dropdown (js/$ dom-node) "refresh")))
:reagent-render
(fn [{:keys [value] :as options} _]
(let [value @value]
[:div.ui.fluid.search.selection.dropdown
[:input {:type "hidden" :name "choice" :value value}]
[:i.dropdown.icon]
[:div.default.text "Select choice"]
[:div.menu
(doall (for [{:keys [value text]} choices]
(conj
^{:key (str "choice-" value)}
[:div.item {:data-value value}]
text)))]]))}))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment