git.fiddlerwoaroof.com
Browse code

moving

Ed Langley authored on 29/10/2020 22:08:40
Showing 3 changed files
... ...
@@ -7,14 +7,17 @@
7 7
                  [thheller/shadow-cljs "2.6.7"]
8 8
                  [fulcrologic/fulcro "2.6.3"]
9 9
 
10
-                                        ; Only required if you use server
10
+                 ;; Only required if you use server
11 11
                  [http-kit "2.3.0"]
12 12
                  [ring/ring-core "1.7.0" :exclusions [commons-codec]]
13 13
                  [bk/ring-gzip "0.3.0"]
14 14
                  [bidi "2.1.4"]
15 15
 
16
-                                        ; only required if you want to use this for tests
17
-                 [fulcrologic/fulcro-spec "2.1.1" :scope "test" :exclusions [fulcrologic/fulcro]]]
16
+                 ;; only required if you want to use this for tests
17
+                 [fulcrologic/fulcro-spec "2.1.1" :scope "test" :exclusions [fulcrologic/fulcro]]
18
+
19
+                 [binaryage/dirac "RELEASE"]
20
+                 ]
18 21
 
19 22
   :uberjar-name "fulcro_cljdoc.jar"
20 23
 
... ...
@@ -39,10 +42,10 @@
39 42
                                          [devcards "0.2.6" :exclusions [cljsjs/react cljsjs/react-dom]]]
40 43
                           :repl-options
41 44
                           {:init-ns shadow.user
42
-                           :nrepl-middleware
43
-                           [shadow.cljs.devtools.server.nrepl/cljs-load-file
44
-                            shadow.cljs.devtools.server.nrepl/cljs-eval
45
-                            shadow.cljs.devtools.server.nrepl/cljs-select]}}
45
+                           :nrepl-middleware [shadow.cljs.devtools.server.nrepl/cljs-load-file
46
+                                              shadow.cljs.devtools.server.nrepl/cljs-eval
47
+                                              shadow.cljs.devtools.server.nrepl/cljs-select
48
+                                              dirac.nrepl/middleware]}}
46 49
              :dev        [:cljs
47 50
                           {:source-paths ["src/dev" "src/main" "src/cards"]
48 51
                            :jvm-opts     ["-XX:-OmitStackTraceInFastThrow" "-client" "-XX:+TieredCompilation" "-XX:TieredStopAtLevel=1"
... ...
@@ -79,3 +79,4 @@
79 79
   (shadow-api/watch :main)
80 80
   (shadow-api/watch :cards)
81 81
   (shadow-api/watch :test))
82
+
... ...
@@ -2,62 +2,112 @@
2 2
   (:require
3 3
    [fulcro.client.mutations :as m]
4 4
    [garden.core :as g]
5
+   [garden.selectors :as gs]
5 6
    [fulcro-css.css :as css]
6 7
    [fulcro.client.util :as util]
7 8
    [fulcro.client.data-fetch :as df]
8
-   #?(:cljs [fulcro.client.localized-dom :as dom] :clj [fulcro.client.localized-dom-server :as dom])
9
+   [clojure.string]
10
+   #?(:cljs [fulcro.client.dom :as dom!]
11
+      :clj [fulcro.client.dom-server :as dom!])
12
+   #?(:cljs [fulcro.client.localized-dom :as dom]
13
+      :clj [fulcro.client.localized-dom-server :as dom])
9 14
    [fulcro-cljdoc.api.mutations :as api]
10 15
    [fulcro.client.primitives :as prim :refer [defsc]]
11 16
    [fulcro.i18n :as i18n :refer [tr trf]]))
12 17
 
13
-(defn ensure-seq [m-seq]
18
+(defn ensure-seq 
14 19
   "make sure that m-seq is a seq, otherwise seqify it"
20
+  [m-seq]
15 21
   (if (seq? m-seq)
16 22
     m-seq
17 23
     [m-seq]))
18 24
 
19 25
 (defsc Sidebar [this {items :items}]
20
-  (dom/ul (map #(apply (comp dom/li
21
-                             dom/a)
22
-                       %)
23
-               (ensure-seq items))))
26
+  {:css [[:.sidebar {:display :block
27
+                     :color "rgb(63,63,63)"
28
+                     :background "rgb(197,199,168)"
29
+                     :border-right "double 5px #88a"
30
+                     :height "100vh"
31
+                     :min-width "9em"
32
+                     :text-align "right"
33
+                     :width "12.5vw"}]]}
34
+  (dom/nav :.sidebar
35
+           (dom/ul (map #(apply (comp dom/li
36
+                                      dom/a)
37
+                                %)
38
+                        (ensure-seq items)))))
24 39
 (def ui-sidebar (prim/factory Sidebar))
