forked from reagent-project/reagent
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommon.cljs
More file actions
44 lines (42 loc) · 1.56 KB
/
common.cljs
File metadata and controls
44 lines (42 loc) · 1.56 KB
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
(ns reagentdemo.common
(:require [reagent.core :as r]
[reagent.debug :refer-macros [dbg println]]))
(defn demo-component [{:keys [expected comp src hint complete no-heading]}]
(r/with-let [showing-solution (r/atom false)
showing-hint (r/atom false)]
[:div
(when expected
[:div.demo-example.clearfix
(when-not no-heading
[:h3.demo-heading "Expected output "])
(if-not complete
[:div.simple-demo [expected]]
[expected])
(when comp
[:div
(when-not no-heading
[:h3.demo-heading "Actual output "])
(if-not complete
[:div.simple-demo [comp]]
[comp])])
(when hint
[:div
[:a.demo-example-hide {:on-click (fn [e]
(.preventDefault e)
(swap! showing-hint not)
nil)}
(if @showing-hint "hide" "show")]
[:h3.demo-heading "Hint"]
(when @showing-hint
hint)])])
(if src
[:div.demo-source.clearfix
[:a.demo-example-hide {:on-click (fn [e]
(.preventDefault e)
(swap! showing-solution not)
nil)}
(if @showing-solution "hide" "show")]
(when-not no-heading
[:h3.demo-heading "Solution"])
(when @showing-solution src)]
[:div.clearfix])]))