Last active
November 19, 2020 10:56
-
-
Save viebel/aea3dad2de27c25121d1914d606d4087 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns simple.core | |
(:require | |
[reagent.core :as reagent :refer-macros [with-let]] | |
[reagent.dom :refer [render]])) | |
(def my-org | |
{:name "nestle" | |
:description "bla bla bla" | |
:children [{:name "Choco" | |
:description "woo"} | |
{:name "Moka" | |
:description "boo" | |
:children [{:name "Elite" | |
:description "YESH"}]}]}) | |
(defn org-tree [org] | |
(with-let [opened (reagent/atom false)] | |
(if @opened | |
[:div | |
[:div {:onClick #(do | |
(println "close" (:name org)) | |
(reset! opened false) | |
)} | |
"Name: "(:name org)] | |
[:div "Description: " (:description org)] | |
[:ul | |
(for [child (:children org)] | |
[:li [org-tree child]])]] | |
[:div {:onClick #(do | |
(println "open" (:name org)) | |
(reset! opened true) | |
)} | |
"> " (:name org)]))) | |
(defn ui [] | |
[org-tree my-org]) | |
;; do not touch | |
(render [ui] js/klipse-container) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment