-
Notifications
You must be signed in to change notification settings - Fork 9
/
home.cljs
30 lines (26 loc) · 1.03 KB
/
home.cljs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
(ns cljs-spa.page.home
(:require ;; See https://github.com/pesterhazy/cljs-spa-example/issues/13
[react-select :refer [default] :rename {default react-select}]
[cljs-spa.state :refer [!state]]))
(def options
[{:value "simplicity", :label "simplicity"}
{:value "immutable data", :label "immutable data"}
{:value "lazy sequences", :label "lazy sequences"}])
(defn selector-ui []
[:> react-select
{:is-multi true,
:options (clj->js options),
:on-change (fn [xs]
(swap! !state assoc
:selection
(->> (js->clj xs :keywordize-keys true)
(map :label)
(into #{}))))}])
(defn result-ui []
[:div [:h3 "So you like"]
(let [selection (:selection @!state)]
(if (seq selection) [:div (pr-str selection)] "Nothing yet"))])
(defn page-ui []
[:div {:style {:max-width 400}} [:h3 "cljs-spa-example"]
[:div {:style {:margin-top 20, :margin-bottom 20}} "What do you like?"]
[selector-ui] [result-ui]])