Avatar
solid-ui/avatarFreeComponent
An avatar component
Live preview
live · rendered by the registry
Rendered by solid-ui on their own page — this is the component running, not a screenshot of it.Install it
npx shadcn@latest add https://www.solid-ui.com/r/avatar.jsonSource
1import type { ValidComponent } from "solid-js"2import { splitProps } from "solid-js"34import * as ImagePrimitive from "@kobalte/core/image"5import type { PolymorphicProps } from "@kobalte/core/polymorphic"67import { cn } from "~/lib/utils"89type AvatarRootProps<T extends ValidComponent = "span"> = ImagePrimitive.ImageRootProps<T> & {10 class?: string | undefined11}1213const Avatar = <T extends ValidComponent = "span">(14 props: PolymorphicProps<T, AvatarRootProps<T>>15) => {16 const [local, others] = splitProps(props as AvatarRootProps, ["class"])17 return (18 <ImagePrimitive.Root19 class={cn("relative flex size-10 shrink-0 overflow-hidden rounded-full", local.class)}20 {...others}21 />22 )23}2425type AvatarImageProps<T extends ValidComponent = "img"> = ImagePrimitive.ImageImgProps<T> & {26 class?: string | undefined27}2829const AvatarImage = <T extends ValidComponent = "img">(30 props: PolymorphicProps<T, AvatarImageProps<T>>31) => {32 const [local, others] = splitProps(props as AvatarImageProps, ["class"])33 return <ImagePrimitive.Img class={cn("aspect-square size-full", local.class)} {...others} />34}3536type AvatarFallbackProps<T extends ValidComponent = "span"> =37 ImagePrimitive.ImageFallbackProps<T> & { class?: string | undefined }3839const AvatarFallback = <T extends ValidComponent = "span">(40 props: PolymorphicProps<T, AvatarFallbackProps<T>>41) => {42 const [local, others] = splitProps(props as AvatarFallbackProps, ["class"])43 return (44 <ImagePrimitive.Fallback45 class={cn("flex size-full items-center justify-center bg-muted", local.class)}46 {...others}47 />48 )49}5051export { Avatar, AvatarImage, AvatarFallback }
What it pulls in
npm packages
Files it writes
More from solid-ui
All 55 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Accordionaccordion | solid-ui | Components | Free | 2 deps | |
| Alertalert | solid-ui | Components | Free | 3 deps | |
| Alert Dialogalert-dialog | solid-ui | Components | Free | 2 deps | |
| Aspect Ratioaspect-ratio | solid-ui | Components | Free | 1 dep | |
| Badgebadge | solid-ui | Components | Free | 2 deps | |
| Badge Deltabadge-delta | solid-ui | Components | Free | 2 deps | |
| Bar Listbar-list | solid-ui | Components | Free | 1 dep | |
| Breadcrumbbreadcrumb | solid-ui | Components | Free | 2 deps |
