{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "avatar",
  "title": "Avatar",
  "description": "A face or initials that identifies a person at a glance, alone or as an overlapping group with a +N.",
  "dependencies": [
    "radix-ui",
    "motion"
  ],
  "registryDependencies": [
    "utils",
    "https://miseui.junsu4621.workers.dev/r/motion.json"
  ],
  "files": [
    {
      "path": "registry/miseui/ui/avatar.tsx",
      "content": "import type * as React from \"react\"\nimport { Children, createContext, useContext, useMemo, useState } from \"react\"\nimport { Avatar as AvatarPrimitive } from \"radix-ui\"\nimport { motion, useReducedMotion } from \"motion/react\"\nimport { SPRING_DEFAULT } from \"@/registry/miseui/lib/motion\"\nimport {\n  MARK_SIZE_CLASS,\n  OVERLAP_CLASS,\n  SHAPE_CLASS,\n  SIZE_CLASS,\n  SPREAD_PX,\n  STATUS_CLASS,\n  avatarTone,\n  getInitials,\n  type AvatarGroupEffect,\n  type AvatarSize,\n  type AvatarStatus,\n  type AvatarVariant,\n} from \"@/registry/miseui/ui/avatar-tokens\"\nimport { cn } from \"@/registry/miseui/lib/utils\"\n\ninterface AvatarGroupContextValue {\n  size: AvatarSize\n  variant: AvatarVariant\n}\n\nconst AvatarGroupContext = createContext<AvatarGroupContextValue | null>(null)\n\ninterface AvatarProps extends Omit<React.ComponentProps<\"span\">, \"children\"> {\n  /** Used for the accessible label, the initials and their colour. */\n  name: string\n  src?: string\n  size?: AvatarSize\n  /** `circle` for people, `rounded` for teams and products, `ring` for the current speaker, `status` for presence. */\n  variant?: AvatarVariant\n  /** `status` variant only. */\n  status?: AvatarStatus\n}\n\nfunction Avatar({ name, src, size, variant, status = \"online\", className, ...props }: AvatarProps) {\n  const group = useContext(AvatarGroupContext)\n  const resolvedSize = size ?? group?.size ?? \"md\"\n  const resolvedVariant = variant ?? group?.variant ?? \"circle\"\n  const showMark = resolvedVariant === \"status\"\n  return (\n    <span\n      role=\"img\"\n      aria-label={showMark ? `${name}, ${status}` : name}\n      data-slot=\"avatar\"\n      data-variant={resolvedVariant}\n      data-size={resolvedSize}\n      className={cn(\"relative inline-flex shrink-0 align-middle\", className)}\n      {...props}\n    >\n      <AvatarPrimitive.Root\n        className={cn(\n          \"inline-flex select-none items-center justify-center overflow-hidden font-medium\",\n          SIZE_CLASS[resolvedSize],\n          SHAPE_CLASS[resolvedVariant],\n          // The cut-out between overlapping faces; the ring variant already has its own offset.\n          group && resolvedVariant !== \"ring\" && \"ring-2 ring-background\",\n        )}\n      >\n        <AvatarPrimitive.Image data-slot=\"avatar-image\" src={src} alt=\"\" className=\"size-full object-cover\" />\n        <AvatarPrimitive.Fallback\n          data-slot=\"avatar-fallback\"\n          className={cn(\"flex size-full items-center justify-center\", avatarTone(name))}\n        >\n          {getInitials(name)}\n        </AvatarPrimitive.Fallback>\n      </AvatarPrimitive.Root>\n      {showMark && (\n        <span\n          data-slot=\"avatar-status\"\n          data-status={status}\n          className={cn(\n            \"absolute right-0 bottom-0 overflow-hidden rounded-full ring-2 ring-background\",\n            MARK_SIZE_CLASS[resolvedSize],\n            STATUS_CLASS[status],\n          )}\n        />\n      )}\n    </span>\n  )\n}\n\ninterface AvatarGroupProps extends React.ComponentProps<\"div\"> {\n  /** How many faces to show before the +N. */\n  max?: number\n  /** The real headcount when `children` is only a page of it. */\n  total?: number\n  size?: AvatarSize\n  variant?: AvatarVariant\n  /** `stack` spreads the faces apart on hover or focus, on a spring. */\n  effect?: AvatarGroupEffect\n}\n\n/** Parts on hover or on focus inside the group; the state only moves when the effect is on. */\nfunction useSpread(isOn: boolean) {\n  const [spread, setSpread] = useState(false)\n  if (!isOn) return { spread: false, handlers: {} }\n  return {\n    spread,\n    handlers: {\n      onPointerEnter: () => setSpread(true),\n      onPointerLeave: () => setSpread(false),\n      onFocus: () => setSpread(true),\n      onBlur: () => setSpread(false),\n    },\n  }\n}\n\nfunction groupCells(children: React.ReactNode, max: number, total: number | undefined, size: AvatarSize) {\n  const items = Children.toArray(children)\n  const shown = items.slice(0, Math.max(0, max))\n  const count = total ?? items.length\n  const extra = Math.max(0, count - shown.length)\n  return { count, cells: extra > 0 ? [...shown, <OverflowCount key=\"overflow\" extra={extra} size={size} />] : shown }\n}\n\nfunction AvatarGroup({\n  max = 4,\n  total,\n  size = \"md\",\n  variant = \"circle\",\n  effect,\n  className,\n  style,\n  children,\n  \"aria-label\": ariaLabel,\n  ...props\n}: AvatarGroupProps) {\n  const reduceMotion = useReducedMotion() ?? false\n  const isStack = effect === \"stack\"\n  const { spread, handlers } = useSpread(isStack)\n  const context = useMemo(() => ({ size, variant }), [size, variant])\n  const { cells, count } = groupCells(children, max, total, size)\n  return (\n    <AvatarGroupContext.Provider value={context}>\n      <div\n        role=\"group\"\n        aria-label={ariaLabel ?? `${count} people`}\n        data-slot=\"avatar-group\"\n        data-effect={effect}\n        data-spread={isStack ? String(spread) : undefined}\n        className={cn(\"inline-flex items-center\", className)}\n        // Transforms take no layout space, so the spread is reserved up front and never covers a neighbour.\n        style={isStack ? { paddingInlineEnd: (cells.length - 1) * SPREAD_PX, ...style } : style}\n        {...handlers}\n        {...props}\n      >\n        {cells.map((cell, index) => (\n          <motion.span\n            key={index}\n            className={cn(\"relative inline-flex\", index > 0 && OVERLAP_CLASS[size])}\n            style={{ zIndex: cells.length - index }}\n            initial={false}\n            animate={{ x: spread ? index * SPREAD_PX : 0 }}\n            transition={reduceMotion ? { duration: 0 } : SPRING_DEFAULT}\n          >\n            {cell}\n          </motion.span>\n        ))}\n      </div>\n    </AvatarGroupContext.Provider>\n  )\n}\n\nfunction OverflowCount({ extra, size }: { extra: number; size: AvatarSize }) {\n  return (\n    <span\n      role=\"img\"\n      aria-label={`${extra} more`}\n      data-slot=\"avatar-overflow\"\n      className={cn(\n        \"inline-flex items-center justify-center rounded-full bg-muted font-medium text-muted-foreground tabular-nums ring-2 ring-background\",\n        SIZE_CLASS[size],\n      )}\n    >\n      +{extra}\n    </span>\n  )\n}\n\nexport {\n  Avatar,\n  AvatarGroup,\n  avatarTone,\n  getInitials,\n  type AvatarProps,\n  type AvatarGroupProps,\n  type AvatarVariant,\n  type AvatarSize,\n  type AvatarStatus,\n  type AvatarGroupEffect,\n}\n",
      "type": "registry:ui"
    },
    {
      "path": "registry/miseui/ui/avatar-tokens.ts",
      "content": "export type AvatarVariant = \"circle\" | \"rounded\" | \"ring\" | \"status\"\nexport type AvatarSize = \"sm\" | \"md\" | \"lg\"\nexport type AvatarStatus = \"online\" | \"away\" | \"busy\" | \"offline\"\nexport type AvatarGroupEffect = \"stack\"\n\nexport const SIZE_CLASS: Record<AvatarSize, string> = {\n  sm: \"size-8 text-xs\",\n  md: \"size-10 text-sm\",\n  lg: \"size-12 text-[15px]\",\n}\n\nexport const SHAPE_CLASS: Record<AvatarVariant, string> = {\n  circle: \"rounded-full\",\n  rounded: \"rounded-lg\",\n  ring: \"rounded-full ring-2 ring-mise ring-offset-2 ring-offset-background\",\n  status: \"rounded-full\",\n}\n\n/** Pairs of theme tokens only, so initials stay legible in every palette and in dark mode. */\nconst TONES = [\n  \"bg-muted text-foreground\",\n  \"bg-mise-soft text-foreground\",\n  \"bg-mise/30 text-foreground\",\n  \"bg-foreground/10 text-foreground\",\n  \"bg-secondary text-secondary-foreground\",\n] as const\n\n/** Shape as well as colour, so presence survives colour blindness and every accent palette. */\nexport const STATUS_CLASS: Record<AvatarStatus, string> = {\n  online: \"bg-mise\",\n  away: \"border-2 border-mise bg-background\",\n  busy: \"bg-destructive after:absolute after:inset-x-[20%] after:top-1/2 after:h-0.5 after:-translate-y-1/2 after:bg-background\",\n  offline: \"border-2 border-muted-foreground/50 bg-background\",\n}\n\nexport const MARK_SIZE_CLASS: Record<AvatarSize, string> = { sm: \"size-2.5\", md: \"size-3\", lg: \"size-3.5\" }\nexport const OVERLAP_CLASS: Record<AvatarSize, string> = { sm: \"-ml-2\", md: \"-ml-2.5\", lg: \"-ml-3\" }\nexport const SPREAD_PX = 12\n\n/** Same name, same colour, on every render and every device. */\nexport function avatarTone(name: string): string {\n  const hash = Array.from(name).reduce((sum, char) => (sum * 31 + (char.codePointAt(0) ?? 0)) >>> 0, 7)\n  return TONES[hash % TONES.length]\n}\n\nexport function getInitials(name: string): string {\n  const parts = name.trim().split(/\\s+/).filter(Boolean)\n  if (parts.length === 0) return \"?\"\n  const first = Array.from(parts[0])[0]\n  const last = parts.length > 1 ? Array.from(parts[parts.length - 1])[0] : \"\"\n  return `${first}${last}`.toUpperCase()\n}\n",
      "type": "registry:ui"
    }
  ],
  "categories": [
    "display"
  ],
  "type": "registry:ui"
}