Skip to content

Commit

Permalink
Collection avatar component
Browse files Browse the repository at this point in the history
  • Loading branch information
vkjr committed Sep 30, 2023
1 parent f5f1e63 commit ada435c
Show file tree
Hide file tree
Showing 8 changed files with 79 additions and 0 deletions.
Binary file added resources/images/mock2/bored-ape.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 18 additions & 0 deletions src/quo2/components/avatars/collection_avatar/component_spec.cljs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
(ns quo2.components.avatars.collection-avatar.component-spec
(:require [quo2.components.avatars.collection-avatar.view :as collection-avatar]
[status-im2.common.resources :as resources]
[test-helpers.component :as h]))

(defonce bored-ape (resources/get-mock-image :bored-ape))

(h/describe "collection avatar"
(h/describe "Profile picture"
(h/test "Doesn't crash without image"
(h/render
[collection-avatar/view])
(h/is-truthy (h/get-by-label-text :collection-avatar)))

(h/test "Renders with image"
(h/render
[collection-avatar/view {:image bored-ape}])
(h/is-truthy (h/get-by-label-text :collection-avatar)))))
10 changes: 10 additions & 0 deletions src/quo2/components/avatars/collection_avatar/style.cljs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
(ns quo2.components.avatars.collection-avatar.style
(:require [quo2.foundations.colors :as colors]))

(defn collection-avatar
[theme]
{:width 24
:height 24
:border-width 1
:border-color (colors/theme-colors colors/neutral-80-opa-10 colors/white-opa-10 theme)
:border-radius 6})
18 changes: 18 additions & 0 deletions src/quo2/components/avatars/collection_avatar/view.cljs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
(ns quo2.components.avatars.collection-avatar.view
(:require [quo2.components.avatars.collection-avatar.style :as style]
[quo2.theme :as quo.theme]
[react-native.fast-image :as fast-image]
))

(defn- view-internal
"Opts:
:image - collection image
:theme - keyword -> :light/:dark"
[{:keys [image theme]}]
[fast-image/fast-image
{:accessibility-label :collection-avatar
:source image
:style (style/collection-avatar theme)}])

(def view (quo.theme/with-theme view-internal))
2 changes: 2 additions & 0 deletions src/quo2/core.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
(:require
quo2.components.avatars.account-avatar.view
quo2.components.avatars.channel-avatar.view
quo2.components.avatars.collection-avatar.view
quo2.components.avatars.group-avatar.view
quo2.components.avatars.icon-avatar
quo2.components.avatars.user-avatar.view
Expand Down Expand Up @@ -149,6 +150,7 @@
(def icon-avatar quo2.components.avatars.icon-avatar/icon-avatar)
(def user-avatar quo2.components.avatars.user-avatar.view/user-avatar)
(def wallet-user-avatar quo2.components.avatars.wallet-user-avatar/wallet-user-avatar)
(def collection-avatar quo2.components.avatars.collection-avatar.view/view)

;;;; Banner
(def banner quo2.components.banners.banner.view/view)
Expand Down
1 change: 1 addition & 0 deletions src/status_im2/common/resources.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@

(def mock-images
{:diamond (js/require "../resources/images/mock2/diamond.png")
:bored-ape (js/require "../resources/images/mock2/bored-ape.png")
:coinbase (js/require "../resources/images/mock2/coinbase.png")
:collectible (js/require "../resources/images/mock2/collectible.png")
:contact (js/require "../resources/images/mock2/contact.png")
Expand Down
27 changes: 27 additions & 0 deletions src/status_im2/contexts/quo_preview/avatars/collection_avatar.cljs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
(ns status-im2.contexts.quo-preview.avatars.collection-avatar

(:require [quo2.core :as quo]
[reagent.core :as reagent]
[status-im2.contexts.quo-preview.preview :as preview]
[status-im2.common.resources :as resources]))

(def descriptor
[{:key :image
:type :select
:options [{:key (resources/get-mock-image :bored-ape)
:value "Bored ape"}
{:key (resources/get-mock-image :ring)
:value "Circle"}
]}
])

(defn view
[]
(let [state (reagent/atom {:image (resources/get-mock-image :bored-ape)
})]
(fn []
[preview/preview-container
{:state state
:descriptor descriptor
:component-container-style {:align-items :center}}
[quo/collection-avatar @state]])))
3 changes: 3 additions & 0 deletions src/status_im2/contexts/quo_preview/main.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
:as animated-header-list]
[status-im2.contexts.quo-preview.avatars.account-avatar :as account-avatar]
[status-im2.contexts.quo-preview.avatars.channel-avatar :as channel-avatar]
[status-im2.contexts.quo-preview.avatars.collection-avatar :as collection-avatar]
[status-im2.contexts.quo-preview.avatars.group-avatar :as group-avatar]
[status-im2.contexts.quo-preview.avatars.icon-avatar :as icon-avatar]
[status-im2.contexts.quo-preview.avatars.user-avatar :as user-avatar]
Expand Down Expand Up @@ -183,6 +184,8 @@
:component wallet-user-avatar/view}
{:name :channel-avatar
:component channel-avatar/view}
{:name :collection-avatar
:component collection-avatar/view}
{:name :account-avatar
:component account-avatar/view}]
:banner [{:name :banner
Expand Down

0 comments on commit ada435c

Please sign in to comment.