From f6e554bab09e3198a375ef01ea1d263a56e9935c 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 Signed-off-by: yqrashawn --- .../avatars/user_avatar/schema.cljs | 23 +++++++++++++++++++ .../components/avatars/user_avatar/view.cljs | 8 +++++-- 2 files changed, 29 insertions(+), 2 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..147ae35eadd3 --- /dev/null +++ b/src/quo/components/avatars/user_avatar/schema.cljs @@ -0,0 +1,23 @@ +(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 {:optional true} [:maybe :schema.common/customization-color]] + [:static? {:optional true} [:maybe boolean?]] + [:status-indicator? {:optional true} [:maybe boolean?]] + [:online? {:optional true} [:maybe boolean?]] + [:ring? {:optional true} [:maybe boolean?]] + [:theme :schema.common/theme] + [:profile-picture + [:maybe + [:or + :schema.common/image-source + [: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..880357655be1 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 @@ -58,7 +60,7 @@ customization-color :blue} :as props}] (let [full-name (or full-name "Your Name") - ;; image generated with profile-picture-fn is round cropped + ;; 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)))