Avatar
docs/avatarFreeComponent
avatar component for SolidJS
Live preview
live · rendered by the registry
Rendered by docs on their own page — this is the component running, not a screenshot of it.Install it
npx shadcn@latest add https://solidcn.dev/r/avatar.jsonSource
1import type { Component, JSX } from "solid-js";2import { Show, createSignal, splitProps } from "solid-js";3import { cn } from "~/lib/utils";45const Avatar: Component<JSX.HTMLAttributes<HTMLSpanElement>> = (props) => {6 const [local, rest] = splitProps(props, ["class"]);7 return (8 <span9 class={cn("relative flex h-10 w-10 shrink-0 overflow-hidden rounded-full", local.class)}10 {...rest}11 />12 );13};1415type AvatarImageProps = JSX.ImgHTMLAttributes<HTMLImageElement>;1617const AvatarImage: Component<AvatarImageProps> = (props) => {18 const [local, rest] = splitProps(props, ["class", "src", "alt", "onError"]);19 const [error, setError] = createSignal(false);2021 return (22 <Show when={!error()}>23 {/* biome-ignore lint/a11y/useAltText: alt forwarded via local.alt — callers provide meaningful text */}24 <img25 class={cn("aspect-square h-full w-full object-cover", local.class)}26 src={local.src}27 alt={local.alt ?? ""}28 onError={(e) => {29 setError(true);30 if (typeof local.onError === "function") {31 local.onError(e);32 }33 }}34 {...rest}35 />36 </Show>37 );38};3940const AvatarFallback: Component<JSX.HTMLAttributes<HTMLSpanElement>> = (props) => {41 const [local, rest] = splitProps(props, ["class"]);42 return (43 <span44 class={cn(45 "flex h-full w-full items-center justify-center rounded-full bg-muted text-sm font-medium",46 local.class,47 )}48 {...rest}49 />50 );51};5253export { Avatar, AvatarImage, AvatarFallback };
More from docs
All 44 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Accordionaccordion | docs | Components | Free | no deps | |
| Alert Dialogalert-dialog | docs | Components | Free | no deps | |
| Badgebadge | docs | Components | Free | no deps | |
| Breadcrumbbreadcrumb | docs | Components | Free | no deps | |
| Buttonbutton | docs | Components | Free | no deps | |
| Calendarcalendar | docs | Components | Free | no deps | |
| Cardcard | docs | Components | Free | no deps | |
| Carouselcarousel | docs | Components | Free | no deps |
