Skip to content

Commit ba595d3

Browse files
J-Son89ibrkhalil
authored andcommitted
feat: add token tag component (#13599) (#13644)
Rebase
1 parent 82231a5 commit ba595d3

File tree

8 files changed

+182
-0
lines changed

8 files changed

+182
-0
lines changed
629 Bytes
Loading
806 Bytes
Loading
262 Bytes
Loading
336 Bytes
Loading

src/quo2/components/tag.cljs

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
(ns quo2.components.tag
2+
(:require [quo.react-native :as rn]
3+
[quo2.foundations.colors :as colors]
4+
[quo.theme :as theme]
5+
[quo2.components.text :as text]))
6+
7+
(def themes {:light {:background-color colors/neutral-20}
8+
:dark {:background-color colors/neutral-80}})
9+
10+
(defn get-value-from-size [size big-option small-option]
11+
(if (= size :big) big-option small-option))
12+
13+
(defn tag-container [size]
14+
{:height (get-value-from-size size 32 24)
15+
:align-items :center
16+
:flex-direction :row
17+
:border-radius 20})
18+
19+
(defn tag "[tag opts \"label\"]]
20+
opts
21+
{
22+
:size :small/:big
23+
:token-img-src :token-img-src
24+
:token-img-style {}
25+
:border-color :color
26+
:overlay child-elements
27+
}"
28+
[_ _]
29+
(fn [{:keys [size token-img-src token-img-style border-color overlay]
30+
:or {size :small}} label]
31+
[rn/view
32+
{:style (when border-color
33+
{:border-color border-color
34+
:border-radius 20
35+
:border-width 1})}
36+
[rn/view
37+
{:style (merge (tag-container size) (get themes (theme/get-theme)))}
38+
[rn/image
39+
{:source token-img-src
40+
:style (merge
41+
{:height (get-value-from-size size 28 20)
42+
:width (get-value-from-size size 28 20)
43+
:margin-left 2
44+
:margin-right (get-value-from-size size 8 6)} token-img-style)}]
45+
[text/text
46+
{:weight :medium
47+
:number-of-lines 1
48+
:style
49+
{:margin-right (get-value-from-size size 12 11)}
50+
:size (get-value-from-size size :paragraph-2 :label)} label]
51+
overlay]]))

src/quo2/components/token_tag.cljs

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
(ns quo2.components.token-tag
2+
(:require [quo2.foundations.colors :as colors]
3+
[quo.react-native :as rn]
4+
[quo.theme :as theme]
5+
[status-im.ui.components.icons.icons :as icons]
6+
[quo2.components.tag :as tag]))
7+
8+
(defn get-value-from-size [size big-option small-option]
9+
(if (= size :big) big-option small-option))
10+
11+
(def icon-container-styles
12+
{:display :flex
13+
:align-items :center
14+
:justify-content :center
15+
:position :absolute
16+
:border-radius 20
17+
:margin-left 2})
18+
19+
(defn token-tag
20+
"[token-tag opts]
21+
opts
22+
{
23+
:token string
24+
:value string
25+
:size :small/:big
26+
:token-img-src :token-img-src
27+
:border-color :color
28+
:is-required true/false
29+
:is-purchasable true/false
30+
}"
31+
[_ _]
32+
(fn [{:keys [token value size token-img-src border-color is-required is-purchasable]
33+
:or
34+
{size :small border-color (if (= (theme/get-theme) :dark) colors/purple-60 colors/purple-50)}}]
35+
36+
[tag/tag {:size size
37+
:token-img-src token-img-src
38+
:border-color (when is-required border-color)
39+
:overlay
40+
(when (or is-required is-purchasable)
41+
[rn/view
42+
{:style (merge icon-container-styles
43+
{:width 15.5
44+
:height 15.5
45+
:background-color border-color
46+
:border-color (if (= (theme/get-theme) :dark) colors/black colors/white)
47+
:border-width 1
48+
:right (get-value-from-size size -3.75 -5.75)
49+
:bottom (get-value-from-size size (- 32 7.75 4) (- 24 7.75 2)) ; (- height (icon-height/2) spacing)
50+
})}
51+
[icons/icon (if is-required :main-icons2/required-checkmark12 :main-icons2/purchasable12)
52+
{:no-color true
53+
:width 13.5
54+
:height 13.5}]])}
55+
(str value " " token)]))

src/quo2/screens/main.cljs

+7
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
[quo2.screens.user-avatar :as user-avatar]
1313
[quo2.screens.group-avatar :as group-avatar]
1414
[quo2.screens.activity-logs :as activity-logs]
15+
[quo2.screens.token-tag :as token-tag]
1516
[quo2.screens.counter :as counter]
1617
[quo2.screens.segmented :as segmented]
1718
[quo2.screens.info-message :as info-message]
@@ -43,9 +44,15 @@
4344
{:name :quo2-tabs
4445
:insets {:top false}
4546
:component tabs/preview-tabs}
47+
<<<<<<< HEAD
4648
{:name :quo2-user-avatar
4749
:insets {:top false}
4850
:component user-avatar/preview-user-avatar}
51+
=======
52+
{:name :quo2-token-tag
53+
:insets {:top false}
54+
:component token-tag/preview-token-tag}
55+
>>>>>>> 47a31ae0a (feat: add token tag component (#13599) (#13644))
4956
{:name :quo2-segmented
5057
:insets {:top false}
5158
:component segmented/preview-segmented}

src/quo2/screens/token_tag.cljs

+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
(ns quo2.screens.token-tag
2+
(:require [quo.react-native :as rn]
3+
[quo.previews.preview :as preview]
4+
[reagent.core :as reagent]
5+
[quo2.components.token-tag :as quo2]
6+
[quo.design-system.colors :as colors]))
7+
8+
(def descriptor [{:label "Size:"
9+
:key :size
10+
:type :select
11+
:options [{:key :big
12+
:value "big"}
13+
{:key :small
14+
:value "small"}]}
15+
{:label "Value:"
16+
:key :value
17+
:type :select
18+
:options [{:key 0
19+
:value "0"}
20+
{:key 10
21+
:value "10"}
22+
{:key 100
23+
:value "100"}
24+
{:key 1000
25+
:value "1000"}
26+
{:key 10000
27+
:value "10000"}]}
28+
29+
{:label "Community Color:"
30+
:key :border-color
31+
:type :select
32+
:options [{:key "#00a191"
33+
:value "green"}
34+
{:key "red"
35+
:value "red"}]}
36+
{:label "Is Required:"
37+
:key :is-required
38+
:type :boolean}
39+
{:label "Is Purchasable:"
40+
:key :is-purchasable
41+
:type :boolean}
42+
{:label "Token:"
43+
:key :token
44+
:type :select
45+
:options [{:key "ETH"
46+
:value "ETH"}
47+
{:key "SNT"
48+
:value "SNT"}]}])
49+
50+
(def eth-token (js/require "../resources/images/tokens/mainnet/ETH.png"))
51+
(def snt-token (js/require "../resources/images/tokens/mainnet/SNT.png"))
52+
53+
(defn cool-preview []
54+
(let [state (reagent/atom {:size :big :value 10 :token "ETH" :is-required true :is-purchasable false})]
55+
(fn []
56+
[rn/view {:margin-bottom 50
57+
:padding 16}
58+
[preview/customizer state descriptor]
59+
[rn/view {:padding-vertical 60
60+
:align-items :center}
61+
[quo2/token-tag (merge @state {:token-img-src (if (= (get-in @state [:token]) "ETH") eth-token snt-token)})]]])))
62+
63+
(defn preview-token-tag []
64+
[rn/view {:background-color (:ui-background @colors/theme)
65+
:flex 1}
66+
[rn/flat-list {:flex 1
67+
:keyboardShouldPersistTaps :always
68+
:header [cool-preview]
69+
:key-fn str}]])

0 commit comments

Comments
 (0)