Skip to content

Commit e0eb5b0

Browse files
authored
Support images in dropdown component (#22382) (#22495)
1 parent 572316b commit e0eb5b0

File tree

4 files changed

+69
-9
lines changed

4 files changed

+69
-9
lines changed

src/quo/components/dropdowns/network_dropdown/component_spec.cljs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,18 @@
4141
:show-new-chain-indicator? true}
4242
networks-list])
4343
(h/is-truthy (h/query-by-label-text :network-dropdown))
44-
(h/is-truthy (h/query-by-label-text :new-chain-indicator))))
44+
(h/is-truthy (h/query-by-label-text :new-chain-indicator)))
45+
46+
(h/test "Should show label"
47+
(h/render [network-dropdown/view
48+
{:state :default
49+
:label "Mainnet"}
50+
networks-list])
51+
(h/is-truthy (h/get-by-text "Mainnet")))
52+
53+
(h/test "Should show dropdown icon"
54+
(h/render [network-dropdown/view
55+
{:state :default
56+
:dropdown-icon? true}
57+
networks-list])
58+
(h/is-truthy (h/query-by-label-text :dropdown-icon))))

src/quo/components/dropdowns/network_dropdown/style.cljs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,19 @@
2424
:border-color (container-border-color props)
2525
:align-items :center})
2626

27+
(defn dropdown-text
28+
[theme]
29+
{:color (colors/theme-colors colors/neutral-100 colors/white theme)
30+
:padding-left 8})
31+
32+
(def dropdown-icon-container
33+
{:padding-left 8})
34+
35+
(defn dropdown-icon-colors
36+
[theme]
37+
{:background (colors/theme-colors colors/neutral-20 colors/neutral-80 theme)
38+
:foreground (colors/theme-colors colors/neutral-100 colors/white theme)})
39+
2740
(def new-chain-indicator
2841
{:position :absolute
2942
:right 0})

src/quo/components/dropdowns/network_dropdown/view.cljs

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,25 @@
22
(:require
33
[quo.components.common.new-feature-dot :as new-feature-dot]
44
[quo.components.dropdowns.network-dropdown.style :as style]
5+
[quo.components.icon :as icon]
56
[quo.components.list-items.preview-list.view :as preview-list]
7+
[quo.components.markdown.text :as text]
68
[quo.context :as quo.context]
79
[react-native.core :as rn]))
810

11+
(defn dropdown-icon
12+
[theme]
13+
(let [{:keys [background foreground]} (style/dropdown-icon-colors theme)]
14+
[rn/view {:style style/dropdown-icon-container}
15+
[icon/icon
16+
:i/dropdown
17+
{:size 20
18+
:accessibility-label :dropdown-icon
19+
:color background
20+
:color-2 foreground}]]))
21+
922
(defn view
10-
[{:keys [on-press state show-new-chain-indicator?] :as props} networks]
23+
[{:keys [on-press state show-new-chain-indicator? label dropdown-icon?] :as props} networks]
1124
(let [theme (quo.context/use-theme)
1225
[pressed? set-pressed] (rn/use-state false)
1326
on-press-in (rn/use-callback #(set-pressed true))
@@ -23,8 +36,18 @@
2336
[new-feature-dot/view
2437
{:style style/new-chain-indicator
2538
:accessibility-label :new-chain-indicator}])
26-
[preview-list/view
27-
{:type :network
28-
:list-size (count networks)
29-
:size :size-20}
30-
networks]]))
39+
[rn/view {:flex-direction :row}
40+
[preview-list/view
41+
{:type :network
42+
:list-size (count networks)
43+
:size :size-20}
44+
networks]
45+
(when label
46+
[text/text
47+
{:size :paragraph-1
48+
:weight :medium
49+
:style (style/dropdown-text theme)
50+
:number-of-lines 1}
51+
label])
52+
(when dropdown-icon?
53+
[dropdown-icon theme])]]))

src/status_im/contexts/preview/quo/dropdowns/network_dropdown.cljs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,13 @@
1919
:type :select
2020
:options [{:key 1}
2121
{:key 2}
22-
{:key 3}]}])
22+
{:key 3}]}
23+
{:key :dropdown-icon?
24+
:type :select
25+
:options [{:key true}
26+
{:key false}]}
27+
{:key :label
28+
:type :text}])
2329

2430
(def ^:private networks-list
2531
[{:source (quo.resources/get-network :ethereum)}
@@ -28,7 +34,11 @@
2834

2935
(defn view
3036
[]
31-
(let [component-state (reagent/atom {:state :default :blur? false :amount 3})]
37+
(let [component-state (reagent/atom {:state :default
38+
:blur? false
39+
:amount 3
40+
:dropdown-icon? false
41+
:label nil})]
3242
(fn []
3343
[preview/preview-container
3444
{:state component-state

0 commit comments

Comments
 (0)