Skip to content

Commit

Permalink
chore(schema): for user-avatar component
Browse files Browse the repository at this point in the history
Signed-off-by: yqrashawn <namy.19@gmail.com>
  • Loading branch information
yqrashawn committed Feb 20, 2024
1 parent 424bbc3 commit fb8e724
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/quo/components/avatars/user_avatar/component_spec.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
(h/describe "Profile picture"
(h/test "Renders"
(h/render
[user-avatar/user-avatar {:profile-picture mock-picture}])
[user-avatar/user-avatar {:profile-picture mock-picture :theme :light}])
(h/is-truthy (h/get-by-label-text :profile-picture)))

(h/test "Renders even if `:full-name` is passed"
(h/render
[user-avatar/user-avatar {:profile-picture mock-picture}])
[user-avatar/user-avatar {:profile-picture mock-picture :theme :dark}])
(h/is-truthy (h/get-by-label-text :profile-picture)))))
23 changes: 23 additions & 0 deletions src/quo/components/avatars/user_avatar/schema.cljs
Original file line number Diff line number Diff line change
@@ -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])
8 changes: 6 additions & 2 deletions src/quo/components/avatars/user_avatar/view.cljs
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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)))

0 comments on commit fb8e724

Please sign in to comment.