Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add hints #11

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 17 additions & 6 deletions demo/reagentdemo/common.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
(:require [reagent.core :as r]
[reagent.debug :refer-macros [dbg println]]))

(defn demo-component [{:keys [expected comp src complete no-heading]}]
(r/with-let [showing (r/atom false)]
(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
Expand All @@ -18,16 +19,26 @@
[:h3.demo-heading "Actual output "])
(if-not complete
[:div.simple-demo [comp]]
[comp])])])
[comp])])
(when hint
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could extract these toggles into a helper component

[: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 not)
(swap! showing-solution not)
nil)}
(if @showing "hide" "show")]
(if @showing-solution "hide" "show")]
(when-not no-heading
[:h3.demo-heading "Solution"])
(when @showing src)]
(when @showing-solution src)]
[:div.clearfix])]))
9 changes: 8 additions & 1 deletion demo/reagentdemo/intro.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,16 @@
and to be fast enough by default that you rarely have to care
about performance."]

[:p "A very basic Reagent component may look something like this: "]
[:p "Vamos a empezar con un ejemplo de componente Reagent básico:"]
[demo-component {:expected simple-component
:comp solutions/simple-component
:hint [:div
[:p "Components in reagent use "
[:a {:href "https://github.com/weavejester/hiccup"}
"hiccup syntax"]
". Here's an example: "]
[:code (s/syntaxed "[:p \"I like it \" [:span {:style {:color :green}} \"green\"]]")]
[:p "Now try to write your solution on solutions/simple-component (in the file src/reagentdemo/solutions.cljs), in such a way that it looks like the example above."]]
:src (s/src-of [:simple-component])}]

[:p "You can build new components using other components as
Expand Down
2 changes: 1 addition & 1 deletion demo/reagentdemo/solutions.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
[reagent.core :as r]))

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

(defn simple-parent []
[:div "Fix me in reagentdemo.solutions/simple-parent"])
Expand Down