Skip to content

Commit 89978c5

Browse files
committed
[Refactor] Toast component to use theme context
Signed-off-by: Mohamed Javid <[email protected]>
1 parent 4c4c1ee commit 89978c5

File tree

7 files changed

+77
-54
lines changed

7 files changed

+77
-54
lines changed

src/quo2/components/avatars/user_avatar/style.cljs

+5-5
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
:border-radius dimensions}))
4242

4343
(defn initials-avatar
44-
[size draw-ring? customization-color]
44+
[size draw-ring? customization-color theme]
4545
(let [outer-dimensions (get-in sizes [size :outer])
4646
inner-dimensions (get-in sizes [size (if draw-ring? :inner :outer)])]
4747
{:position :absolute
@@ -52,7 +52,7 @@
5252
:border-radius inner-dimensions
5353
:justify-content :center
5454
:align-items :center
55-
:background-color (colors/custom-color-by-theme customization-color 50 60)}))
55+
:background-color (colors/custom-color-by-theme customization-color 50 60 nil nil theme)}))
5656

5757
(def initials-avatar-text
5858
{:color colors/white-opa-70})
@@ -67,7 +67,7 @@
6767
:background-color background}))
6868

6969
(defn dot
70-
[size ring?]
70+
[size ring? theme]
7171
(let [dimensions (get-in sizes [size :status-indicator])
7272
border-width (get-in sizes [size :status-indicator-border])
7373
right (case size
@@ -89,5 +89,5 @@
8989
:height dimensions
9090
:border-width border-width
9191
:border-radius dimensions
92-
:background-color (colors/theme-colors colors/white colors/neutral-100)
93-
:border-color (colors/theme-colors colors/white colors/neutral-100)}))
92+
:background-color (colors/theme-colors colors/white colors/neutral-100 theme)
93+
:border-color (colors/theme-colors colors/white colors/neutral-100 theme)}))

src/quo2/components/avatars/user_avatar/view.cljs

+10-6
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
(ns quo2.components.avatars.user-avatar.view
22
(:require [quo2.components.avatars.user-avatar.style :as style]
33
[quo2.components.markdown.text :as text]
4+
[quo2.theme :as quo.theme]
45
[react-native.core :as rn]
56
[react-native.fast-image :as fast-image]
67
utils.string))
78

89
(defn initials-avatar
9-
[{:keys [full-name size draw-ring? customization-color]}]
10+
[{:keys [full-name size draw-ring? customization-color theme]}]
1011
(let [font-size (get-in style/sizes [size :font-size])
1112
amount-initials (if (#{:xs :xxs :xxxs} size) 1 2)]
1213
[rn/view
1314
{:accessibility-label :initials-avatar
14-
:style (style/initials-avatar size draw-ring? customization-color)}
15+
:style (style/initials-avatar size draw-ring? customization-color theme)}
1516
[text/text
1617
{:style style/initials-avatar-text
1718
:size font-size
@@ -20,12 +21,12 @@
2021

2122
(def valid-ring-sizes #{:big :medium :small})
2223

23-
(defn user-avatar
24+
(defn- user-avatar-internal
2425
"If no `profile-picture` is given, draws the initials based on the `full-name` and
2526
uses `ring-background` to display the ring behind the initials when given. Otherwise,
2627
shows the `profile-picture` which already comes with the ring drawn."
2728
[{:keys [full-name status-indicator? online? size profile-picture ring-background
28-
customization-color static? muted?]
29+
customization-color static? muted? theme]
2930
:or {status-indicator? true
3031
online? true
3132
size :big
@@ -49,11 +50,14 @@
4950
{:full-name full-name
5051
:size size
5152
:draw-ring? draw-ring?
52-
:customization-color customization-color}])
53+
:customization-color customization-color
54+
:theme theme}])
5355
(when status-indicator?
5456
[rn/view
5557
{:accessibility-label :status-indicator
56-
:style (style/dot size draw-ring?)}
58+
:style (style/dot size draw-ring? theme)}
5759
[rn/view
5860
{:accessibility-label :inner-status-indicator-dot
5961
:style (style/inner-dot size online?)}]])]))
62+
63+
(def user-avatar (quo.theme/with-theme user-avatar-internal))

src/quo2/components/icon.cljs

+7-7
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
[quo2.components.icons.icons :as icons]
44
[quo2.components.icons.svg :as icons.svg]
55
[quo2.foundations.colors :as colors]
6+
[quo2.theme :as quo.theme]
67
[react-native.core :as rn]))
78

89
(defn- valid-color?
@@ -12,11 +13,10 @@
1213
(not (string/blank? color)))))
1314

1415
(defn memo-icon-fn
15-
[icon-name
16-
{:keys [color color-2 no-color
17-
container-style size accessibility-label]
16+
[{:keys [color color-2 no-color
17+
container-style size accessibility-label theme]
1818
:or {accessibility-label :icon}}
19-
_]
19+
icon-name]
2020
(let [size (or size 20)]
2121
^{:key icon-name}
2222
(if-let [svg-icon (icons.svg/get-icon icon-name size)]
@@ -34,15 +34,15 @@
3434
(when (not no-color)
3535
{:tint-color (if (and (string? color) (not (string/blank? color)))
3636
color
37-
(colors/theme-colors colors/neutral-100 colors/white))})
37+
(colors/theme-colors colors/neutral-100 colors/white theme))})
3838

3939
container-style)
4040
:accessibility-label accessibility-label
4141
:source (icons/icon-source (str (name icon-name) size))}])))
4242

43-
(def themed-icon (memoize memo-icon-fn))
43+
(def ^:private themed-icon (memoize (quo.theme/with-theme memo-icon-fn)))
4444

4545
(defn icon
4646
([icon-name] (icon icon-name nil))
4747
([icon-name params]
48-
(themed-icon icon-name params (colors/dark?))))
48+
(themed-icon params icon-name)))

src/quo2/components/markdown/text.cljs

+7-5
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
(ns quo2.components.markdown.text
22
(:require [quo2.foundations.colors :as colors]
33
[quo2.foundations.typography :as typography]
4-
[quo2.theme :as theme]
4+
[quo2.theme :as quo.theme]
55
[react-native.core :as rn]
66
[reagent.core :as reagent]))
77

88
(defn text-style
9-
[{:keys [size align weight style]}]
9+
[{:keys [size align weight style theme]}]
1010
(merge (case (or weight :regular)
1111
:regular typography/font-regular
1212
:medium typography/font-medium
@@ -25,14 +25,16 @@
2525
{:text-align (or align :auto)}
2626
(if (:color style)
2727
style
28-
(assoc style :color (if (= (theme/get-theme) :dark) colors/white colors/neutral-100)))))
28+
(assoc style :color (if (= theme :dark) colors/white colors/neutral-100)))))
2929

30-
(defn text
30+
(defn- text-internal
3131
[]
3232
(let [this (reagent/current-component)
3333
props (reagent/props this)
3434
style (text-style props)]
3535
(into [rn/text
3636
(merge {:style style}
37-
(dissoc props :style :size :align :weight :color))]
37+
(dissoc props :style :size :align :weight :color :theme))]
3838
(reagent/children this))))
39+
40+
(def text (quo.theme/with-theme text-internal))

src/quo2/components/notifications/count_down_circle.cljs

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
(ns quo2.components.notifications.count-down-circle
22
(:require [goog.string :as gstring]
33
[quo2.foundations.colors :as colors]
4-
[quo2.theme :as theme]
4+
[quo2.theme :as quo.theme]
55
[react-native.core :as rn]
66
[react-native.svg :as svg]
77
[reagent.core :as reagent]))
@@ -48,8 +48,8 @@
4848
{:color {:dark colors/neutral-80-opa-40
4949
:light colors/white-opa-40}})
5050

51-
(defn circle-timer
52-
[{:keys [color duration size stroke-width trail-color rotation initial-remaining-time]}]
51+
(defn- circle-timer-internal
52+
[{:keys [color duration size stroke-width trail-color rotation initial-remaining-time theme]}]
5353
(let [rotation (or rotation :clockwise)
5454
duration (or duration 4)
5555
stroke-width (or stroke-width 1)
@@ -98,8 +98,10 @@
9898
[svg/path
9999
{:d path
100100
:fill :none
101-
:stroke (or color (get-in themes [:color (theme/get-theme)]))
101+
:stroke (or color (get-in themes [:color theme]))
102102
:stroke-linecap :square
103103
:stroke-width stroke-width
104104
:stroke-dasharray path-length
105105
:stroke-dashoffset (linear-ease @display-time 0 path-length duration)}])]])})))
106+
107+
(def circle-timer (quo.theme/with-theme circle-timer-internal))

src/quo2/components/notifications/toast/view.cljs

+36-24
Original file line numberDiff line numberDiff line change
@@ -4,31 +4,38 @@
44
[quo2.components.markdown.text :as text]
55
[quo2.components.notifications.count-down-circle :as count-down-circle]
66
[quo2.components.notifications.toast.style :as style]
7-
[quo2.theme :as theme]
7+
[quo2.theme :as quo.theme]
88
[react-native.blur :as blur]
99
[react-native.core :as rn]
1010
[utils.i18n :as i18n]))
1111

1212
(defn toast-action-container
13-
[{:keys [on-press style]} & children]
13+
[{:keys [on-press style theme]} & children]
1414
[rn/touchable-highlight
1515
{:on-press on-press
1616
:underlay-color :transparent}
1717
[into
1818
[rn/view
19-
{:style (merge (style/action-container (theme/get-theme)) style)}]
19+
{:style (merge (style/action-container theme) style)}]
2020
children]])
2121

22-
(defn toast-undo-action
23-
[duration on-press theme]
24-
[toast-action-container {:on-press on-press :accessibility-label :toast-undo-action}
22+
(defn toast-undo-action-internal
23+
[{:keys [undo-duration undo-on-press theme]}]
24+
[toast-action-container
25+
{:on-press undo-on-press
26+
:accessibility-label :toast-undo-action
27+
:theme theme}
2528
[rn/view {:style {:margin-right 5}}
26-
[count-down-circle/circle-timer {:duration duration}]]
29+
[count-down-circle/circle-timer {:duration undo-duration}]]
2730
[text/text
28-
{:size :paragraph-2 :weight :medium :style (style/text theme)}
31+
{:size :paragraph-2
32+
:weight :medium
33+
:style (style/text theme)}
2934
[i18n/label :t/undo]]])
3035

31-
(defn- toast-container
36+
(def ^:private toast-undo-action (quo.theme/with-theme toast-undo-action-internal))
37+
38+
(defn- toast-container-internal
3239
[{:keys [left title text right container-style theme]}]
3340
[rn/view {:style (merge style/box-container container-style)}
3441
[blur/view
@@ -58,22 +65,27 @@
5865
text])]
5966
right]])
6067

68+
(def ^:private toast-container (quo.theme/with-theme toast-container-internal))
69+
6170
(defn toast
6271
[{:keys [icon icon-color title text action undo-duration undo-on-press container-style
6372
theme user]}]
64-
[toast-container
65-
{:left (cond icon
66-
[icon/icon icon
67-
(cond-> (style/icon theme)
68-
icon-color
69-
(assoc :color icon-color))]
73+
(let [context-theme (or theme (quo.theme/get-theme))]
74+
[quo.theme/provider {:theme context-theme}
75+
[toast-container
76+
{:left (cond icon
77+
[icon/icon icon
78+
(cond-> (style/icon context-theme)
79+
icon-color
80+
(assoc :color icon-color))]
7081

71-
user
72-
[user-avatar/user-avatar user])
73-
:title title
74-
:text text
75-
:right (if undo-duration
76-
[toast-undo-action undo-duration undo-on-press theme]
77-
action)
78-
:container-style container-style
79-
:theme theme}])
82+
user
83+
[user-avatar/user-avatar user])
84+
:title title
85+
:text text
86+
:right (if undo-duration
87+
[toast-undo-action
88+
{:undo-duration undo-duration
89+
:undo-on-press undo-on-press}]
90+
action)
91+
:container-style container-style}]]))

src/quo2/foundations/colors.cljs

+6-3
Original file line numberDiff line numberDiff line change
@@ -256,11 +256,14 @@
256256
suffix-light 50/60
257257
suffix-dark 50/60
258258
opacity-light 0-100 (optional)
259-
opacity-dark 0-100 (optional)"
259+
opacity-dark 0-100 (optional)
260+
theme :light/:dark (optional)"
260261
([color suffix-light suffix-dark]
261-
(custom-color-by-theme color suffix-light suffix-dark nil nil))
262+
(custom-color-by-theme color suffix-light suffix-dark nil nil (theme/get-theme)))
262263
([color suffix-light suffix-dark opacity-light opacity-dark]
263-
(if (theme/dark?)
264+
(custom-color-by-theme color suffix-light suffix-dark opacity-light opacity-dark (theme/get-theme)))
265+
([color suffix-light suffix-dark opacity-light opacity-dark theme]
266+
(if (= theme :dark)
264267
(custom-color color suffix-dark opacity-dark)
265268
(custom-color color suffix-light opacity-light))))
266269

0 commit comments

Comments
 (0)