-
Notifications
You must be signed in to change notification settings - Fork 984
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement wallet user avatar to match designs (#17703)
- Loading branch information
1 parent
9a5ed62
commit 0eef520
Showing
9 changed files
with
116 additions
and
89 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
16 changes: 16 additions & 0 deletions
16
src/quo/components/avatars/wallet_user_avatar/component_spec.cljs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"))))) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters