Skip to content

Instantly share code, notes, and snippets.

@borkdude
Created March 23, 2018 10:42
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 borkdude/8940696b87f22e40a4ccc402066fce68 to your computer and use it in GitHub Desktop.
Save borkdude/8940696b87f22e40a4ccc402066fce68 to your computer and use it in GitHub Desktop.
(defn dropdown*
[dropdown widget-id]
(let
[state (subscribe [::subs/dropdown-option widget-id])
option (or (:default-option dropdown)
(:id (first (:options dropdown))))]
(dispatch [::events/set-dropdown-option widget-id
option])
(debug "MOUNT" dropdown widget-id)
(fn [dropdown widget-id]
[:div.control-dropdowns
(doall
(let [{:keys [id options]} dropdown]
(debug "STATE" @state)
(do
^{:key (key->css id)}
[DropdownButton
{:id id
:bs-size "xs"
:title (:label (first (filter #(= (or @state
option)
(:id %)) options)))}
(map-indexed
(fn [idx opt]
^{:key opt}
[MenuItem
{:on-select #(dispatch [::events/set-dropdown-option
widget-id (:id opt)])
:event-key idx}
(:label opt)])
options)])))])))
(defn dropdown*
[dropdown widget-id]
(r/with-let
[state (subscribe [::subs/dropdown-option widget-id])
option (or (:default-option dropdown)
(:id (first (:options dropdown))))]
(dispatch [::events/set-dropdown-option widget-id
option])
(debug "MOUNT" dropdown widget-id)
[:div.control-dropdowns
(doall
(let [{:keys [id options]} dropdown]
(debug "STATE" @state)
(do
^{:key (key->css id)}
[DropdownButton
{:id id
:bs-size "xs"
:title (:label (first (filter #(= (or @state
option)
(:id %)) options)))}
(map-indexed
(fn [idx opt]
^{:key opt}
[MenuItem
{:on-select #(dispatch [::events/set-dropdown-option
widget-id (:id opt)])
:event-key idx}
(:label opt)])
options)])))]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment