|
1 | 1 | (ns quo2.components.drawers.action-drawers.view
|
2 |
| - (:require [quo2.components.icon :as icon] |
| 2 | + (:require [react-native.core :as rn] |
| 3 | + [quo2.components.drawers.action-drawers.style :as style] |
| 4 | + [quo2.components.icon :as icon] |
3 | 5 | [quo2.components.markdown.text :as text]
|
4 | 6 | [quo2.foundations.colors :as colors]
|
5 |
| - [react-native.core :as rn] |
6 |
| - [quo2.components.drawers.action-drawers.style :as style])) |
| 7 | + [quo2.theme :as theme])) |
7 | 8 |
|
8 | 9 | (defn- get-icon-color
|
9 |
| - [danger? override-theme] |
| 10 | + [danger? theme] |
10 | 11 | (if danger?
|
11 |
| - colors/danger-60 |
12 |
| - (colors/theme-colors colors/neutral-50 colors/neutral-40 override-theme))) |
| 12 | + (colors/theme-colors colors/danger-50 colors/danger-60 theme) |
| 13 | + (colors/theme-colors colors/neutral-50 colors/neutral-40 theme))) |
13 | 14 |
|
14 | 15 | (defn- divider
|
15 |
| - [] |
| 16 | + [theme] |
16 | 17 | [rn/view
|
17 |
| - {:style (style/divider) |
| 18 | + {:style (style/divider theme) |
18 | 19 | :accessible true
|
19 | 20 | :accessibility-label :divider}])
|
20 | 21 |
|
|
24 | 25 | [rn/view (dissoc props :on-press) child]
|
25 | 26 | [rn/touchable-highlight props child]))
|
26 | 27 |
|
27 |
| -(defn- action |
| 28 | +(defn- action-internal |
28 | 29 | [{:keys [icon
|
29 | 30 | label
|
30 | 31 | sub-label
|
|
34 | 35 | disabled?
|
35 | 36 | on-press
|
36 | 37 | add-divider?
|
37 |
| - override-theme |
| 38 | + theme |
38 | 39 | accessibility-label
|
39 |
| - icon-color] |
40 |
| - :as action-props}] |
41 |
| - (when action-props |
42 |
| - [:<> {:key label} |
43 |
| - (when add-divider? |
44 |
| - [divider]) |
45 |
| - [maybe-pressable disabled? |
46 |
| - {:accessibility-label accessibility-label |
47 |
| - :style (style/container sub-label disabled?) |
48 |
| - :underlay-color (colors/theme-colors colors/neutral-5 colors/neutral-90 override-theme) |
49 |
| - :on-press on-press} |
50 |
| - [rn/view |
51 |
| - {:style (style/row-container sub-label)} |
52 |
| - [rn/view |
53 |
| - {:accessibility-label :left-icon-for-action |
54 |
| - :accessible true |
55 |
| - :style style/left-icon} |
56 |
| - [icon/icon icon |
57 |
| - {:color (or icon-color (get-icon-color danger? override-theme)) |
58 |
| - :size 20}]] |
59 |
| - [rn/view |
60 |
| - {:style style/text-container} |
| 40 | + icon-color]}] |
| 41 | + [:<> |
| 42 | + (when add-divider? |
| 43 | + [divider theme]) |
| 44 | + [maybe-pressable disabled? |
| 45 | + {:accessibility-label accessibility-label |
| 46 | + :style (style/container sub-label disabled?) |
| 47 | + :underlay-color (colors/theme-colors colors/neutral-5 colors/neutral-90 theme) |
| 48 | + :on-press on-press} |
| 49 | + [rn/view |
| 50 | + {:style (style/row-container sub-label)} |
| 51 | + [rn/view |
| 52 | + {:accessibility-label :left-icon-for-action |
| 53 | + :accessible true |
| 54 | + :style style/left-icon} |
| 55 | + [icon/icon icon |
| 56 | + {:color (or icon-color (get-icon-color danger? theme)) |
| 57 | + :size 20}]] |
| 58 | + [rn/view |
| 59 | + {:style style/text-container} |
| 60 | + [text/text |
| 61 | + {:size :paragraph-1 |
| 62 | + :weight :medium |
| 63 | + :style {:color |
| 64 | + (cond |
| 65 | + danger? (colors/theme-colors colors/danger-50 colors/danger-60 theme) |
| 66 | + :else (colors/theme-colors colors/neutral-100 colors/white theme))}} |
| 67 | + label] |
| 68 | + (when sub-label |
61 | 69 | [text/text
|
62 |
| - {:size :paragraph-1 |
63 |
| - :weight :medium |
64 |
| - :style {:color |
65 |
| - (cond |
66 |
| - danger? (colors/theme-colors colors/danger-50 colors/danger-60 override-theme) |
67 |
| - :else (colors/theme-colors colors/neutral-100 colors/white override-theme))}} |
68 |
| - label] |
69 |
| - (when sub-label |
| 70 | + {:size :paragraph-2 |
| 71 | + :style {:color |
| 72 | + (colors/theme-colors colors/neutral-50 colors/neutral-40 theme)}} |
| 73 | + sub-label])] |
| 74 | + (when (or right-text right-icon) |
| 75 | + [rn/view {:style style/right-side-container} |
| 76 | + (when right-text |
70 | 77 | [text/text
|
71 |
| - {:size :paragraph-2 |
72 |
| - :style {:color |
73 |
| - (colors/theme-colors colors/neutral-50 colors/neutral-40 override-theme)}} |
74 |
| - sub-label])] |
75 |
| - (when (or right-text right-icon) |
76 |
| - [rn/view {:style style/right-side-container} |
77 |
| - (when right-text |
78 |
| - [text/text |
79 |
| - {:accessibility-label :right-text-for-action |
80 |
| - :size :paragraph-1 |
81 |
| - :style (style/right-text override-theme)} |
82 |
| - right-text]) |
83 |
| - (when right-icon |
84 |
| - [rn/view |
85 |
| - {:style style/right-icon |
86 |
| - :accessible true |
87 |
| - :accessibility-label :right-icon-for-action} |
88 |
| - [icon/icon right-icon |
89 |
| - {:color (get-icon-color danger? override-theme) |
90 |
| - :size 20}]])])]]])) |
| 78 | + {:accessibility-label :right-text-for-action |
| 79 | + :size :paragraph-1 |
| 80 | + :style (style/right-text theme)} |
| 81 | + right-text]) |
| 82 | + (when right-icon |
| 83 | + [rn/view |
| 84 | + {:style style/right-icon |
| 85 | + :accessible true |
| 86 | + :accessibility-label :right-icon-for-action} |
| 87 | + [icon/icon right-icon |
| 88 | + {:color (get-icon-color danger? theme) |
| 89 | + :size 20}]])])]]]) |
| 90 | + |
| 91 | +(def ^:private action (theme/with-theme action-internal)) |
91 | 92 |
|
92 | 93 | (defn action-drawer
|
93 | 94 | [sections]
|
94 | 95 | [:<>
|
95 | 96 | (doall
|
96 | 97 | (for [actions sections]
|
97 |
| - (doall |
98 |
| - (map action actions))))]) |
| 98 | + (let [filtered-actions (filter some? actions)] |
| 99 | + (doall |
| 100 | + (map #(with-meta [action %] {:key (:label %)}) filtered-actions)))))]) |
0 commit comments