Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avatars/Community Avatar Component #20147

Merged
merged 1 commit into from
May 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
(ns quo.components.avatars.community-avatar.component-spec
(:require [quo.components.avatars.community-avatar.view :as community-avatar]
[test-helpers.component :as h]))

(h/describe "Avatars: Community Avatar"
(h/test "should render correctly"
(h/render-with-theme-provider
[community-avatar/view {:image "mock-image"}])
(h/is-truthy (h/get-by-label-text :community-avatar))))
12 changes: 12 additions & 0 deletions src/quo/components/avatars/community_avatar/style.cljs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
(ns quo.components.avatars.community-avatar.style)

(def ^:private sizes
{:size-32 32
:size-24 24})

(defn image
[size]
(let [size-val (sizes size)]
{:border-radius (/ size-val 2)
:width size-val
:height size-val}))
23 changes: 23 additions & 0 deletions src/quo/components/avatars/community_avatar/view.cljs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
(ns quo.components.avatars.community-avatar.view
(:require [quo.components.avatars.community-avatar.style :as style]
[react-native.core :as rn]
[schema.core :as schema]))

(def ?schema
[:=>
[:catn
[:props
[:map {:closed true}
[:size {:optional true} [:maybe [:enum :size-32 :size-24]]]
[:image :schema.common/image-source]
[:container-style {:optional true} [:maybe :map]]]]]
:any])

(defn- view-internal
[{:keys [size image container-style]}]
[rn/image
{:source image
:accessibility-label :community-avatar
:style (merge (style/image size) container-style)}])

(def view (schema/instrument #'view-internal ?schema))
2 changes: 1 addition & 1 deletion src/quo/components/buttons/swap_order_button/schema.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@
[:map {:closed true}
[:disabled? {:optional true} [:maybe :boolean]]
[:on-press fn?]
[:container-style {:optional true} [:maybe :any]]]]]
[:container-style {:optional true} [:maybe :map]]]]]
:any])
2 changes: 1 addition & 1 deletion src/quo/components/buttons/swap_order_button/view.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
[react-native.core :as rn]
[schema.core :as schema]))

(defn view-internal
(defn- view-internal
[{:keys [disabled? on-press container-style]}]
(let [theme (quo.theme/use-theme)
[pressed? set-pressed] (rn/use-state false)
Expand Down
2 changes: 2 additions & 0 deletions src/quo/core.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
quo.components.avatars.account-avatar.view
quo.components.avatars.channel-avatar.view
quo.components.avatars.collection-avatar.view
quo.components.avatars.community-avatar.view
quo.components.avatars.group-avatar.view
quo.components.avatars.icon-avatar
quo.components.avatars.token-avatar.view
Expand Down Expand Up @@ -191,6 +192,7 @@
(def account-avatar quo.components.avatars.account-avatar.view/view)
(def channel-avatar quo.components.avatars.channel-avatar.view/view)
(def collection-avatar quo.components.avatars.collection-avatar.view/view)
(def community-avatar quo.components.avatars.community-avatar.view/view)
(def group-avatar quo.components.avatars.group-avatar.view/view)
(def icon-avatar quo.components.avatars.icon-avatar/icon-avatar)
(def token-avatar quo.components.avatars.token-avatar.view/view)
Expand Down
1 change: 1 addition & 0 deletions src/quo/core_spec.cljs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
(ns quo.core-spec
(:require
quo.components.avatars.account-avatar.component-spec
quo.components.avatars.community-avatar.component-spec
quo.components.avatars.token-avatar.component-spec
quo.components.avatars.user-avatar.component-spec
quo.components.banners.banner.component-spec
Expand Down
24 changes: 24 additions & 0 deletions src/status_im/contexts/preview/quo/avatars/community_avatar.cljs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
(ns status-im.contexts.preview.quo.avatars.community-avatar
(:require
[quo.core :as quo]
[react-native.core :as rn]
[status-im.common.resources :as resources]
[status-im.contexts.preview.quo.preview :as preview]))

(def descriptor
[{:type :select
:key :size
:options [{:key :size-32}
{:key :size-24}]}])

(defn view
[]
(let [[state set-state] (rn/use-state {:size :size-32})]
[preview/preview-container
{:state state
:set-state set-state
:descriptor descriptor}
[quo/community-avatar
(assoc state
:image
(resources/get-mock-image :community-logo))]]))
5 changes: 4 additions & 1 deletion src/status_im/contexts/preview/quo/main.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
[status-im.contexts.preview.quo.avatars.account-avatar :as account-avatar]
[status-im.contexts.preview.quo.avatars.channel-avatar :as channel-avatar]
[status-im.contexts.preview.quo.avatars.collection-avatar :as collection-avatar]
[status-im.contexts.preview.quo.avatars.community-avatar :as community-avatar]
[status-im.contexts.preview.quo.avatars.group-avatar :as group-avatar]
[status-im.contexts.preview.quo.avatars.icon-avatar :as icon-avatar]
[status-im.contexts.preview.quo.avatars.token-avatar :as token-avatar]
Expand Down Expand Up @@ -221,7 +222,9 @@
:component shadows/view}]
:animated-list [{:name :animated-header-list
:component animated-header-list/mock-screen}]
:avatar [{:name :group-avatar
:avatar [{:name :community-avatar
:component community-avatar/view}
{:name :group-avatar
:component group-avatar/view}
{:name :icon-avatar
:component icon-avatar/view}
Expand Down