{ "name": "avatar", "type": "registry:ui", "title": "Avatar", "description": "A user or entity's profile image with a text fallback.", "dependencies": [ "@base-ui/react@^1.8.0", "cn@^0.3.0", "lucide-react@^1.46.0" ], "registryDependencies": [ "https://raw.githubusercontent.com/wunder-ui/wunderui/main/r/styles.json" ], "files": [ { "path": "components/ui/avatar.tsx", "type": "registry:ui", "target": "components/ui/avatar.tsx", "content": "\"use client\"\n\nimport * as React from \"react\"\nimport { Avatar as AvatarPrimitive } from \"@base-ui/react/avatar\"\nimport { Check, Moon } from \"lucide-react\"\nimport { cn } from \"@/lib/utils\"\nimport { opticalCenter } from \"@/lib/optical-center\"\n\n/** Tinted initials — mirrors the Figma Avatar \"Style=_primary\" variants\n * (tint/ background + tint-text/ text, both mode-aware tokens). */\ntype AvatarColor =\n | \"indigo\"\n | \"blue\"\n | \"purple\"\n | \"pink\"\n | \"red\"\n | \"orange\"\n | \"yellow\"\n | \"green\"\n | \"alternative\"\n | \"grey\"\n\ntype AvatarBadgeStatus = \"available\" | \"busy\" | \"away\" | \"dnd\" | \"offline\" | \"unknown\"\n\nconst AVATAR_COLOR_CLASSES: Record = {\n indigo: \"bg-tint-indigo text-tint-text-indigo\",\n blue: \"bg-tint-blue text-tint-text-blue\",\n purple: \"bg-tint-purple text-tint-text-purple\",\n pink: \"bg-tint-pink text-tint-text-pink\",\n red: \"bg-tint-red text-tint-text-red\",\n orange: \"bg-tint-orange text-tint-text-orange\",\n yellow: \"bg-tint-yellow text-tint-text-yellow\",\n green: \"bg-tint-green text-tint-text-green\",\n alternative: \"bg-tint-alternative text-tint-text-alternative\",\n grey: \"bg-muted text-text-secondary\",\n}\n\n// Owner rule (Oct 31 2026): the indicator sits top right with its centre on\n// the corner of the shape. Circle of size s: centre at (0.854 s, 0.146 s).\n// Rounded square of radius r: centre at (s - 0.293 r, 0.293 r). --badge-d is the dot size.\nconst BADGE_POSITION = \"absolute top-[calc(14.645%-var(--badge-d)/2)] right-[calc(14.645%-var(--badge-d)/2)] z-10 inline-flex size-(--badge-d) items-center justify-center rounded-full bg-primary text-primary-foreground bg-blend-color ring-[1.5px] ring-(--surface) select-none [--badge-d:--spacing(2)] group-data-[shape=square]/avatar:top-[calc(var(--radius-md)*0.293-var(--badge-d)/2)] group-data-[shape=square]/avatar:right-[calc(var(--radius-md)*0.293-var(--badge-d)/2)]\"\n\nconst STATUS_SHAPES: Record = {\n available: ,\n busy: (\n \n ),\n dnd: (\n \n ),\n away: (\n \n \n \n ),\n offline: null,\n unknown: null,\n}\n\nconst STATUS_LABELS: Record = {\n available: \"Available\",\n busy: \"Busy\",\n away: \"Away\",\n dnd: \"Do not disturb\",\n offline: \"Offline\",\n unknown: \"Status unknown\",\n}\n\nfunction Avatar({\n className,\n size = \"default\",\n shape = \"circle\",\n variant = \"plain\",\n color,\n interactive,\n selected,\n disabled,\n render,\n children,\n ...props\n}: AvatarPrimitive.Root.Props & {\n /** Figma Avatar sizes: sm = 24px (2xs), xs = 28px, default = 36px (small), lg = 40px (medium), xl = 44px (large) */\n size?: \"sm\" | \"xs\" | \"default\" | \"lg\" | \"xl\"\n shape?: \"circle\" | \"square\"\n variant?: \"plain\" | \"primary\"\n /** Soft tint for initials avatars; ignored when an image renders. */\n color?: AvatarColor\n interactive?: boolean\n selected?: boolean\n disabled?: boolean\n}) {\n return (\n : render}\n className={cn(\n \"group/avatar relative flex size-9 shrink-0 select-none after:absolute after:inset-0 after:border after:border-border-control after:mix-blend-darken dark:after:mix-blend-lighten\",\n \"data-[shape=circle]:rounded-full data-[shape=circle]:after:rounded-full\",\n \"data-[shape=square]:rounded-md data-[shape=square]:after:rounded-md\",\n \"data-[size=sm]:size-6 data-[size=xs]:size-7 data-[size=lg]:size-10 data-[size=xl]:size-11\",\n // Figma keeps the glyph at 16 px and only shrinks it on the two small sizes.\n \"[&_svg]:size-4 data-[size=sm]:[&_svg]:size-3 data-[size=xs]:[&_svg]:size-3.5\",\n \"data-[variant=primary]:bg-primary data-[variant=primary]:text-primary-foreground data-[variant=primary]:after:border-transparent\",\n color && AVATAR_COLOR_CLASSES[color],\n color && \"after:border-transparent\",\n interactive && \"cursor-pointer focus-ring data-[interactive]:focus-visible:after:border-primary data-[interactive]:focus-visible:after:mix-blend-normal data-[interactive]:hover:ring-3 data-[interactive]:hover:ring-bg-page data-[interactive]:active:ring-3 data-[interactive]:active:ring-bg-subtle data-[interactive]:data-[disabled]:opacity-40 data-[interactive]:data-[disabled]:pointer-events-none data-[interactive]:data-[selected]:ring-3 data-[interactive]:data-[selected]:ring-bg-subtle\",\n className\n )}\n {...props}\n >\n {children}\n {selected && (\n svg]:size-2\",\n \"group-data-[size=xs]/avatar:[--badge-d:--spacing(3.5)] group-data-[size=xs]/avatar:[&>svg]:size-2.5\",\n \"group-data-[size=default]/avatar:[&>svg]:size-3\",\n \"group-data-[size=lg]/avatar:[&>svg]:size-3\",\n \"group-data-[size=xl]/avatar:[&>svg]:size-3\"\n )}\n >\n \n \n )}\n \n )\n}\n\nfunction AvatarImage({ className, ...props }: AvatarPrimitive.Image.Props) {\n return (\n \n )\n}\n\nfunction AvatarFallback({\n className,\n children,\n ...props\n}: AvatarPrimitive.Fallback.Props) {\n return (\n \n {/* Initials sit on the cap-height centre of the circle, not on the line-box centre. */}\n {opticalCenter(children)}\n \n )\n}\n\nfunction AvatarBadge({\n className,\n status,\n ...props\n}: React.ComponentProps<\"span\"> & {\n status?: AvatarBadgeStatus\n}) {\n if (status) {\n const { children: _children, ...rest } = props\n return (\n \n {STATUS_SHAPES[status]}\n \n )\n }\n\n return (\n svg]:hidden\",\n \"group-data-[size=xs]/avatar:[&>svg]:hidden\",\n \"group-data-[size=default]/avatar:[&>svg]:size-2\",\n \"group-data-[size=lg]/avatar:[--badge-d:--spacing(2.5)] group-data-[size=lg]/avatar:[&>svg]:size-2\",\n \"group-data-[size=xl]/avatar:[--badge-d:--spacing(3)] group-data-[size=xl]/avatar:[&>svg]:size-2\",\n className\n )}\n {...props}\n />\n )\n}\n\nfunction AvatarGroup({ className, children, layout = \"overlap\", ...props }: React.ComponentProps<\"div\"> & {\n layout?: \"overlap\" | \"spaced\"\n}) {\n const rootRef = React.useRef(null)\n\n // Distance-falloff hover lift: hovering one avatar lifts it and gently\n // lifts its neighbors, then everything snaps back with an overshoot spring\n // on mouseleave. The timing-function is set inline right before the\n // --avatar-shift/--avatar-scale writes so hover-in gets a clean ease and\n // the return gets the bouncy one, without a second class for \"leaving\".\n function setShifts(activeIndex: number | null, phase: \"in\" | \"out\") {\n const items = rootRef.current?.querySelectorAll(\"[data-avatar-hover-item]\")\n if (!items) return\n const timing = phase === \"out\" ? \"var(--ease-overshoot)\" : \"cubic-bezier(0.22, 1, 0.36, 1)\"\n items.forEach((el, index) => {\n el.style.transitionTimingFunction = timing\n if (activeIndex == null) {\n el.style.setProperty(\"--avatar-shift\", \"0px\")\n el.style.setProperty(\"--avatar-scale-active\", \"1\")\n return\n }\n const distance = Math.abs(index - activeIndex)\n el.style.setProperty(\"--avatar-shift\", `${(-4 * 0.45 ** distance).toFixed(3)}px`)\n el.style.setProperty(\"--avatar-scale-active\", index === activeIndex ? \"1.05\" : \"1\")\n })\n }\n\n return (\n setShifts(null, \"out\")}\n className={cn(\n \"group/avatar-group flex\",\n layout === \"overlap\"\n ? \"-space-x-3 [&_[data-slot=avatar]]:ring-2 [&_[data-slot=avatar]]:ring-(--surface)\"\n : \"gap-1.5\",\n className\n )}\n {...props}\n >\n {React.Children.map(children, (child, index) => (\n setShifts(index, \"in\")}\n className=\"origin-center transition-transform ease-entrance duration-slow will-change-transform [transform:translateY(var(--avatar-shift,0px))_scale(var(--avatar-scale-active,1))] motion-reduce:[transform:none] motion-reduce:transition-none\"\n >\n {child}\n \n ))}\n \n )\n}\n\nconst AVATAR_GROUP_COUNT_BASE_CLASSES =\n \"relative flex size-9 shrink-0 items-center justify-center rounded-full ring-2 ring-(--surface) group-has-data-[size=lg]/avatar-group:size-10 group-has-data-[size=xl]/avatar-group:size-11 group-has-data-[size=xs]/avatar-group:size-7 group-has-data-[size=sm]/avatar-group:size-6 [&>svg]:size-4 group-has-data-[size=lg]/avatar-group:[&>svg]:size-5 group-has-data-[size=sm]/avatar-group:[&>svg]:size-3\"\n\ntype AvatarGroupCountProps =\n | ({ interactive?: false } & React.ComponentProps<\"div\">)\n | ({ interactive: true } & React.ComponentProps<\"button\">)\n\nfunction AvatarGroupCount(props: AvatarGroupCountProps) {\n if (props.interactive) {\n const { interactive: _interactive, className, children, ...rest } = props\n return (\n \n {opticalCenter(children)}\n \n )\n }\n\n const { interactive: _interactive, className, children, ...rest } = props\n return (\n \n {opticalCenter(children)}\n \n )\n}\n\nexport type { AvatarColor, AvatarBadgeStatus }\nexport {\n Avatar,\n AvatarImage,\n AvatarFallback,\n AvatarGroup,\n AvatarGroupCount,\n AvatarBadge,\n}\n" }, { "path": "lib/optical-center.tsx", "type": "registry:lib", "target": "lib/optical-center.tsx", "content": "import * as React from \"react\"\n\nconst isText = (node: React.ReactNode): node is string | number => typeof node === \"string\" || typeof node === \"number\"\n\n/**\n * Puts the text of a circle, pill or badge on the cap-height centre (owner rule, 10 Nov 2026).\n *\n * A flex container centres the line box, and a line box is taller below the baseline than the cap height is\n * above it, so digits and capitals sit a little low. `optical-center` (line-height 1 and `text-box: trim-both\n * cap alphabetic`) shrinks the text to the cap height; it only works on a block of its own, so every run of\n * plain text inside the container is wrapped in a ``. Elements (icons,\n * nested components) are left alone, and so is `null`, `false` and an empty string.\n *\n * Runs of text are merged into one span, so `+{n}` (two text children) stays one flex item.\n */\nfunction opticalCenter(children: React.ReactNode): React.ReactNode {\n const nodes = React.Children.toArray(children)\n if (nodes.length === 0) return children\n const out: React.ReactNode[] = []\n let run: Array = []\n const flush = () => {\n if (run.length === 0) return\n out.push(\n \n {run}\n \n )\n run = []\n }\n for (const node of nodes) {\n if (isText(node)) run.push(node)\n else {\n flush()\n out.push(node)\n }\n }\n flush()\n return out\n}\n\nexport { opticalCenter }\n" }, { "path": "lib/utils.ts", "type": "registry:lib", "target": "lib/utils.ts", "content": "import type { CnFunction } from \"cn\"\nimport { createCn } from \"cn/config\"\n\n/**\n * clsx + tailwind-merge, taught WunderUI's own theme utilities so they merge\n * in the right group: `text-label-sm` is a font size (not a text colour, which\n * dropped it next to `text-text-tertiary`), `bg-gradient-*` a background image\n * (not a colour that `bg-card` would remove), and the motion utilities\n * `ease-entrance …` and `duration-fast …` replace each other.\n */\nexport const cn: CnFunction = createCn({\n extend: {\n classGroups: {\n \"font-size\": [{ text: [\"label-sm\", \"micro\"] }],\n \"bg-image\": [\n {\n bg: [\n \"gradient-primary\",\n \"gradient-indigo\",\n \"gradient-blue\",\n \"gradient-purple\",\n \"gradient-pink\",\n \"gradient-red\",\n \"gradient-orange\",\n \"gradient-yellow\",\n \"gradient-green\",\n \"gradient-alternative\",\n \"gradient-slate\",\n \"gradient-dark\",\n ],\n },\n ],\n ease: [{ ease: [\"entrance\", \"exit\", \"move\", \"overshoot\", \"spring\"] }],\n duration: [{ duration: [\"instant\", \"fast\", \"base\", \"slow\", \"deliberate\", \"ambient\"] }],\n },\n },\n})\n" } ], "docs": "https://wunderui.com/components/avatar", "meta": { "group": "Core Elements", "exports": [ "Avatar", "AvatarBadge", "AvatarBadgeStatus", "AvatarColor", "AvatarFallback", "AvatarImage" ] } }