|
1 | 1 | (ns example.core |
2 | 2 | (:require [rum.core :as rum] |
3 | | - [cljss.core :as css :refer-macros [inject-global defstyles]] |
| 3 | + [cljss.core :as css :refer-macros [defstyles defkeyframes]] |
| 4 | + [cljss.rum :refer-macros [defstyled]] |
4 | 5 | [devcards.core :refer-macros [defcard start-devcard-ui!]] |
5 | 6 | [sablono.core :refer [html]])) |
6 | 7 |
|
|
12 | 13 |
|
13 | 14 | ;; design system |
14 | 15 | (def colors |
15 | | - {:blue "#298FCA" |
16 | | - :green "#7BC86C" |
| 16 | + {:blue "#298FCA" |
| 17 | + :green "#7BC86C" |
17 | 18 | :orange "#FFB968" |
18 | | - :red "#EF7564" |
| 19 | + :red "#EF7564" |
19 | 20 | :yellow "#F5DD29"}) |
20 | 21 |
|
21 | 22 | (defstyles text-styles [size] |
22 | 23 | {:font-family "Helvetica Neue" |
23 | | - :font-size size}) |
| 24 | + :font-size size}) |
24 | 25 |
|
25 | 26 | (rum/defc Text |
26 | 27 | [{:keys [size]} |
|
43 | 44 |
|
44 | 45 | (def button->color |
45 | 46 | {:warning (:orange colors) |
46 | | - :error (:red colors) |
47 | | - :ok (:green colors)}) |
| 47 | + :error (:red colors) |
| 48 | + :ok (:green colors)}) |
48 | 49 |
|
49 | 50 | (rum/defc Button |
50 | 51 | [{:keys [kind |
51 | 52 | on-click]} |
52 | 53 | child] |
53 | 54 | [:button |
54 | 55 | {:on-click on-click |
55 | | - :css {:background (get button->color kind) |
56 | | - :border 0 |
57 | | - :border-radius "5px" |
58 | | - :padding "8px 24px" |
59 | | - :font-size "14px" |
60 | | - :color "#fff" |
61 | | - :&:hover {:color "black" |
62 | | - :cursor "pointer"} |
63 | | - :&:focus {:outline "none"}}} |
| 56 | + :css {:background (get button->color kind) |
| 57 | + :border 0 |
| 58 | + :border-radius "5px" |
| 59 | + :padding "8px 24px" |
| 60 | + :font-size "14px" |
| 61 | + :color "#fff" |
| 62 | + :&:hover {:color "black" |
| 63 | + :cursor "pointer"} |
| 64 | + :&:focus {:outline "none"}}} |
64 | 65 | child]) |
65 | 66 |
|
66 | 67 | ;; cards |
67 | 68 | (defcard Colors |
68 | 69 | "Base colors" |
69 | 70 | (fn [state _] |
70 | 71 | (html |
71 | | - [:div {:css {:display "flex" |
| 72 | + [:div {:css {:display "flex" |
72 | 73 | :justify-content "space-between"}} |
| 74 | + |
73 | 75 | (for [[_ color] (:colors @state)] |
74 | 76 | [:div |
75 | | - {:css {:background color |
76 | | - :width "100px" |
77 | | - :height "100px" |
| 77 | + {:css {:background color |
| 78 | + :width "100px" |
| 79 | + :height "100px" |
78 | 80 | :border-radius "5px" |
79 | | - :padding "8px"}} |
| 81 | + :padding "8px" |
| 82 | + :&:hover {:border "1px solid blue"} |
| 83 | + ::css/media {[[:max-width "740px"]] |
| 84 | + {:width "64px" |
| 85 | + :height "64px"}}}} |
80 | 86 | color])])) |
81 | 87 | {:colors colors}) |
82 | 88 |
|
|
94 | 100 | (Button {:kind :error} "Error") |
95 | 101 | (Button {:kind :ok} "OK")])) |
96 | 102 |
|
| 103 | +(def spinner-sizes |
| 104 | + {"m" "16px" |
| 105 | + "l" "32px" |
| 106 | + "xl" "64px"}) |
| 107 | + |
| 108 | +(defkeyframes spin [] |
| 109 | + {:from {:transform "rotate(0deg)"} |
| 110 | + :to {:transform "rotate(360deg)"}}) |
| 111 | + |
| 112 | +(rum/defc spinner |
| 113 | + [{:keys [size color]}] |
| 114 | + [:div {:css {:width (spinner-sizes size) |
| 115 | + :height (spinner-sizes size) |
| 116 | + :border-radius "50%" |
| 117 | + :border-top (str "2px solid " color) |
| 118 | + :border-left "2px solid rgba(0,0,255,0.3)" |
| 119 | + :border-bottom "2px solid rgba(0,0,255,0.3)" |
| 120 | + :border-right "2px solid rgba(0,0,255,0.3)" |
| 121 | + :animation (str (spin) " 1500ms linear infinite")}}]) |
| 122 | + |
| 123 | +(defcard Spinner |
| 124 | + (html |
| 125 | + [:div |
| 126 | + (spinner {:size "m" :color "blue"}) |
| 127 | + (spinner {:size "l" :color "blue"}) |
| 128 | + (spinner {:size "xl" :color "blue"})])) |
| 129 | + |
| 130 | +(defstyled text-field :textarea |
| 131 | + {:width :width |
| 132 | + :height :height |
| 133 | + :border-radius "5px" |
| 134 | + :border "1px solid #ccc" |
| 135 | + :&:hover {:background-color "#eee"} |
| 136 | + :&:focus {:outline "none" |
| 137 | + :border "1px solid blue"}}) |
| 138 | + |
| 139 | +(defcard TextField |
| 140 | + (text-field {:width "300px" |
| 141 | + :height "140px"})) |
97 | 142 |
|
98 | 143 | (defn mount [] |
99 | 144 | (css/remove-styles!)) |
|
0 commit comments