Skip to content

Commit b4fb7c6

Browse files
committed
[nested-grid] Update docs
1 parent ca8256d commit b4fb7c6

File tree

2 files changed

+28
-12
lines changed

2 files changed

+28
-12
lines changed

src/re_com/nested_grid.cljs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@
3333
next-acc
3434
(recur next-path next-acc remainder)))))
3535

36+
(defn leaf-paths [paths]
37+
(reduce (fn [paths p] (remove (partial ancestor? p) paths)) paths paths))
38+
3639
(def spec->headers* (memoize header-spec->header-paths))
3740

3841
(assert (= (header-spec->header-paths [:a :b :c])
@@ -323,7 +326,7 @@
323326
on-export-column-header pr-str}}]
324327
(let [themed (fn [part props] (theme/apply props {:part part} {}))
325328
column-paths (spec->headers* column-tree)
326-
column-leaf-paths (reduce (fn [paths p] (remove (partial ancestor? p) paths)) column-paths column-paths)
329+
column-leaf-paths (leaf-paths column-paths)
327330
leaf-column? (set column-leaf-paths)
328331
row-paths (spec->headers* row-tree)
329332
leaf-row? (set (reduce (fn [paths p] (remove #(descendant? % p) paths)) row-paths row-paths))

src/re_demo/nested_grid.cljs

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -72,15 +72,7 @@
7272
[:li "In that case: "
7373
[:ul
7474
[:li [:code ":a"] " and " [:code ":b"] " are siblings, each with two children."]
75-
[:li [:code "1"] " and " [:code "2"] " are siblings, both children of " [:code ":a"]]]
76-
[nested-grid
77-
:column-tree ["Tree" "Paths"]
78-
:row-tree [{:label "Basic" :tree [:a :b :c]}
79-
{:label "Nested"}]
80-
:cell (fn [{:keys [column-path] {:keys [tree]} :row-path}]
81-
(case (last column-path)
82-
"Tree" (str tree)
83-
"paths" (str (nested-grid/header-spec->header-paths tree))))]]]]
75+
[:li [:code "1"] " and " [:code "2"] " are siblings, both children of " [:code ":a"]]]]]]
8476
[:br]
8577
[:li "A " [:code ":column-path"] " describes a distinct location within a "
8678
[:code ":column-tree"] "."
@@ -129,7 +121,7 @@
129121
[:li "Does not re-render when you scroll or click. Even if that first render is expensive, "
130122
"the UI should be snappy once it completes."]]]
131123
[title2 "Quick Start"]
132-
[p "To use" [:code "nested-grid"] ", at a minimum, you must declare:"
124+
[p "To use " [:code "nested-grid"] ", at a minimum, you must declare:"
133125
[:ul
134126
[:li [:code ":column-tree"] ": a vector describing the column structure."]
135127
[:li [:code ":row-tree"] ": a vector describing the row structure."]
@@ -351,11 +343,32 @@
351343
(defn header-demo []
352344
[:hi])
353345

346+
(defn internals-demo []
347+
[v-box
348+
:children
349+
[[p "This table demonstrates how " [:code "nested-grid"] " derives a vector of " [:code ":column-path"] "s from a " [:code ":column-tree"] ":"]
350+
[nested-grid
351+
:column-tree [{:id "Tree" :width 130}
352+
{:id "Leaf Paths" :width 155}
353+
{:id "All Paths" :width 180}]
354+
:row-tree [{:label "Basic" :tree [:a :b :c]}
355+
{:label "Nested" :tree [:a [:b :c]]}
356+
{:label "Branching" :tree [:a [:b] :c [:d]]}
357+
{:label "Explicit" :tree [[:a [:b :c]]
358+
[:d [:e :f]]]}
359+
{:label "Typed" :tree [:kw 42 "str" {:k :map}]}]
360+
:cell (fn [{:keys [column-path] [{:keys [tree]}] :row-path}]
361+
(case (:id (last column-path))
362+
"Tree" (str tree)
363+
"Leaf Paths" (str (vec (nested-grid/leaf-paths
364+
(nested-grid/header-spec->header-paths tree))))
365+
"All Paths" (str (nested-grid/header-spec->header-paths tree))))]]])
366+
354367
(defn demos []
355368
(let [tabs [{:id :basic :label "Basic Demo" :view basic-demo}
356369
{:id :color :label "Color" :view color-demo}
357370
{:id :shade :label "Shade" :view color-shade-demo}
358-
{:id :header :label "Headers" :view header-demo}
371+
{:id :internals :label "Internals" :view internals-demo}
359372
{:id :spec :label "Spec" :view header-spec-demo}]
360373
!tab-id (r/atom (:id (first tabs)))
361374
!tab (r/reaction (u/item-for-id @!tab-id tabs))]

0 commit comments

Comments
 (0)