Compare commits

..

1 Commits

Author SHA1 Message Date
Oliver Marks 2460cfe73f Refactor
continuous-integration/drone/push Build is passing Details
2021-01-29 14:47:14 +00:00
1 changed files with 19 additions and 21 deletions

View File

@ -32,7 +32,7 @@
[:header.b--black-70.pv4 {:class (when tagline "bb")} [:header.b--black-70.pv4 {:class (when tagline "bb")}
[:h3.f2.fw7.ttu.tracked.lh-title.mt0.mb3.avenir title] [:h3.f2.fw7.ttu.tracked.lh-title.mt0.mb3.avenir title]
(when tagline [:h4.f3.fw4.i.lh-title.mt0 tagline])] (when tagline [:h4.f3.fw4.i.lh-title.mt0 tagline])]
[:section.pt5.pb4 [:p.times.lh-copy.measure.f5.mt0 description]]]]]) [:section.pt5.pb4 [:p.times.lh-copy.measure.f4.mt0 description]]]]])
;; form one component to render article tiles ;; form one component to render article tiles
(defn articles [{:keys [title body articles]}] (defn articles [{:keys [title body articles]}]
@ -66,7 +66,10 @@
(defn circle [{:keys [img alt]}] (defn circle [{:keys [img alt]}]
[:div.pa4.tc [:img.br-100.ba.h3.w3.dib {:src img :alt alt}]]) [:div.pa4.tc [:img.br-100.ba.h3.w3.dib {:src img :alt alt}]])
;; form one component to render a nav link
;; form one component ro render a nav link
(defn navbar-link [{:keys [href title text] :or {text nil title nil}}] (defn navbar-link [{:keys [href title text] :or {text nil title nil}}]
[:a.link.dim.white.dib.mr3 {:key href :href href :title title} text]) [:a.link.dim.white.dib.mr3 {:key href :href href :title title} text])
@ -76,13 +79,11 @@
[:nav.f6.fw6.ttu.tracked [:nav.f6.fw6.ttu.tracked
(map navbar-link links)]]) (map navbar-link links)]])
;; form2 component notice the render function takes the same param as the component function (defn my-component [title]
;; this is important, you can hit issues if you forget this in form 2 components. (let [local-state (reagent/atom true)]
(defn my-component [title value] (fn []
(let [local-state (reagent/atom value)] [:h1 {:class (when @local-state "hid")
(fn [title] :on-click (fn [] (swap! local-state not))} title])))
[:h1 {:class (when @local-state "hide")
:on-click (fn [] (swap! local-state inc))} (str title " " @local-state)])))
;; form one homepage component ;; form one homepage component
@ -120,16 +121,19 @@
[:div.mw7.center.avenir @content]]))) [:div.mw7.center.avenir @content]])))
;; form one render about page component ;; form one render about page component
(defn about-page [] (defn about-page []
[:main.mt4 [:main.mt4
[:section.mw7.center.avenir [:section.mw7.center.avenir
[:h1 "Clojure library examples to aid learning"] [:h1 "Clojure library examples to aid learning"]
[:p "Selection of clojure demos, rendered in reagent which itself is an example of using reagent."] [:p "Selection of clojure demos, rendered in reagent which itself is an example of using reagent."]
[my-component "Clickable component" 1] [my-component "component 1"]
[my-component "Clickable component" 2] [my-component "component 2"]
[:p "Image circle componenet"] [circle {:alt "test"}]
[circle {:img "http://placekitten.com/g/300/300" :alt "test"}] [article {:title "Article"
[:p "Product card component"] :description (-> site-data :lorem)
:tagline "tagline here"}]
[:div.flex.flex-column.flex-row-ns [:div.flex.flex-column.flex-row-ns
[product-card [product-card
{:title "Cat 01" {:title "Cat 01"
@ -140,17 +144,11 @@
{:title "Cat 02" {:title "Cat 02"
:amount "£10.59" :amount "£10.59"
:description "Cat description here" :description "Cat description here"
:link "http://placekitten.com/g/600/300"}]] :link "http://placekitten.com/g/600/300"}]]]])
[:p "Article component"]
[article {:title "Example Article component"
:description (-> site-data :lorem)
:tagline "https://tachyons.io/components/"}]]])
;; form 3 component wrap rendering to catch errors and render them ;; form 3 component wrap rendering to catch errors and render them
;; or just render the rest of the page if all is good ;; or just render the rest of the page if all is good
;; this uses =create-class= and a hash map of life cycle functions ;; this uses =create-class= and a hash map of life cycle functions
(defn err-boundary (defn err-boundary
[& children] [& children]
(let [err-state (reagent/atom nil)] (let [err-state (reagent/atom nil)]