From b119860b81a82ee53a7474cb7c21e0179c361715 Mon Sep 17 00:00:00 2001 From: Alexander Date: Tue, 11 Jun 2024 15:26:04 +0200 Subject: [PATCH] Enhance the `dapp-avatar` component (#20392) --- .../components/avatars/dapp_avatar/style.cljs | 70 ++++++++++++++----- .../components/avatars/dapp_avatar/view.cljs | 18 +++-- .../preview/quo/avatars/dapp_avatar.cljs | 9 ++- 3 files changed, 68 insertions(+), 29 deletions(-) diff --git a/src/quo/components/avatars/dapp_avatar/style.cljs b/src/quo/components/avatars/dapp_avatar/style.cljs index 41cb4edd0ab..01878b61acb 100644 --- a/src/quo/components/avatars/dapp_avatar/style.cljs +++ b/src/quo/components/avatars/dapp_avatar/style.cljs @@ -1,23 +1,59 @@ (ns quo.components.avatars.dapp-avatar.style) -(def ^:const size 32) +(defn- size->int + [size] + (case size + :size-32 32 + :size-64 64 + 32)) -(def container - {:height size - :width size}) +(defn container + [size] + (let [container-size (size->int size)] + {:height container-size + :width container-size})) -(def hole-view - {:width size - :height size}) +(defn hole-view + [size] + (let [container-size (size->int size)] + {:width container-size + :height container-size})) -(def context - {:width 16 - :height 16 - :border-radius 8 - :position :absolute - :right -4 - :bottom -4}) +(defn context + [size] + (let [context-size (case size + :size-32 16 + :size-64 20 + 20) + offset (case size + :size-32 -4 + :size-64 0 + -4)] + {:width context-size + :height context-size + :border-radius (/ context-size 2) + :position :absolute + :right offset + :bottom offset})) -(def image - {:width size - :height size}) +(defn context-hole + [size] + (let [context-hole-size (case size + :size-32 18 + :size-64 24 + 18) + offset (case size + :size-32 19 + :size-64 42 + 19)] + {:x offset + :y offset + :width context-hole-size + :height context-hole-size + :borderRadius (/ context-hole-size 2)})) + +(defn image + [size] + (let [container-size (size->int size)] + {:width container-size + :height container-size})) diff --git a/src/quo/components/avatars/dapp_avatar/view.cljs b/src/quo/components/avatars/dapp_avatar/view.cljs index 00facc7737c..5a4bcdeda51 100644 --- a/src/quo/components/avatars/dapp_avatar/view.cljs +++ b/src/quo/components/avatars/dapp_avatar/view.cljs @@ -11,32 +11,30 @@ [:props [:map {:closed true} [:context? {:optional true} [:maybe :boolean]] + [:size {:optional true} [:maybe [:enum :size-32 :size-64]]] [:image :schema.common/image-source] [:network-image {:optional true} [:maybe :schema.common/image-source]] [:container-style {:optional true} [:maybe :map]]]]] :any]) (defn- view-internal - [{:keys [context? image network-image container-style]}] + [{:keys [context? size image network-image container-style]}] [rn/view - {:style (merge style/container container-style) + {:style (-> (style/container size) + (merge container-style)) :accessibility-label :dapp-avatar} [hole-view/hole-view (cond-> {:holes (if context? - [{:x 19 - :y 19 - :width 18 - :height 18 - :borderRadius 9}] + [(style/context-hole size)] []) - :style style/hole-view} + :style (style/hole-view size)} platform/android? (assoc :key context?)) [rn/image {:source image - :style style/image}]] + :style (style/image size)}]] (when context? [rn/image {:source network-image - :style style/context}])]) + :style (style/context size)}])]) (def view (schema/instrument #'view-internal ?schema)) diff --git a/src/status_im/contexts/preview/quo/avatars/dapp_avatar.cljs b/src/status_im/contexts/preview/quo/avatars/dapp_avatar.cljs index 4a3c2a1e878..34f0d6f96b2 100644 --- a/src/status_im/contexts/preview/quo/avatars/dapp_avatar.cljs +++ b/src/status_im/contexts/preview/quo/avatars/dapp_avatar.cljs @@ -7,11 +7,16 @@ (def descriptor [{:type :boolean - :key :context?}]) + :key :context?} + {:type :select + :key :size + :options [{:key :size-32} + {:key :size-64}]}]) (defn view [] - (let [[state set-state] (rn/use-state {:context? false})] + (let [[state set-state] (rn/use-state {:context? false + :size :size-32})] [preview/preview-container {:state state :set-state set-state