25 40
 
41
+(defn h* [{level :level :as props} & children]
42
+  (apply (case level
43
+           1 dom/h1
44
+           2 dom/h2
45
+           3 dom/h3
46
+           4 dom/h4
47
+           5 dom/h5
48
+           6 dom/h6)
49
+         (dissoc props :level)
50
+         children))
51
+
52
+(defsc Header [this {title :title}]
53
+  {:css [[:header {:text-shadow "0 0 0.1em rgb(63,63,63), 0 0 0.2em #fff"}]
54
+         [:h1 {:font-size "1.5em"}]]}
55
+  (dom/header
56
+   (h* {:level 1} title)
57
+   (prim/children this)))
58
+
59
+(def ui-header (prim/factory Header))
60
+
26 61
 ;; The main UI of your application
27 62
 (defsc Layout [this props]
28 63
   {:css [[:.container {:display :flex}]
29
-         [:main :.sidebar
64
+         [:main (gs/> :.container :nav)
30 65
           {:padding "1em 1.5em"
31
-           :vertical-scroll :auto}]
66
+           :scroll-y :auto}]
67
+         [(gs/> :.container :nav)
68
+          {:padding-top "5em"}]
69
+         [:$content {}]
32 70
          [:main     {:background "rgb(63,63,63)"
33 71
                      :color "rgb(197,199,168)"
34 72
                      :height "100vh"
35 73
                      :flex-grow 1}]
36
-         [:.sidebar {:display :block
37
-                     :color "rgb(63,63,63)"
38
-                     :background "rgb(197,199,168)"
39
-                     :border-right "double 5px #88a"
40
-                     :height "100vh"
41
-                     :min-width "25vw"
42
-                     :max-width "33vw"}]]}
43
-  (let [children (prim/children props)]
44
-    (let [names (map #(do [{:href "#"} (name %)])
45
-                     (keys (ns-publics 'fulcro-cljdoc.ui.root)))
46
-          out (dom/div :.container
47
-                       (dom/nav :.sidebar (ui-sidebar {:items names}))
48
-                       (dom/main 
49
-                        children))]
74
+         [:header {:border-bottom "double 5px #88a"
75
+                   :margin "0 -1.5em"
76
+                   :margin-bottom "0.75em"
77
+                   :padding-bottom "1em"
78
+                   :padding-left "1.5em"}]]
79
+   :css-include [Sidebar Header]}
80
+  (let [children (prim/children this)
81
+        sidebar (util/first-node Sidebar children)
82
+        header (util/first-node Header children)
83
+        others (filter #(and (not= sidebar %)
84
+                             (not= header %))
85
+                       children)]
86
+    (let [out (dom/div :.container
87
+                       sidebar
88
+                       (dom/main
89
+                        header
90
+                        (dom/section :$content others)))]
50 91
       out)))
51 92
 
52 93
 (def layout (prim/factory Layout))
53 94
 
54 95
 (defsc Root [this props]
55 96
   {:css-include [Layout]}
56
-  (println "hi")
57
-  ;; (css/upsert-css "root-css" Root)
58
-  (layout 
59
-   (ui-sidebar)
60
-   (dom/div "hi")))
61
-
62
-#?(:cljs (css/upsert-css "root-css" Layout))
63
-;; (dom/style {:dangerouslySetInnerHTML {:__html (g/css (css/get-css Root))}})
97
+  (let [publics (ns-publics 'fulcro-cljdoc.ui.root)
98
+        names (map #(do [{:href "#"}
99
+                         (name %)])
100
+                   (sort-by (comp clojure.string/lower-case
101
+                                  name)
102
+                            (keys publics)))]
103
+    (layout {}
104
+            (ui-sidebar {:items names})
105
+            (ui-header {:title "Hi there"})
106
+            (dom/div {}
107
+                     "hello world"
108
+                     (:doc
109
+                      (meta
110
+                       (get publics
111
+                            (symbol "ensure-seq"))))))))
112
+
113
+#?(:cljs (css/upsert-css "root-css" Root))