Skip to content

Commit 47a44b4

Browse files
committed
Add mechanism to show a hint on each example
Adds an example hint, in spanish as we are aiming at translating to spanish for the tutorial
1 parent 318d5f2 commit 47a44b4

File tree

3 files changed

+26
-8
lines changed

3 files changed

+26
-8
lines changed

demo/reagentdemo/common.cljs

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22
(:require [reagent.core :as r]
33
[reagent.debug :refer-macros [dbg println]]))
44

5-
(defn demo-component [{:keys [expected comp src complete no-heading]}]
6-
(r/with-let [showing (r/atom false)]
5+
(defn demo-component [{:keys [expected comp src hint complete no-heading]}]
6+
(r/with-let [showing-solution (r/atom false)
7+
showing-hint (r/atom false)]
78
[:div
89
(when expected
910
[:div.demo-example.clearfix
@@ -18,16 +19,26 @@
1819
[:h3.demo-heading "Actual output "])
1920
(if-not complete
2021
[:div.simple-demo [comp]]
21-
[comp])])])
22+
[comp])])
23+
(when hint
24+
[:div
25+
[:a.demo-example-hide {:on-click (fn [e]
26+
(.preventDefault e)
27+
(swap! showing-hint not)
28+
nil)}
29+
(if @showing-hint "hide" "show")]
30+
[:h3.demo-heading "Hint"]
31+
(when @showing-hint
32+
hint)])])
2233

2334
(if src
2435
[:div.demo-source.clearfix
2536
[:a.demo-example-hide {:on-click (fn [e]
2637
(.preventDefault e)
27-
(swap! showing not)
38+
(swap! showing-solution not)
2839
nil)}
29-
(if @showing "hide" "show")]
40+
(if @showing-solution "hide" "show")]
3041
(when-not no-heading
3142
[:h3.demo-heading "Solution"])
32-
(when @showing src)]
43+
(when @showing-solution src)]
3344
[:div.clearfix])]))

demo/reagentdemo/intro.cljs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,9 +132,16 @@
132132
and to be fast enough by default that you rarely have to care
133133
about performance."]
134134

135-
[:p "A very basic Reagent component may look something like this: "]
135+
[:p "Vamos a empezar con un ejemplo de componente Reagent básico:"]
136136
[demo-component {:expected simple-component
137137
:comp solutions/simple-component
138+
:hint [:div
139+
[:p "Los componentes en reagent usan sintaxis tipo "
140+
[:a {:href "https://github.com/weavejester/hiccup"}
141+
"hiccup"]
142+
". Un ejemplo de hiccup: "]
143+
[:code (s/syntaxed "[:p \"Soy del \" [:span {:style {:color :red}} \"Rojo\"]]")]
144+
[:p "Ahora intenta escribir la solución en solutions/simple-component (en el archivo src/reagentdemo/solutions.cljs), de forma tal que se vea como más arriba."]]
138145
:src (s/src-of [:simple-component])}]
139146

140147
[:p "You can build new components using other components as

demo/reagentdemo/solutions.cljs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
"Solutions for the tutorial examples. Your code goes here.")
33

44
(defn simple-component []
5-
[:div "Hello!"])
5+
[:div "Fix me in reagentdemo.solutions/simple-component"])

0 commit comments

Comments
 (0)