From 3dedf85faee888cfec46fdb65c9d57df1dc2e5f8 Mon Sep 17 00:00:00 2001 From: yqrashawn Date: Tue, 20 Feb 2024 17:14:10 +0800 Subject: [PATCH] chore(schema): for user-avatar component --- .../avatars/user_avatar/schema.cljs | 26 +++++++++++++++++++ .../components/avatars/user_avatar/view.cljs | 12 ++++++--- 2 files changed, 34 insertions(+), 4 deletions(-) create mode 100644 src/quo/components/avatars/user_avatar/schema.cljs diff --git a/src/quo/components/avatars/user_avatar/schema.cljs b/src/quo/components/avatars/user_avatar/schema.cljs new file mode 100644 index 000000000000..b02178b87009 --- /dev/null +++ b/src/quo/components/avatars/user_avatar/schema.cljs @@ -0,0 +1,26 @@ +(ns quo.components.avatars.user-avatar.schema + (:require + [quo.components.avatars.user-avatar.style :as style])) + + +(def ?schema + [:=> + [:catn + [:props + [:map + [:full-name {:optional true} [:maybe string?]] + [:size {:optional true} [:maybe (into [:enum] (keys style/sizes))]] + [:customization-color [:maybe :schema.common/customization-color]] + [:static? {:optional true} [:maybe :any]] + [:status-indicator? {:optional true} [:maybe :any]] + [:online? {:optional true} [:maybe :any]] + [:ring? {:optional true} [:maybe :any]] + [:theme :schema.common/theme] + [:profile-picture + [:maybe + [:or + string? + number? + [:map [:uri string?]] + [:map [:fn fn?]]]]]]]] + :any]) diff --git a/src/quo/components/avatars/user_avatar/view.cljs b/src/quo/components/avatars/user_avatar/view.cljs index 621ef9845e04..ecc5ceb4f496 100644 --- a/src/quo/components/avatars/user_avatar/view.cljs +++ b/src/quo/components/avatars/user_avatar/view.cljs @@ -1,11 +1,13 @@ (ns quo.components.avatars.user-avatar.view (:require + [quo.components.avatars.user-avatar.schema :as component-schema] [quo.components.avatars.user-avatar.style :as style] [quo.components.common.no-flicker-image :as no-flicker-image] [quo.components.markdown.text :as text] [quo.theme] [react-native.core :as rn] [react-native.fast-image :as fast-image] + [schema.core :as schema] utils.string)) (defn initials-avatar @@ -55,10 +57,10 @@ status-indicator? true online? true ring? true - customization-color :blue} + customization-color :blue + full-name "Your Name"} :as props}] - (let [full-name (or full-name "Your Name") - ;; image generated with profile-picture-fn is round cropped + (let [;; image generated with `profile-picture-fn` is round cropped ;; no need to add border-radius for them outer-styles (style/outer size (not (:fn profile-picture))) ;; Once image is loaded, fast image re-renders view with the help of reagent atom, @@ -108,4 +110,6 @@ :else {:uri profile-picture})}])])) -(def user-avatar (quo.theme/with-theme user-avatar-internal)) +(def user-avatar + (quo.theme/with-theme + (schema/instrument #'user-avatar-internal component-schema/?schema)))