Browse code

Add styling and views to have a consistent visual appeal to my other apps

Joseph Weston authored on 02/03/2022 06:52:37
Showing 6 changed files
... ...
@@ -1,6 +1,8 @@
1
-(ns jambda.config)
1
+(ns jambda.config
2
+  (:require [cljs.core :refer [goog-define]]))
2 3
 
3 4
 (def debug?
4 5
   ^boolean goog.DEBUG)
5 6
 
6
-(goog-define ^js/String version "unknown")
7
+; This will be filled in at compile time by shadow-git-inject
8
+(goog-define ^String version "-- no version --")
... ...
@@ -4,8 +4,7 @@
4 4
    [re-frame.core :as re-frame]
5 5
    [jambda.events :as events]
6 6
    [jambda.views :as views]
7
-   [jambda.config :as config]
8
-   ))
7
+   [jambda.config :as config]))
9 8
 
10 9
 
11 10
 (defn dev-setup []
... ...
@@ -1,4 +1,4 @@
1 1
 (ns jambda.db)
2 2
 
3 3
 (def default-db
4
-  {:name "re-frame"})
4
+    {:name "Jambda"})
... ...
@@ -2,8 +2,8 @@
2 2
   (:require
3 3
    [re-frame.core :as re-frame]
4 4
    [jambda.db :as db]
5
-   [day8.re-frame.tracing :refer-macros [fn-traced]]
6
-   ))
5
+   [day8.re-frame.tracing :refer-macros [fn-traced]]))
6
+
7 7
 
8 8
 (re-frame/reg-event-db
9 9
  ::initialize-db
10 10
new file mode 100644
... ...
@@ -0,0 +1,90 @@
1
+(ns jambda.styles
2
+  (:require
3
+   [spade.core :as spade]
4
+   [garden.selectors :as s])
5
+  (:require-macros
6
+    [garden.def :refer [defcssfn]]
7
+    [spade.core   :refer [defglobal defclass]]))
8
+
9
+(def gruvbox-colors
10
+  {:dark0-hard       :#1d2021
11
+   :dark0            :#282828
12
+   :dark0-soft       :#32302f
13
+   :dark1            :#3c3836
14
+   :dark2            :#504945
15
+   :dark3            :#665c54
16
+   :dark4            :#7c6f64
17
+
18
+   :gray-245         :#928374
19
+   :gray-244         :#928374
20
+
21
+   :light0-hard      :#f9f5d7
22
+   :light0           :#fbf1c7
23
+   :light0-soft      :#f2e5bc
24
+   :light1           :#ebdbb2
25
+   :light2           :#d5c4a1
26
+   :light3           :#bdae93
27
+   :light4           :#a89984
28
+
29
+   :bright-red       :#fb4934
30
+   :bright-green     :#b8bb26
31
+   :bright-yellow    :#fabd2f
32
+   :bright-blue      :#83a598
33
+   :bright-purple    :#d3869b
34
+   :bright-aqua      :#8ec07c
35
+   :bright-orange    :#fe8019
36
+
37
+   :neutral-red      :#cc241d
38
+   :neutral-green    :#98971a
39
+   :neutral-yellow   :#d79921
40
+   :neutral-blue     :#458588
41
+   :neutral-purple   :#b16286
42
+   :neutral-aqua     :#689d6a
43
+   :neutral-orange   :#d65d0e
44
+
45
+   :faded-red        :#9d0006
46
+   :faded-green      :#79740e
47
+   :faded-yellow     :#b57614
48
+   :faded-blue       :#076678
49
+   :faded-purple     :#8f3f71
50
+   :faded-aqua       :#427b58
51
+   :faded-orange     :#af3a03})
52
+
53
+; TODO: put this in an atom and put it in the appstate
54
+(def colorscheme gruvbox-colors)
55
+
56
+(defcssfn calc)
57
+
58
+(def mono-font ["Source Code Pro" "monospace"])
59
+
60
+(defn- content-after [x] [(s/& s/after) {:content (str "'" x "'")}])
61
+(defn- content-before [x] [(s/& s/before) {:content (str "'" x "'")}])
62
+
63
+(defglobal defaults
64
+  [:body
65
+   {
66
+    :color (colorscheme :dark1)
67
+    :font-family mono-font
68
+    :font-size :100%
69
+    :line-height :1.2rem
70
+    :background-color    (colorscheme :light0-hard)}])
71
+
72
+(defclass screen []
73
+    {:display :flex
74
+     :justify-content :center})
75
+
76
+(defclass main-panel []
77
+    {:width :88ch})
78
+
79
+(defclass footer []
80
+    {:font-size :0.75rem}
81
+    [(s/not (s/last-child)) {} (content-after " ยท ")])
82
+
83
+(def title-style
84
+  [:h1 {:margin-top :0.2rem
85
+        :margin-bottom :0.2rem
86
+        :background-color (colorscheme :dark1)
87
+        :color (colorscheme :light0-soft)
88
+        :padding :0.2rem
89
+        ; letters that hang down touch the lower edge of the box without this
90
+        :padding-bottom :0.4rem}])
... ...
@@ -1,13 +1,49 @@
1 1
 (ns jambda.views
2 2
   (:require
3 3
    [re-frame.core :as re-frame]
4
-   [jambda.subs :as subs]
4
+   [clojure.string :as string]
5
+   [goog.string :as gstr]
5 6
    [jambda.config :as config]
6
-   ))
7
+   [jambda.styles :as styles]
8
+   [jambda.subs :as subs]))
7 9
 
8
-(defn main-panel []
10
+(defn- join-lines [coll]
11
+    (string/join \newline coll))
12
+
13
+(defn- comma-separated [coll]
14
+    (string/join ", " coll))
15
+
16
+(defn- parenthesize [s]
17
+    (when s (str "(" s ")")))
18
+
19
+(defn- spaced [& elements]
20
+    (string/join " " (filter identity elements)))
21
+
22
+
23
+(defn- link-to [href & content]
24
+    [:a {:href href} content])
25
+
26
+(def agpl-link
27
+    (link-to
28
+     "https://www.gnu.org/licenses/agpl-3.0.html"
29
+     "GNU Affero Public License"))
30
+
31
+(def uberspace-link
32
+    (link-to
33
+     "https://uberspace.de/"
34
+     "Uberspace"))
35
+
36
+(defn footer []
37
+  [:footer {:class (styles/footer)}
38
+   [:span.license agpl-link]
39
+   [:span.version (spaced "version:" config/version)]
40
+   [:span.host "Hosted by " uberspace-link]])
41
+
42
+(defn title []
9 43
   (let [name (re-frame/subscribe [::subs/name])]
10
-    [:div
11
-     [:h1
12
-      "Hello from " @name". Version " config/version]
13
-     ]))
44
+    [:h1 "Welcome to " @name]))
45
+   
46
+(defn main-panel []
47
+  [:div {:class (styles/screen)}
48
+   [:div {:class (styles/main-panel)}
49
+    [title] [footer]]])