Skip to content

Commit

Permalink
Implement wallet user avatar to match designs (#17703)
Browse files Browse the repository at this point in the history
  • Loading branch information
tumanov-alex authored Nov 2, 2023
1 parent 9a5ed62 commit 0eef520
Show file tree
Hide file tree
Showing 9 changed files with 116 additions and 89 deletions.
68 changes: 0 additions & 68 deletions src/quo/components/avatars/wallet_user_avatar.cljs

This file was deleted.

16 changes: 16 additions & 0 deletions src/quo/components/avatars/wallet_user_avatar/component_spec.cljs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
(ns quo.components.avatars.wallet-user-avatar.component-spec
(:require [quo.components.avatars.wallet-user-avatar.view :as wallet-user-avatar]
[test-helpers.component :as h]))

(h/describe "wallet user avatar"
(h/describe "View internal"
(h/test "Renders by default even with no input parameters"
(h/render
[wallet-user-avatar/wallet-user-avatar {}])
(h/is-truthy (h/query-by-label-text :wallet-user-avatar)))

(h/test "Renders user’s initials when full name is provided"
(h/render
[wallet-user-avatar/wallet-user-avatar {:full-name "Jane Smith"}])
(h/is-truthy (h/get-by-text "JS")))))

27 changes: 27 additions & 0 deletions src/quo/components/avatars/wallet_user_avatar/style.cljs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
(ns quo.components.avatars.wallet-user-avatar.style
(:require [quo.foundations.colors :as colors]))

(defn- circle-color
[customization-color]
(colors/custom-color customization-color 50 20))

(defn- text-color
[customization-color theme]
(colors/theme-colors
(colors/custom-color customization-color 50)
(colors/custom-color customization-color 60)
theme))

(defn container
[circle-size customization-color]
{:width circle-size
:height circle-size
:border-radius circle-size
:text-align :center
:justify-content :center
:align-items :center
:background-color (circle-color customization-color)})

(defn text
[customization-color theme]
{:color (text-color customization-color theme)})
57 changes: 57 additions & 0 deletions src/quo/components/avatars/wallet_user_avatar/view.cljs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
(ns quo.components.avatars.wallet-user-avatar.view
(:require [quo.components.avatars.wallet-user-avatar.style :as style]
[quo.components.markdown.text :as text]
[quo.theme :as quo.theme]
[react-native.core :as rn]
utils.string))

(def properties
{:size-20 {:size 20
:font-size :label
:font-weight :medium}
:size-24 {:size 24
:font-size :label
:font-weight :semi-bold}
:size-32 {:size 32
:font-size :paragraph-2
:font-weight :semi-bold}
:size-48 {:size 48
:font-size :paragraph-1
:font-weight :semi-bold}
:size-64 {:size 64
:font-size :paragraph-1
:font-weight :medium}
:size-80 {:size 80
:font-size :heading-1
:font-weight :medium}})

(def smallest-possible (first (keys properties)))
(def second-smallest-possible (second (keys properties)))
(defn check-if-size-small
[size]
(or (= size smallest-possible)
(= size second-smallest-possible)))
(def biggest-possible (last (keys properties)))

(defn- view-internal
"Options:
:full-name - string (default: nil) - used to generate initials
:customization-color - keyword (default: nil) - color of the avatar
:size - keyword (default: last element of properties object) - size of the
avatar
:monospace? - boolean (default: false) - use monospace font"
[{:keys [full-name customization-color size theme monospace?]
:or {size biggest-possible}}]
(let [circle-size (:size (size properties))
small? (check-if-size-small size)]
[rn/view
{:style (style/container circle-size customization-color)}
[text/text
{:accessibility-label :wallet-user-avatar
:size (:font-size (size properties))
:weight (if monospace? :monospace (:font-weight (size properties)))
:style (style/text customization-color theme)}
(utils.string/get-initials full-name (if small? 1 2))]]))

(def wallet-user-avatar (quo.theme/with-theme view-internal))
2 changes: 1 addition & 1 deletion src/quo/components/list_items/address/view.cljs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
(ns quo.components.list-items.address.view
(:require
[clojure.string :as string]
[quo.components.avatars.wallet-user-avatar :as wallet-user-avatar]
[quo.components.avatars.wallet-user-avatar.view :as wallet-user-avatar]
[quo.components.list-items.address.style :as style]
[quo.components.markdown.text :as text]
[quo.foundations.colors :as colors]
Expand Down
2 changes: 1 addition & 1 deletion src/quo/components/list_items/saved_address/view.cljs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
(ns quo.components.list-items.saved-address.view
(:require
[clojure.string :as string]
[quo.components.avatars.wallet-user-avatar :as wallet-user-avatar]
[quo.components.avatars.wallet-user-avatar.view :as wallet-user-avatar]
[quo.components.icon :as icon]
[quo.components.list-items.saved-address.style :as style]
[quo.components.markdown.text :as text]
Expand Down
2 changes: 1 addition & 1 deletion src/quo/components/share/qr_code/view.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
[quo.components.avatars.account-avatar.view :as account-avatar]
[quo.components.avatars.channel-avatar.view :as channel-avatar]
[quo.components.avatars.user-avatar.view :as user-avatar]
[quo.components.avatars.wallet-user-avatar :as wallet-avatar]
[quo.components.avatars.wallet-user-avatar.view :as wallet-avatar]
[quo.components.share.qr-code.style :as style]
[react-native.core :as rn]
[react-native.fast-image :as fast-image]))
Expand Down
4 changes: 2 additions & 2 deletions src/quo/core.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
quo.components.avatars.group-avatar.view
quo.components.avatars.icon-avatar
quo.components.avatars.user-avatar.view
quo.components.avatars.wallet-user-avatar
quo.components.avatars.wallet-user-avatar.view
quo.components.banners.banner.view
quo.components.browser.browser-input.view
quo.components.buttons.button.view
Expand Down Expand Up @@ -159,7 +159,7 @@
(def group-avatar quo.components.avatars.group-avatar.view/view)
(def icon-avatar quo.components.avatars.icon-avatar/icon-avatar)
(def user-avatar quo.components.avatars.user-avatar.view/user-avatar)
(def wallet-user-avatar quo.components.avatars.wallet-user-avatar/wallet-user-avatar)
(def wallet-user-avatar quo.components.avatars.wallet-user-avatar.view/wallet-user-avatar)

;;;; Banner
(def banner quo.components.banners.banner.view/view)
Expand Down
27 changes: 11 additions & 16 deletions src/status_im2/contexts/quo_preview/avatars/wallet_user_avatar.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,23 @@
[status-im2.contexts.quo-preview.preview :as preview]))

(def descriptor
[{:label "First name"
:key :f-name
:type :text}
{:label "Last name"
:key :l-name
:type :text}
[{:key :full-name
:type :text}
{:key :size
:type :select
:options [{:key :small}
{:key :medium}
{:key :large}
:options [{:key :size-20}
{:key :size-24}
{:key :size-32}
{:key :size-48}
{:key :size-64}
{:key :x-large
:value "X Large"}]}
(preview/customization-color-option {:key :customization-color})])
{:key :size-80}]}
(preview/customization-color-option)])

(defn view
[]
(let [state (reagent/atom {:first-name "empty"
:last-name "name"
:size :x-large
:customization-color :indigo})]
(let [state (reagent/atom {:full-name "empty name"
:size :size-80
:customization-color :blue})]
(fn []
[preview/preview-container {:state state :descriptor descriptor}
[quo/wallet-user-avatar @state]])))

0 comments on commit 0eef520

Please sign in to comment.