@mortenbrudvik/waveui 0.11.0 → 0.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +157 -13
- package/dist/components/button/Link.cjs +1 -1
- package/dist/components/button/Link.cjs.map +1 -1
- package/dist/components/button/Link.mjs +4 -4
- package/dist/components/data-display/Avatar.cjs +1 -1
- package/dist/components/data-display/Avatar.cjs.map +1 -1
- package/dist/components/data-display/Avatar.colors.cjs +2 -0
- package/dist/components/data-display/Avatar.colors.cjs.map +1 -0
- package/dist/components/data-display/Avatar.colors.mjs +45 -0
- package/dist/components/data-display/Avatar.colors.mjs.map +1 -0
- package/dist/components/data-display/Avatar.context.cjs +1 -1
- package/dist/components/data-display/Avatar.context.cjs.map +1 -1
- package/dist/components/data-display/Avatar.context.mjs +4 -2
- package/dist/components/data-display/Avatar.context.mjs.map +1 -1
- package/dist/components/data-display/Avatar.mjs +103 -96
- package/dist/components/data-display/Avatar.mjs.map +1 -1
- package/dist/components/data-display/Avatar.sizes.cjs +2 -0
- package/dist/components/data-display/Avatar.sizes.cjs.map +1 -0
- package/dist/components/data-display/Avatar.sizes.mjs +41 -0
- package/dist/components/data-display/Avatar.sizes.mjs.map +1 -0
- package/dist/components/data-display/AvatarGroup.cjs +1 -1
- package/dist/components/data-display/AvatarGroup.cjs.map +1 -1
- package/dist/components/data-display/AvatarGroup.context.cjs +2 -0
- package/dist/components/data-display/AvatarGroup.context.cjs.map +1 -0
- package/dist/components/data-display/AvatarGroup.context.mjs +9 -0
- package/dist/components/data-display/AvatarGroup.context.mjs.map +1 -0
- package/dist/components/data-display/AvatarGroup.mjs +65 -122
- package/dist/components/data-display/AvatarGroup.mjs.map +1 -1
- package/dist/components/data-display/AvatarGroup.partition.cjs +2 -0
- package/dist/components/data-display/AvatarGroup.partition.cjs.map +1 -0
- package/dist/components/data-display/AvatarGroup.partition.mjs +14 -0
- package/dist/components/data-display/AvatarGroup.partition.mjs.map +1 -0
- package/dist/components/data-display/AvatarGroup.parts.cjs +2 -0
- package/dist/components/data-display/AvatarGroup.parts.cjs.map +1 -0
- package/dist/components/data-display/AvatarGroup.parts.mjs +178 -0
- package/dist/components/data-display/AvatarGroup.parts.mjs.map +1 -0
- package/dist/components/data-display/InfoButton.cjs +1 -1
- package/dist/components/data-display/InfoButton.cjs.map +1 -1
- package/dist/components/data-display/InfoButton.mjs +12 -12
- package/dist/components/data-display/InteractionTag.cjs +1 -1
- package/dist/components/data-display/InteractionTag.cjs.map +1 -1
- package/dist/components/data-display/InteractionTag.mjs +36 -33
- package/dist/components/data-display/InteractionTag.mjs.map +1 -1
- package/dist/components/data-display/Persona.cjs +1 -1
- package/dist/components/data-display/Persona.cjs.map +1 -1
- package/dist/components/data-display/Persona.mjs +96 -37
- package/dist/components/data-display/Persona.mjs.map +1 -1
- package/dist/components/data-display/PresenceBadge.cjs +1 -1
- package/dist/components/data-display/PresenceBadge.cjs.map +1 -1
- package/dist/components/data-display/PresenceBadge.mjs +42 -28
- package/dist/components/data-display/PresenceBadge.mjs.map +1 -1
- package/dist/components/data-display/Tag.cjs +1 -1
- package/dist/components/data-display/Tag.cjs.map +1 -1
- package/dist/components/data-display/Tag.mjs +111 -108
- package/dist/components/data-display/Tag.mjs.map +1 -1
- package/dist/components/feedback/Toaster.cjs +1 -1
- package/dist/components/feedback/Toaster.cjs.map +1 -1
- package/dist/components/feedback/Toaster.mjs +235 -235
- package/dist/components/feedback/Toaster.mjs.map +1 -1
- package/dist/components/input/Combobox.cjs +1 -1
- package/dist/components/input/Combobox.cjs.map +1 -1
- package/dist/components/input/Combobox.mjs +176 -175
- package/dist/components/input/Combobox.mjs.map +1 -1
- package/dist/components/input/DatePicker.cjs +1 -1
- package/dist/components/input/DatePicker.cjs.map +1 -1
- package/dist/components/input/DatePicker.mjs +188 -187
- package/dist/components/input/DatePicker.mjs.map +1 -1
- package/dist/components/input/Dropdown.cjs +1 -1
- package/dist/components/input/Dropdown.cjs.map +1 -1
- package/dist/components/input/Dropdown.mjs +41 -40
- package/dist/components/input/Dropdown.mjs.map +1 -1
- package/dist/components/input/Option.cjs +1 -1
- package/dist/components/input/Option.cjs.map +1 -1
- package/dist/components/input/Option.mjs +89 -87
- package/dist/components/input/Option.mjs.map +1 -1
- package/dist/components/input/TagPicker.root.cjs +1 -1
- package/dist/components/input/TagPicker.root.cjs.map +1 -1
- package/dist/components/input/TagPicker.root.mjs +136 -135
- package/dist/components/input/TagPicker.root.mjs.map +1 -1
- package/dist/components/input/TimePicker.cjs +1 -1
- package/dist/components/input/TimePicker.cjs.map +1 -1
- package/dist/components/input/TimePicker.mjs +156 -154
- package/dist/components/input/TimePicker.mjs.map +1 -1
- package/dist/components/layout/Card.cjs +1 -1
- package/dist/components/layout/Card.cjs.map +1 -1
- package/dist/components/layout/Card.context.cjs +2 -0
- package/dist/components/layout/Card.context.cjs.map +1 -0
- package/dist/components/layout/Card.context.mjs +14 -0
- package/dist/components/layout/Card.context.mjs.map +1 -0
- package/dist/components/layout/Card.mjs +138 -92
- package/dist/components/layout/Card.mjs.map +1 -1
- package/dist/components/layout/Card.preview.cjs +2 -0
- package/dist/components/layout/Card.preview.cjs.map +1 -0
- package/dist/components/layout/Card.preview.mjs +22 -0
- package/dist/components/layout/Card.preview.mjs.map +1 -0
- package/dist/components/layout/Carousel.button.cjs +2 -0
- package/dist/components/layout/Carousel.button.cjs.map +1 -0
- package/dist/components/layout/Carousel.button.mjs +34 -0
- package/dist/components/layout/Carousel.button.mjs.map +1 -0
- package/dist/components/layout/Carousel.cjs +1 -1
- package/dist/components/layout/Carousel.cjs.map +1 -1
- package/dist/components/layout/Carousel.context.cjs +2 -0
- package/dist/components/layout/Carousel.context.cjs.map +1 -0
- package/dist/components/layout/Carousel.context.mjs +24 -0
- package/dist/components/layout/Carousel.context.mjs.map +1 -0
- package/dist/components/layout/Carousel.drag.cjs +2 -0
- package/dist/components/layout/Carousel.drag.cjs.map +1 -0
- package/dist/components/layout/Carousel.drag.mjs +79 -0
- package/dist/components/layout/Carousel.drag.mjs.map +1 -0
- package/dist/components/layout/Carousel.groups.cjs +2 -0
- package/dist/components/layout/Carousel.groups.cjs.map +1 -0
- package/dist/components/layout/Carousel.groups.mjs +23 -0
- package/dist/components/layout/Carousel.groups.mjs.map +1 -0
- package/dist/components/layout/Carousel.mjs +288 -150
- package/dist/components/layout/Carousel.mjs.map +1 -1
- package/dist/components/layout/Carousel.styles.cjs +2 -0
- package/dist/components/layout/Carousel.styles.cjs.map +1 -0
- package/dist/components/layout/Carousel.styles.mjs +30 -0
- package/dist/components/layout/Carousel.styles.mjs.map +1 -0
- package/dist/components/layout/TabList.cjs +1 -1
- package/dist/components/layout/TabList.cjs.map +1 -1
- package/dist/components/layout/TabList.mjs +163 -124
- package/dist/components/layout/TabList.mjs.map +1 -1
- package/dist/components/navigation/Menu.popover.cjs +1 -1
- package/dist/components/navigation/Menu.popover.cjs.map +1 -1
- package/dist/components/navigation/Menu.popover.mjs +137 -127
- package/dist/components/navigation/Menu.popover.mjs.map +1 -1
- package/dist/components/navigation/Menu.root.cjs +1 -1
- package/dist/components/navigation/Menu.root.cjs.map +1 -1
- package/dist/components/navigation/Menu.root.mjs +4 -4
- package/dist/components/overlays/Dialog.cjs +1 -1
- package/dist/components/overlays/Dialog.cjs.map +1 -1
- package/dist/components/overlays/Dialog.mjs +123 -123
- package/dist/components/overlays/Dialog.mjs.map +1 -1
- package/dist/components/overlays/Drawer.panel.cjs +1 -1
- package/dist/components/overlays/Drawer.panel.cjs.map +1 -1
- package/dist/components/overlays/Drawer.panel.mjs +12 -12
- package/dist/components/overlays/Drawer.panel.mjs.map +1 -1
- package/dist/components/overlays/Popover.cjs +1 -1
- package/dist/components/overlays/Popover.cjs.map +1 -1
- package/dist/components/overlays/Popover.mjs +173 -162
- package/dist/components/overlays/Popover.mjs.map +1 -1
- package/dist/components/overlays/TeachingPopover.cjs +1 -1
- package/dist/components/overlays/TeachingPopover.cjs.map +1 -1
- package/dist/components/overlays/TeachingPopover.mjs +96 -91
- package/dist/components/overlays/TeachingPopover.mjs.map +1 -1
- package/dist/components/overlays/Tooltip.cjs +1 -1
- package/dist/components/overlays/Tooltip.cjs.map +1 -1
- package/dist/components/overlays/Tooltip.mjs +47 -47
- package/dist/components/overlays/Tooltip.mjs.map +1 -1
- package/dist/components/portal/Portal.cjs +1 -1
- package/dist/components/portal/Portal.cjs.map +1 -1
- package/dist/components/portal/Portal.mjs +5 -5
- package/dist/components/table/DataGrid.cjs +1 -1
- package/dist/components/table/DataGrid.cjs.map +1 -1
- package/dist/components/table/DataGrid.mjs +1 -1
- package/dist/hooks/useDismiss.cjs.map +1 -1
- package/dist/hooks/useDismiss.mjs.map +1 -1
- package/dist/hooks/useFocusTrap.cjs.map +1 -1
- package/dist/hooks/useFocusTrap.mjs.map +1 -1
- package/dist/hooks/useFocusVisible.cjs +2 -0
- package/dist/hooks/useFocusVisible.cjs.map +1 -0
- package/dist/hooks/useFocusVisible.mjs +49 -0
- package/dist/hooks/useFocusVisible.mjs.map +1 -0
- package/dist/hooks/useFocusableGroup.cjs +2 -0
- package/dist/hooks/useFocusableGroup.cjs.map +1 -0
- package/dist/hooks/useFocusableGroup.mjs +70 -0
- package/dist/hooks/useFocusableGroup.mjs.map +1 -0
- package/dist/hooks/useModalLayer.cjs +1 -1
- package/dist/hooks/useModalLayer.cjs.map +1 -1
- package/dist/hooks/useModalLayer.mjs +4 -4
- package/dist/hooks/useModalOpen.cjs +2 -0
- package/dist/hooks/useModalOpen.cjs.map +1 -0
- package/dist/hooks/useModalOpen.mjs +14 -0
- package/dist/hooks/useModalOpen.mjs.map +1 -0
- package/dist/hooks/usePopupPosition.cjs +1 -1
- package/dist/hooks/usePopupPosition.cjs.map +1 -1
- package/dist/hooks/usePopupPosition.mjs +82 -53
- package/dist/hooks/usePopupPosition.mjs.map +1 -1
- package/dist/hooks/useResolvedTarget.cjs +2 -0
- package/dist/hooks/useResolvedTarget.cjs.map +1 -0
- package/dist/hooks/useResolvedTarget.mjs +37 -0
- package/dist/hooks/useResolvedTarget.mjs.map +1 -0
- package/dist/hooks/useRovingGrid.cjs +1 -1
- package/dist/hooks/useRovingGrid.cjs.map +1 -1
- package/dist/hooks/useRovingGrid.mjs +8 -57
- package/dist/hooks/useRovingGrid.mjs.map +1 -1
- package/dist/hooks/useRovingTabIndex.cjs +1 -1
- package/dist/hooks/useRovingTabIndex.cjs.map +1 -1
- package/dist/hooks/useRovingTabIndex.mjs +142 -107
- package/dist/hooks/useRovingTabIndex.mjs.map +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +1364 -66
- package/dist/index.d.ts +1364 -66
- package/dist/index.mjs +132 -115
- package/dist/lib/classNames.cjs +1 -1
- package/dist/lib/classNames.cjs.map +1 -1
- package/dist/lib/classNames.mjs +112 -92
- package/dist/lib/classNames.mjs.map +1 -1
- package/dist/lib/initials.cjs +2 -0
- package/dist/lib/initials.cjs.map +1 -0
- package/dist/lib/initials.mjs +21 -0
- package/dist/lib/initials.mjs.map +1 -0
- package/dist/lib/layers.cjs +1 -1
- package/dist/lib/layers.cjs.map +1 -1
- package/dist/lib/layers.mjs +112 -109
- package/dist/lib/layers.mjs.map +1 -1
- package/dist/styles.css +1 -1
- package/package.json +1 -1
- package/src/styles/tokens.css +102 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Avatar.mjs","names":["React","avatarSizeClasses","AVATAR_BOX_CLASSES","IMAGE_CLASS","getInitials","parts","name","normaliseName","readSlotProps","slot","getImageKey","imageSlot","src","element","slotProps","isPlainObject","value","proto","sameKeyPart","a","b","keys","k","sameImageKey","part","i","Avatar","sizeProp","ariaLabel","ariaLabelledBy","ariaDescribedBy","ariaDescription","ariaDetails","rest","box","AvatarSizeContext","image","imageKey","failed","setFailed","prevImageKey","setPrevImageKey","visualRef","img","active","checkedSrc","checkedSrcSet","markFailed","rootVisualRef","useMergedRefs","ref","hasConsumerName","roleCarriesName","role","normalisedName","imageAlt","decorative","handleError","ownAlt","hasOwnAlt","renderedAlt","description","imageIsNamed","imageDescription","imageNode","cn","avatarClassNames","overrides","composeEventHandlers","ownIds","joinIds","renderSlot","visualDescription","iconNode","icon","slotRendersContent","initials","content","colorClass","PersonIcon","imageName","slotAltName","label","a11yProps","badgeNode","badge","hasBadge","sizeClasses","visualClassName","className"],"sources":["../../../src/components/data-display/Avatar.tsx"],"sourcesContent":["import * as React from 'react';\nimport { joinIds } from '../../lib/aria';\nimport { cn } from '../../lib/cn';\nimport { avatarClassNames } from '../../lib/classNames';\nimport { composeEventHandlers } from '../../lib/composeEventHandlers';\nimport { useMergedRefs } from '../../hooks/useMergedRefs';\nimport { PersonIcon } from '../../lib/icons';\nimport type { Size, Slot } from '../../lib/types';\nimport { renderSlot, slotRendersContent } from '../../lib/slot';\nimport { AvatarSizeContext, type AvatarSizeContextValue } from './Avatar.context';\n\n/** Properties for the Avatar component. */\nexport interface AvatarProps extends React.HTMLAttributes<HTMLSpanElement> {\n /**\n * URL of the avatar image. When it fails to load (also before hydration, for server-rendered\n * markup), the avatar falls back to its icon or initials; a new `src` is tried again.\n */\n src?: string;\n /**\n * Full name of the person. It names the avatar for assistive technology (the image `alt`; in\n * initials and icon mode, or with a consumer `role`, the avatar's `aria-label`, with\n * `role=\"img\"` unless `role` is given) and generates the initials shown when there is no image.\n */\n name?: string;\n /**\n * Size of the avatar. Without it, an Avatar in the `media` of a tag (Tag, InteractionTag) takes\n * the tag's media box instead: 24, 20 or 16px by the tag's size.\n * @default 'medium'\n */\n size?: Size;\n /**\n * Icon shown instead of the initials when there is no image. Rendered in an `aria-hidden`\n * `<span>` (a slot object can override its attributes). A falsy value (`null`, `false`, `''`,\n * `0`, `NaN`, e.g. `icon={count && <Icon />}`) counts as no icon, as in 0.4, and so does an\n * array, `Set` or generator whose items render nothing. Without `icon` and without a usable\n * `name`, a generic person glyph is shown.\n */\n icon?: Slot<'span'>;\n /**\n * Custom image. Accepts a URL string (treated like `src`), an element (rendered as the image\n * itself, e.g. `<img>` or a framework image component) or an object of `<img>` attributes\n * (`{ src, alt, … }`). Takes precedence over `src`; its `alt` defaults to `name` (an `alt` that\n * is `undefined` counts as not given). When its alt names the avatar, the avatar's\n * `aria-describedby` ids are joined with the slot's own, while the slot's own `aria-description`\n * and `aria-details` win over the avatar's. When the image fails to load, an avatar without a\n * `name` keeps the name of the slot's own `alt`. After a load failure, a new image is tried\n * again: another `src` or `srcSet` of any type (an equal inline object is the same image), or\n * for an element slot another component type or `key`.\n */\n image?: Slot<'img'>;\n /**\n * Badge shown at the bottom end corner, e.g. `<PresenceBadge status=\"busy\" />`. With a badge\n * the avatar is wrapped in an outer `<span>` that receives `ref`, `className` and the other\n * props; `role`, `aria-label`, `aria-labelledby`, `aria-describedby`, `aria-description` and\n * `aria-details` stay on the avatar visual, so the badge keeps its own accessible name. A falsy\n * value (`null`, `false`, `''`, `0`, `NaN`, e.g. `badge={count && <CounterBadge count={count} />}`)\n * counts as no badge, as in 0.4, and so does an array, `Set` or generator whose items render\n * nothing: the avatar then renders without the wrapper.\n */\n badge?: Slot<'span'>;\n /**\n * Hides the avatar visual from assistive technology (`aria-hidden`, empty image `alt`, no\n * `role=\"img\"`). Use it when the name is already shown next to the avatar (Persona). A badge\n * stays exposed.\n * @default false\n */\n decorative?: boolean;\n /** Ref to the root `<span>`: the avatar itself, or the badge wrapper when `badge` is set. */\n ref?: React.Ref<HTMLSpanElement>;\n}\n\n/**\n * Width, height and text size classes of the avatar per `size`. Module-only (not in the barrel):\n * AvatarGroup sizes its overflow button with the same classes, so the two always match.\n */\nexport const avatarSizeClasses: Readonly<Record<Size, string>> = {\n 'extra-small': 'w-6 h-6 text-[10px]', // 24px\n small: 'w-8 h-8 text-xs', // 32px\n medium: 'w-10 h-10 text-sm', // 40px\n large: 'w-12 h-12 text-base', // 48px\n 'extra-large': 'w-14 h-14 text-lg', // 56px\n};\n\n/**\n * Width, height and text size classes of each box of {@link AvatarSizeContext}, for an Avatar\n * that sets no `size`: 24px is the `extra-small` size, 20px and 16px are internal boxes.\n */\nconst AVATAR_BOX_CLASSES: Readonly<Record<AvatarSizeContextValue['size'], string>> = {\n 24: avatarSizeClasses['extra-small'],\n 20: 'w-5 h-5 text-[10px]',\n 16: 'w-4 h-4 text-[10px]',\n};\n\nconst IMAGE_CLASS = 'w-full h-full object-cover';\n\n/** First letter of the first and last word, upper-cased; `''` for a blank name. */\nfunction 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\n/** A name with its whitespace collapsed, or `undefined` when it is blank. */\nfunction normaliseName(name: string | undefined): string | undefined {\n return name?.trim().replace(/\\s+/g, ' ') || undefined;\n}\n\ntype ImageErrorHandler = React.ReactEventHandler<HTMLImageElement>;\n\n/** Description props that go to the element carrying the avatar's name (data-display#19). */\ntype DescriptionProps = Pick<\n React.HTMLAttributes<HTMLElement>,\n 'aria-describedby' | 'aria-description' | 'aria-details'\n>;\n\n/** Props the avatar sets on an element or object image slot, over the slot's own. */\ninterface SlotOverrides {\n onError: ImageErrorHandler;\n alt?: string;\n 'aria-describedby'?: string;\n}\n\n/** The props of an element or object image slot that the avatar reads. */\ninterface ImageSlotProps {\n src?: unknown;\n srcSet?: unknown;\n alt?: unknown;\n onError?: unknown;\n 'aria-describedby'?: unknown;\n}\n\n/** The props of an element or object image slot (to read its `src`, `alt` and handlers). */\nfunction readSlotProps(slot: unknown): ImageSlotProps | undefined {\n if (React.isValidElement(slot)) return slot.props as ImageSlotProps;\n if (typeof slot === 'object' && slot !== null && !(Symbol.iterator in slot)) {\n return slot as ImageSlotProps;\n }\n return undefined;\n}\n\n/**\n * What identifies the image, so a load failure is kept for it and a new image is tried again\n * (data-display#4): the `src` and `srcSet`, of any type (a framework image component may take a\n * static-import object), and for an element slot also its type and `key`.\n */\ntype ImageKey = readonly [type: unknown, key: unknown, src: unknown, srcSet: unknown];\n\nfunction getImageKey(\n imageSlot: unknown,\n slotProps: ImageSlotProps | undefined,\n src: string | undefined,\n): ImageKey {\n if (imageSlot === undefined) return [undefined, undefined, src || undefined, undefined];\n if (typeof imageSlot === 'string') return [undefined, undefined, imageSlot, undefined];\n const element = React.isValidElement(imageSlot) ? imageSlot : undefined;\n return [element?.type, element?.key, slotProps?.src, slotProps?.srcSet];\n}\n\nfunction isPlainObject(value: unknown): value is Record<string, unknown> {\n if (typeof value !== 'object' || value === null) return false;\n const proto: unknown = Object.getPrototypeOf(value);\n return proto === Object.prototype || proto === null;\n}\n\n/** Same value, or plain objects with the same entries (an inline `src={{ … }}` on each render). */\nfunction sameKeyPart(a: unknown, b: unknown): boolean {\n if (Object.is(a, b)) return true;\n if (!isPlainObject(a) || !isPlainObject(b)) return false;\n const keys = Object.keys(a);\n return (\n keys.length === Object.keys(b).length &&\n keys.every((k) => Object.prototype.hasOwnProperty.call(b, k) && Object.is(a[k], b[k]))\n );\n}\n\nfunction sameImageKey(a: ImageKey, b: ImageKey): boolean {\n return a.every((part, i) => sameKeyPart(part, b[i]));\n}\n\n/**\n * A circular picture of a person: their image, an icon, or the initials of their `name`.\n *\n * - **Image**: `image` (URL string, element or `{ src, alt }` object) or `src`. If the image fails\n * to load, the avatar falls back to `icon`, the initials or a person glyph, with their\n * background; a new image is tried again. A server-rendered image that failed before hydration\n * is detected after mount (settled without a natural size, confirmed by `decode()`).\n * - **Accessible name**: an image uses `name` (whitespace collapsed) as its `alt`, or `''` when the\n * name is blank. Without an image (none given, or it failed to load) the avatar is `role=\"img\"`\n * with `aria-label={name}` (without a name: the image slot's own `alt`) and the initials/icon\n * are hidden; without either (and without `aria-label`/`aria-labelledby`) it is decorative\n * (`aria-hidden`). A consumer `aria-label`, `aria-labelledby` or `role` (other than\n * `presentation`/`none`) puts the name on the avatar visual, and an image inside it gets\n * `alt=\"\"`. `decorative` hides it in every mode. `aria-describedby`, `aria-description` and\n * `aria-details` go to the element that carries the name: the `<img>` when a non-blank `alt`\n * names it, otherwise the avatar visual (never an `alt=\"\"` image).\n * - **Badge**: `badge` renders at the bottom end corner (logical, RTL-safe) as a sibling of the\n * avatar visual, so a `PresenceBadge` keeps its own name. With a badge, `ref`, `className` and\n * the rest props go to the outer wrapper.\n *\n * @example\n * <Avatar name=\"Jane Doe\" src=\"/jane.jpg\" badge={<PresenceBadge status=\"available\" />} />\n */\nexport const Avatar = ({\n src,\n name,\n size: sizeProp,\n icon,\n image,\n badge,\n decorative = false,\n className,\n ref,\n role,\n 'aria-label': ariaLabel,\n 'aria-labelledby': ariaLabelledBy,\n 'aria-describedby': ariaDescribedBy,\n 'aria-description': ariaDescription,\n 'aria-details': ariaDetails,\n ...rest\n}: AvatarProps) => {\n // The media box of a surrounding Tag or InteractionTag, for an Avatar without its own `size`.\n const box = React.useContext(AvatarSizeContext);\n const imageSlot =\n image === null || image === undefined || typeof image === 'boolean' || image === ''\n ? undefined\n : image;\n const slotProps = readSlotProps(imageSlot);\n const imageKey = getImageKey(imageSlot, slotProps, src);\n\n // Load failure of the current image; a new image is tried again (C-HOOKS: adjust state during\n // render on prop change).\n const [failed, setFailed] = React.useState(false);\n const [prevImageKey, setPrevImageKey] = React.useState(imageKey);\n if (!sameImageKey(prevImageKey, imageKey)) {\n setPrevImageKey(imageKey);\n setFailed(false);\n }\n\n // An image that failed before hydration (a fast 404 of server-rendered markup) never reaches\n // `onError`: React attaches the listener while hydrating and does not replay the event. After\n // mount, a settled image without a natural size is broken, unless it is an SVG without one, so\n // `decode()` (which rejects for a broken image) confirms it where the browser supports it. Later\n // images, rendered by the client, report their errors through `onError`.\n const visualRef = React.useRef<HTMLSpanElement>(null);\n React.useLayoutEffect(() => {\n const img = visualRef.current?.querySelector('img');\n if (!img || !img.complete || img.naturalWidth !== 0) return;\n let active = true;\n const checkedSrc = img.getAttribute('src');\n const checkedSrcSet = img.getAttribute('srcset');\n const markFailed = () => {\n // Deferred (C-HOOKS); skipped if the image was replaced or got another source meanwhile.\n if (\n active &&\n img.isConnected &&\n img.getAttribute('src') === checkedSrc &&\n img.getAttribute('srcset') === checkedSrcSet\n ) {\n setFailed(true);\n }\n };\n if (typeof img.decode === 'function') img.decode().then(undefined, markFailed);\n else queueMicrotask(markFailed);\n return () => {\n active = false;\n };\n }, []);\n const rootVisualRef = useMergedRefs(ref, visualRef);\n\n const hasConsumerName = ariaLabel !== undefined || ariaLabelledBy !== undefined;\n // A consumer role goes to the visual span together with the name (data-display#19), so the\n // image inside it is presentational (`alt=\"\"`), as with a consumer `aria-label`: the children\n // of `role=\"img\"` are not exposed. A presentational role (`presentation`, `none`) cannot carry\n // a name, so the image keeps it.\n const roleCarriesName = role !== undefined && role !== 'presentation' && role !== 'none';\n const normalisedName = normaliseName(name);\n const imageAlt = decorative || hasConsumerName || roleCarriesName ? '' : (normalisedName ?? '');\n const handleError: ImageErrorHandler = () => setFailed(true);\n\n // The alt text the image renders with: an element or object slot's own `alt` wins over ours. An\n // `alt` that is `undefined` (an optional `alt: user.photoAlt`, a wrapper forwarding `alt={alt}`)\n // or `null` is not given, so ours applies (the slot's own value would otherwise override it).\n const ownAlt = slotProps?.alt;\n const hasOwnAlt = ownAlt !== undefined && ownAlt !== null;\n const renderedAlt: unknown = hasOwnAlt ? ownAlt : imageAlt;\n\n // The description goes to the element that carries the name: the image itself when a non-blank\n // `alt` names it (the visual span then has no role, or a presentational one), otherwise the\n // visual span. An image with an empty `alt` is presentational, and a description on it would\n // conflict with that role.\n const description: DescriptionProps = {\n 'aria-describedby': ariaDescribedBy,\n 'aria-description': ariaDescription,\n 'aria-details': ariaDetails,\n };\n const imageIsNamed =\n !decorative &&\n !hasConsumerName &&\n !roleCarriesName &&\n typeof renderedAlt === 'string' &&\n renderedAlt.trim() !== '';\n const imageDescription: DescriptionProps = imageIsNamed ? description : {};\n\n let imageNode: React.ReactNode = null;\n if (!failed) {\n if (typeof imageSlot === 'string') {\n imageNode = (\n <img\n src={imageSlot}\n alt={imageAlt}\n {...imageDescription}\n className={cn(avatarClassNames.image, IMAGE_CLASS)}\n onError={handleError}\n />\n );\n } else if (imageSlot !== undefined) {\n // The slot's own props win over renderSlot's defaults, so the composed `onError`, the\n // default `alt` (when the slot gives none) and the joined `aria-describedby` (the avatar's\n // ids, then the slot's) are set on the slot itself. A slot's own `aria-description` and\n // `aria-details` win over the avatar's.\n const overrides: SlotOverrides = {\n onError: composeEventHandlers(\n slotProps?.onError as ImageErrorHandler | undefined,\n handleError,\n ),\n };\n if (!hasOwnAlt) overrides.alt = imageAlt;\n if (imageIsNamed) {\n const ownIds = slotProps?.['aria-describedby'];\n overrides['aria-describedby'] = joinIds(\n ariaDescribedBy,\n typeof ownIds === 'string' ? ownIds : undefined,\n );\n }\n const slot = React.isValidElement(imageSlot)\n ? React.cloneElement(imageSlot as React.ReactElement<SlotOverrides>, overrides)\n : slotProps\n ? { ...(imageSlot as object), ...overrides }\n : imageSlot;\n imageNode = renderSlot(slot as Slot<'img'>, 'img', cn(avatarClassNames.image, IMAGE_CLASS), {\n alt: imageAlt,\n ...imageDescription,\n });\n } else if (src) {\n imageNode = (\n <img\n src={src}\n alt={imageAlt}\n {...imageDescription}\n className={cn(avatarClassNames.image, IMAGE_CLASS)}\n onError={handleError}\n />\n );\n }\n }\n const visualDescription = imageNode !== null && imageIsNamed ? {} : description;\n\n // A falsy icon (`icon={count && <Icon />}` with count 0) is no icon, as in 0.4, and so is a\n // collection whose items render nothing (`icon={items.map(…)}` mapping to nothing). The check\n // does not consume a generator: renderSlot still renders its items.\n const iconNode =\n imageNode === null && icon && slotRendersContent(icon)\n ? renderSlot(icon, 'span', cn(avatarClassNames.icon, 'inline-flex'), { 'aria-hidden': true })\n : null;\n const initials = imageNode === null && iconNode === null && name ? getInitials(name) : '';\n\n let content: React.ReactNode;\n let colorClass: string | undefined;\n if (imageNode !== null) {\n content = imageNode;\n } else if (iconNode !== null) {\n content = iconNode;\n colorClass = 'bg-muted text-muted-foreground';\n } else if (initials) {\n content = (\n <span aria-hidden=\"true\" className={avatarClassNames.initials}>\n {initials}\n </span>\n );\n colorClass = 'bg-primary text-primary-foreground';\n } else {\n content = <PersonIcon size=\"60%\" className={avatarClassNames.icon} />;\n colorClass = 'bg-muted text-muted-foreground';\n }\n\n // Accessible name of the avatar visual (data-display#19, #27). With a consumer role and an\n // image it is the name the image would carry: an element or object slot's own alt, else `name`.\n // Without an image (none given, or it failed to load) it is `name`, else the slot's own alt: an\n // avatar named only by its image alt keeps that name when the image fails.\n const imageName =\n imageNode !== null && roleCarriesName && typeof renderedAlt === 'string'\n ? normaliseName(renderedAlt)\n : undefined;\n const slotAltName = typeof ownAlt === 'string' ? normaliseName(ownAlt) : undefined;\n const label =\n ariaLabel ??\n (imageNode === null\n ? (normalisedName ?? slotAltName)\n : roleCarriesName\n ? (imageName ?? normalisedName)\n : undefined);\n let a11yProps: React.HTMLAttributes<HTMLSpanElement>;\n if (decorative) {\n a11yProps = { 'aria-hidden': true, ...visualDescription };\n } else if (label !== undefined || ariaLabelledBy !== undefined) {\n a11yProps = {\n role: role ?? 'img',\n 'aria-label': label,\n 'aria-labelledby': ariaLabelledBy,\n ...visualDescription,\n };\n } else if (imageNode !== null || role !== undefined) {\n a11yProps = { role, ...visualDescription };\n } else {\n a11yProps = { 'aria-hidden': true, ...visualDescription };\n }\n\n // A falsy or empty badge (`badge={count && <CounterBadge … />}` with count 0) is no badge, as in\n // 0.4 and like `icon`: no stray \"0\" in the corner, and no wrapper taking the root props.\n const badgeNode =\n badge && slotRendersContent(badge)\n ? renderSlot(badge, 'span', cn(avatarClassNames.badge, 'absolute bottom-0 end-0 inline-flex'))\n : null;\n const hasBadge = badgeNode !== null;\n\n // An own `size` wins; without one, the box of a surrounding tag's media, else medium. With a\n // badge the visual is sized, not the wrapper.\n const sizeClasses =\n sizeProp !== undefined\n ? avatarSizeClasses[sizeProp]\n : box\n ? AVATAR_BOX_CLASSES[box.size]\n : avatarSizeClasses.medium;\n const visualClassName = cn(\n avatarClassNames.visual,\n 'inline-flex items-center justify-center rounded-full overflow-hidden shrink-0 font-bold',\n sizeClasses,\n colorClass,\n );\n\n if (!hasBadge) {\n return (\n <span\n ref={rootVisualRef}\n {...a11yProps}\n {...rest}\n className={cn(avatarClassNames.root, visualClassName, className)}\n >\n {content}\n </span>\n );\n }\n\n return (\n <span\n ref={ref}\n {...rest}\n className={cn(avatarClassNames.root, 'relative inline-flex shrink-0', className)}\n >\n <span ref={visualRef} {...a11yProps} className={visualClassName}>\n {content}\n </span>\n {badgeNode}\n </span>\n );\n};\n\nAvatar.displayName = 'Avatar';\n"],"mappings":";;;;;;;;;;;;AA2EA,IAAaC,IAAoD;CAC/D,eAAe;CACf,OAAO;CACP,QAAQ;CACR,OAAO;CACP,eAAe;AACjB,GAMMC,KAA+E;CACnF,IAAID,EAAkB;CACtB,IAAI;CACJ,IAAI;AACN,GAEME,IAAc;AAGpB,SAASC,GAAY,GAAsB;CACzC,IAAMC,IAAQC,EAAK,KAAK,CAAC,CAAC,MAAM,KAAK,CAAC,CAAC,OAAO,OAAO;CAIrD,OAHID,EAAM,WAAW,IAAU,OACjB,MAAM,KAAKA,EAAM,EAAG,CAAC,CAAC,MAAM,OAC7BA,EAAM,SAAS,IAAK,MAAM,KAAKA,EAAMA,EAAM,SAAS,EAAG,CAAC,CAAC,MAAM,KAAM,IAAA,CAC5D,YAAY;AACpC;AAGA,SAASE,EAAc,GAA8C;CACnE,OAAOD,GAAM,KAAK,CAAC,CAAC,QAAQ,QAAQ,GAAG,KAAK,KAAA;AAC9C;AA2BA,SAASE,GAAc,GAA2C;CAChE,IAAIR,EAAM,eAAeS,CAAI,GAAG,OAAOA,EAAK;CAC5C,IAAI,OAAOA,KAAS,YAAYA,KAAiB,EAAE,OAAO,YAAYA,IACpE,OAAOA;AAGX;AASA,SAASC,GACP,GACA,GACA,GACU;CACV,IAAIC,MAAc,KAAA,GAAW,OAAO;EAAC,KAAA;EAAW,KAAA;EAAWC,KAAO,KAAA;EAAW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,GAAImC;EACJ,GAAIlD;EACJ,WAAWgC,EAAGC,EAAiB,MAAMsB,GAAiBC,CAAS;EAE9D,UAAAZ;CACG,CAAA;AAgBZ;AAEA,EAAO,cAAc"}
|
|
1
|
+
{"version":3,"file":"Avatar.mjs","names":["React","avatarBoxClasses","IMAGE_CLASS","activeClasses","normaliseName","name","readSlotProps","slot","getImageKey","imageSlot","src","element","slotProps","isPlainObject","value","proto","sameKeyPart","a","b","keys","k","sameImageKey","part","i","Avatar","sizeProp","shapeProp","colorProp","initialsSlot","ariaLabel","ariaLabelledBy","ariaDescribedBy","ariaDescription","ariaDetails","rest","box","AvatarSizeContext","image","imageKey","failed","setFailed","prevImageKey","setPrevImageKey","visualRef","img","active","checkedSrc","checkedSrcSet","markFailed","rootVisualRef","useMergedRefs","ref","hasConsumerName","roleCarriesName","role","normalisedName","imageAlt","decorative","handleError","ownAlt","hasOwnAlt","renderedAlt","description","imageIsNamed","imageDescription","imageNode","cn","avatarClassNames","overrides","composeEventHandlers","ownIds","joinIds","renderSlot","visualDescription","iconNode","icon","slotRendersContent","dir","useDirection","group","AvatarGroupContext","initialsClass","resolvedColor","resolveAvatarColor","idForColor","showsInitials","computedInitials","getInitials","initialsNode","content","colorClass","avatarColorClasses","PersonIcon","imageName","slotAltName","label","a11yProps","badgeNode","badge","hasBadge","resolvedSize","resolvedShape","pixels","avatarPixelSize","stateProps","activeAppearance","visualClassName","avatarShapeClasses","avatarSizeClassesFor","className","AvatarBadgeSizeContext","avatarBadgeSize"],"sources":["../../../src/components/data-display/Avatar.tsx"],"sourcesContent":["import * as React from 'react';\nimport { joinIds } from '../../lib/aria';\nimport { cn } from '../../lib/cn';\nimport { avatarClassNames } from '../../lib/classNames';\nimport { composeEventHandlers } from '../../lib/composeEventHandlers';\nimport { useMergedRefs } from '../../hooks/useMergedRefs';\nimport { useDirection } from '../../hooks/useDirection';\nimport { getInitials } from '../../lib/initials';\nimport { PersonIcon } from '../../lib/icons';\nimport type { Size, Slot } from '../../lib/types';\nimport { renderSlot, slotRendersContent } from '../../lib/slot';\nimport { AvatarBadgeSizeContext, AvatarSizeContext } from './Avatar.context';\nimport { AvatarGroupContext } from './AvatarGroup.context';\nimport { avatarColorClasses, resolveAvatarColor, type AvatarColor } from './Avatar.colors';\nimport {\n avatarBadgeSize,\n avatarBoxClasses,\n avatarPixelSize,\n avatarShapeClasses,\n avatarSizeClassesFor,\n type AvatarSize,\n} from './Avatar.sizes';\n\nexport type { AvatarNumericSize, AvatarSize } from './Avatar.sizes';\nexport type { AvatarColor, AvatarNamedColor } from './Avatar.colors';\n\n/** Properties for the Avatar component. */\nexport interface AvatarProps extends React.HTMLAttributes<HTMLSpanElement> {\n /**\n * URL of the avatar image. When it fails to load (also before hydration, for server-rendered\n * markup), the avatar falls back to its icon or initials; a new `src` is tried again.\n */\n src?: string;\n /**\n * Full name of the person. It names the avatar for assistive technology (the image `alt`; in\n * initials and icon mode, or with a consumer `role`, the avatar's `aria-label`, with\n * `role=\"img\"` unless `role` is given) and generates the initials shown when there is no image.\n */\n name?: string;\n /**\n * Size of the avatar: a named size (`extra-small` 24px to `extra-large` 56px) or a pixel size from\n * 16 to 128. Without it, an Avatar in the `media` of a tag (Tag, InteractionTag) takes the tag's\n * media box instead: 24, 20 or 16px by the tag's size.\n * @default 'medium'\n */\n size?: AvatarSize;\n /**\n * Shape of the avatar. Without it, an Avatar in the `media` of a rounded tag is square.\n * @default 'circular'\n */\n shape?: 'circular' | 'square';\n /**\n * Color of the avatar when it shows initials: `brand` (the primary color), `neutral` (muted),\n * `colorful` (one of the named colors, chosen from `idForColor`, else from `name`; `brand`\n * without either) or a named color of the persona palette. An image, or an icon, keeps its own\n * look.\n * @default 'brand'\n */\n color?: AvatarColor;\n /**\n * Whether the person is active: `active` draws the `activeAppearance` around the avatar, `inactive`\n * dims it, `unset` shows neither.\n * @default 'unset'\n */\n active?: 'active' | 'inactive' | 'unset';\n /**\n * How an `active` avatar is marked: a `ring`, a `shadow`, both (`ring-shadow`) or a `glow` in the\n * primary color.\n * @default 'ring'\n */\n activeAppearance?: 'ring' | 'ring-shadow' | 'shadow' | 'glow';\n /**\n * A stable id (a user id, say) that picks the color of `color=\"colorful\"`, so the same person has\n * the same color wherever they are shown, whatever their name looks like.\n */\n idForColor?: string;\n /**\n * The initials shown when there is no image and no icon, instead of the ones computed from\n * `name` (see `getInitials`): a string, an element or an object of `<span>` attributes. A value\n * that renders nothing (`''`, `[]`) keeps the computed initials. Rendered in an `aria-hidden`\n * `<span>`.\n */\n initials?: Slot<'span'>;\n /**\n * Icon shown instead of the initials when there is no image. Rendered in an `aria-hidden`\n * `<span>` (a slot object can override its attributes). A falsy value (`null`, `false`, `''`,\n * `0`, `NaN`, e.g. `icon={count && <Icon />}`) counts as no icon, as in 0.4, and so does an\n * array, `Set` or generator whose items render nothing. Without `icon` and without a usable\n * `name`, a generic person glyph is shown.\n */\n icon?: Slot<'span'>;\n /**\n * Custom image. Accepts a URL string (treated like `src`), an element (rendered as the image\n * itself, e.g. `<img>` or a framework image component) or an object of `<img>` attributes\n * (`{ src, alt, … }`). Takes precedence over `src`; its `alt` defaults to `name` (an `alt` that\n * is `undefined` counts as not given). When its alt names the avatar, the avatar's\n * `aria-describedby` ids are joined with the slot's own, while the slot's own `aria-description`\n * and `aria-details` win over the avatar's. When the image fails to load, an avatar without a\n * `name` keeps the name of the slot's own `alt`. After a load failure, a new image is tried\n * again: another `src` or `srcSet` of any type (an equal inline object is the same image), or\n * for an element slot another component type or `key`.\n */\n image?: Slot<'img'>;\n /**\n * Badge shown at the bottom end corner, e.g. `<PresenceBadge status=\"busy\" />`. With a badge\n * the avatar is wrapped in an outer `<span>` that receives `ref`, `className` and the other\n * props; `role`, `aria-label`, `aria-labelledby`, `aria-describedby`, `aria-description` and\n * `aria-details` stay on the avatar visual, so the badge keeps its own accessible name. A falsy\n * value (`null`, `false`, `''`, `0`, `NaN`, e.g. `badge={count && <CounterBadge count={count} />}`)\n * counts as no badge, as in 0.4, and so does an array, `Set` or generator whose items render\n * nothing: the avatar then renders without the wrapper.\n */\n badge?: Slot<'span'>;\n /**\n * Hides the avatar visual from assistive technology (`aria-hidden`, empty image `alt`, no\n * `role=\"img\"`). Use it when the name is already shown next to the avatar (Persona). A badge\n * stays exposed.\n * @default false\n */\n decorative?: boolean;\n /** Ref to the root `<span>`: the avatar itself, or the badge wrapper when `badge` is set. */\n ref?: React.Ref<HTMLSpanElement>;\n}\n\n/**\n * Width, height and text size classes of the avatar per `size`. Module-only (not in the barrel):\n * AvatarGroup sizes its overflow button with the same classes, so the two always match.\n */\nexport const avatarSizeClasses: Readonly<Record<Size, string>> = {\n 'extra-small': avatarBoxClasses[24],\n small: avatarBoxClasses[32],\n medium: avatarBoxClasses[40],\n large: avatarBoxClasses[48],\n 'extra-large': avatarBoxClasses[56],\n};\n\nconst IMAGE_CLASS = 'w-full h-full object-cover';\n\n/** How an `active` avatar is marked. Literal strings only. */\nconst activeClasses: Readonly<Record<'ring' | 'ring-shadow' | 'shadow' | 'glow', string>> = {\n ring: 'ring-2 ring-primary ring-offset-2 ring-offset-background',\n 'ring-shadow': 'ring-2 ring-primary ring-offset-2 ring-offset-background shadow-8',\n shadow: 'shadow-8',\n glow: 'shadow-[0_0_0.5rem_0.125rem_var(--wave-primary)]',\n};\n\n/** A name with its whitespace collapsed, or `undefined` when it is blank. */\nfunction normaliseName(name: string | undefined): string | undefined {\n return name?.trim().replace(/\\s+/g, ' ') || undefined;\n}\n\ntype ImageErrorHandler = React.ReactEventHandler<HTMLImageElement>;\n\n/** Description props that go to the element carrying the avatar's name (data-display#19). */\ntype DescriptionProps = Pick<\n React.HTMLAttributes<HTMLElement>,\n 'aria-describedby' | 'aria-description' | 'aria-details'\n>;\n\n/** Props the avatar sets on an element or object image slot, over the slot's own. */\ninterface SlotOverrides {\n onError: ImageErrorHandler;\n alt?: string;\n 'aria-describedby'?: string;\n}\n\n/** The props of an element or object image slot that the avatar reads. */\ninterface ImageSlotProps {\n src?: unknown;\n srcSet?: unknown;\n alt?: unknown;\n onError?: unknown;\n 'aria-describedby'?: unknown;\n}\n\n/** The props of an element or object image slot (to read its `src`, `alt` and handlers). */\nfunction readSlotProps(slot: unknown): ImageSlotProps | undefined {\n if (React.isValidElement(slot)) return slot.props as ImageSlotProps;\n if (typeof slot === 'object' && slot !== null && !(Symbol.iterator in slot)) {\n return slot as ImageSlotProps;\n }\n return undefined;\n}\n\n/**\n * What identifies the image, so a load failure is kept for it and a new image is tried again\n * (data-display#4): the `src` and `srcSet`, of any type (a framework image component may take a\n * static-import object), and for an element slot also its type and `key`.\n */\ntype ImageKey = readonly [type: unknown, key: unknown, src: unknown, srcSet: unknown];\n\nfunction getImageKey(\n imageSlot: unknown,\n slotProps: ImageSlotProps | undefined,\n src: string | undefined,\n): ImageKey {\n if (imageSlot === undefined) return [undefined, undefined, src || undefined, undefined];\n if (typeof imageSlot === 'string') return [undefined, undefined, imageSlot, undefined];\n const element = React.isValidElement(imageSlot) ? imageSlot : undefined;\n return [element?.type, element?.key, slotProps?.src, slotProps?.srcSet];\n}\n\nfunction isPlainObject(value: unknown): value is Record<string, unknown> {\n if (typeof value !== 'object' || value === null) return false;\n const proto: unknown = Object.getPrototypeOf(value);\n return proto === Object.prototype || proto === null;\n}\n\n/** Same value, or plain objects with the same entries (an inline `src={{ … }}` on each render). */\nfunction sameKeyPart(a: unknown, b: unknown): boolean {\n if (Object.is(a, b)) return true;\n if (!isPlainObject(a) || !isPlainObject(b)) return false;\n const keys = Object.keys(a);\n return (\n keys.length === Object.keys(b).length &&\n keys.every((k) => Object.prototype.hasOwnProperty.call(b, k) && Object.is(a[k], b[k]))\n );\n}\n\nfunction sameImageKey(a: ImageKey, b: ImageKey): boolean {\n return a.every((part, i) => sameKeyPart(part, b[i]));\n}\n\n/**\n * A circular picture of a person: their image, an icon, or the initials of their `name`.\n *\n * - **Image**: `image` (URL string, element or `{ src, alt }` object) or `src`. If the image fails\n * to load, the avatar falls back to `icon`, the initials or a person glyph, with their\n * background; a new image is tried again. A server-rendered image that failed before hydration\n * is detected after mount (settled without a natural size, confirmed by `decode()`).\n * - **Accessible name**: an image uses `name` (whitespace collapsed) as its `alt`, or `''` when the\n * name is blank. Without an image (none given, or it failed to load) the avatar is `role=\"img\"`\n * with `aria-label={name}` (without a name: the image slot's own `alt`) and the initials/icon\n * are hidden; without either (and without `aria-label`/`aria-labelledby`) it is decorative\n * (`aria-hidden`). A consumer `aria-label`, `aria-labelledby` or `role` (other than\n * `presentation`/`none`) puts the name on the avatar visual, and an image inside it gets\n * `alt=\"\"`. `decorative` hides it in every mode. `aria-describedby`, `aria-description` and\n * `aria-details` go to the element that carries the name: the `<img>` when a non-blank `alt`\n * names it, otherwise the avatar visual (never an `alt=\"\"` image).\n * - **Badge**: `badge` renders at the bottom end corner (logical, RTL-safe) as a sibling of the\n * avatar visual, so a `PresenceBadge` keeps its own name. With a badge, `ref`, `className` and\n * the rest props go to the outer wrapper.\n *\n * @example\n * <Avatar name=\"Jane Doe\" src=\"/jane.jpg\" badge={<PresenceBadge status=\"available\" />} />\n */\nexport const Avatar = ({\n src,\n name,\n size: sizeProp,\n shape: shapeProp,\n color: colorProp = 'brand',\n idForColor,\n active = 'unset',\n activeAppearance = 'ring',\n initials: initialsSlot,\n icon,\n image,\n badge,\n decorative = false,\n className,\n ref,\n role,\n 'aria-label': ariaLabel,\n 'aria-labelledby': ariaLabelledBy,\n 'aria-describedby': ariaDescribedBy,\n 'aria-description': ariaDescription,\n 'aria-details': ariaDetails,\n ...rest\n}: AvatarProps) => {\n // The media box of a surrounding Tag or InteractionTag, for an Avatar without its own `size`.\n const box = React.useContext(AvatarSizeContext);\n const imageSlot =\n image === null || image === undefined || typeof image === 'boolean' || image === ''\n ? undefined\n : image;\n const slotProps = readSlotProps(imageSlot);\n const imageKey = getImageKey(imageSlot, slotProps, src);\n\n // Load failure of the current image; a new image is tried again (C-HOOKS: adjust state during\n // render on prop change).\n const [failed, setFailed] = React.useState(false);\n const [prevImageKey, setPrevImageKey] = React.useState(imageKey);\n if (!sameImageKey(prevImageKey, imageKey)) {\n setPrevImageKey(imageKey);\n setFailed(false);\n }\n\n // An image that failed before hydration (a fast 404 of server-rendered markup) never reaches\n // `onError`: React attaches the listener while hydrating and does not replay the event. After\n // mount, a settled image without a natural size is broken, unless it is an SVG without one, so\n // `decode()` (which rejects for a broken image) confirms it where the browser supports it. Later\n // images, rendered by the client, report their errors through `onError`.\n const visualRef = React.useRef<HTMLSpanElement>(null);\n React.useLayoutEffect(() => {\n const img = visualRef.current?.querySelector('img');\n if (!img || !img.complete || img.naturalWidth !== 0) return;\n let active = true;\n const checkedSrc = img.getAttribute('src');\n const checkedSrcSet = img.getAttribute('srcset');\n const markFailed = () => {\n // Deferred (C-HOOKS); skipped if the image was replaced or got another source meanwhile.\n if (\n active &&\n img.isConnected &&\n img.getAttribute('src') === checkedSrc &&\n img.getAttribute('srcset') === checkedSrcSet\n ) {\n setFailed(true);\n }\n };\n if (typeof img.decode === 'function') img.decode().then(undefined, markFailed);\n else queueMicrotask(markFailed);\n return () => {\n active = false;\n };\n }, []);\n const rootVisualRef = useMergedRefs(ref, visualRef);\n\n const hasConsumerName = ariaLabel !== undefined || ariaLabelledBy !== undefined;\n // A consumer role goes to the visual span together with the name (data-display#19), so the\n // image inside it is presentational (`alt=\"\"`), as with a consumer `aria-label`: the children\n // of `role=\"img\"` are not exposed. A presentational role (`presentation`, `none`) cannot carry\n // a name, so the image keeps it.\n const roleCarriesName = role !== undefined && role !== 'presentation' && role !== 'none';\n const normalisedName = normaliseName(name);\n const imageAlt = decorative || hasConsumerName || roleCarriesName ? '' : (normalisedName ?? '');\n const handleError: ImageErrorHandler = () => setFailed(true);\n\n // The alt text the image renders with: an element or object slot's own `alt` wins over ours. An\n // `alt` that is `undefined` (an optional `alt: user.photoAlt`, a wrapper forwarding `alt={alt}`)\n // or `null` is not given, so ours applies (the slot's own value would otherwise override it).\n const ownAlt = slotProps?.alt;\n const hasOwnAlt = ownAlt !== undefined && ownAlt !== null;\n const renderedAlt: unknown = hasOwnAlt ? ownAlt : imageAlt;\n\n // The description goes to the element that carries the name: the image itself when a non-blank\n // `alt` names it (the visual span then has no role, or a presentational one), otherwise the\n // visual span. An image with an empty `alt` is presentational, and a description on it would\n // conflict with that role.\n const description: DescriptionProps = {\n 'aria-describedby': ariaDescribedBy,\n 'aria-description': ariaDescription,\n 'aria-details': ariaDetails,\n };\n const imageIsNamed =\n !decorative &&\n !hasConsumerName &&\n !roleCarriesName &&\n typeof renderedAlt === 'string' &&\n renderedAlt.trim() !== '';\n const imageDescription: DescriptionProps = imageIsNamed ? description : {};\n\n let imageNode: React.ReactNode = null;\n if (!failed) {\n if (typeof imageSlot === 'string') {\n imageNode = (\n <img\n src={imageSlot}\n alt={imageAlt}\n {...imageDescription}\n className={cn(avatarClassNames.image, IMAGE_CLASS)}\n onError={handleError}\n />\n );\n } else if (imageSlot !== undefined) {\n // The slot's own props win over renderSlot's defaults, so the composed `onError`, the\n // default `alt` (when the slot gives none) and the joined `aria-describedby` (the avatar's\n // ids, then the slot's) are set on the slot itself. A slot's own `aria-description` and\n // `aria-details` win over the avatar's.\n const overrides: SlotOverrides = {\n onError: composeEventHandlers(\n slotProps?.onError as ImageErrorHandler | undefined,\n handleError,\n ),\n };\n if (!hasOwnAlt) overrides.alt = imageAlt;\n if (imageIsNamed) {\n const ownIds = slotProps?.['aria-describedby'];\n overrides['aria-describedby'] = joinIds(\n ariaDescribedBy,\n typeof ownIds === 'string' ? ownIds : undefined,\n );\n }\n const slot = React.isValidElement(imageSlot)\n ? React.cloneElement(imageSlot as React.ReactElement<SlotOverrides>, overrides)\n : slotProps\n ? { ...(imageSlot as object), ...overrides }\n : imageSlot;\n imageNode = renderSlot(slot as Slot<'img'>, 'img', cn(avatarClassNames.image, IMAGE_CLASS), {\n alt: imageAlt,\n ...imageDescription,\n });\n } else if (src) {\n imageNode = (\n <img\n src={src}\n alt={imageAlt}\n {...imageDescription}\n className={cn(avatarClassNames.image, IMAGE_CLASS)}\n onError={handleError}\n />\n );\n }\n }\n const visualDescription = imageNode !== null && imageIsNamed ? {} : description;\n\n // A falsy icon (`icon={count && <Icon />}` with count 0) is no icon, as in 0.4, and so is a\n // collection whose items render nothing (`icon={items.map(…)}` mapping to nothing). The check\n // does not consume a generator: renderSlot still renders its items.\n const iconNode =\n imageNode === null && icon && slotRendersContent(icon)\n ? renderSlot(icon, 'span', cn(avatarClassNames.icon, 'inline-flex'), { 'aria-hidden': true })\n : null;\n const dir = useDirection();\n const group = React.useContext(AvatarGroupContext);\n // The wedges of a pie overlap at its centre: their initials would print over each other.\n const initialsClass = cn(avatarClassNames.initials, group?.layout === 'pie' && 'invisible');\n const resolvedColor = resolveAvatarColor(colorProp, idForColor, name);\n const showsInitials = imageNode === null && iconNode === null;\n const computedInitials = showsInitials && name ? getInitials(name, { dir }) : '';\n const initialsNode = !showsInitials ? null : initialsSlot && slotRendersContent(initialsSlot) ? (\n renderSlot(initialsSlot, 'span', initialsClass, { 'aria-hidden': true })\n ) : computedInitials ? (\n <span aria-hidden=\"true\" className={initialsClass}>\n {computedInitials}\n </span>\n ) : null;\n\n let content: React.ReactNode;\n let colorClass: string | undefined;\n if (imageNode !== null) {\n content = imageNode;\n } else if (iconNode !== null) {\n content = iconNode;\n colorClass = 'bg-muted text-muted-foreground';\n } else if (initialsNode) {\n content = initialsNode;\n colorClass = avatarColorClasses[resolvedColor];\n } else {\n content = <PersonIcon size=\"60%\" className={avatarClassNames.icon} />;\n colorClass = 'bg-muted text-muted-foreground';\n }\n\n // Accessible name of the avatar visual (data-display#19, #27). With a consumer role and an\n // image it is the name the image would carry: an element or object slot's own alt, else `name`.\n // Without an image (none given, or it failed to load) it is `name`, else the slot's own alt: an\n // avatar named only by its image alt keeps that name when the image fails.\n const imageName =\n imageNode !== null && roleCarriesName && typeof renderedAlt === 'string'\n ? normaliseName(renderedAlt)\n : undefined;\n const slotAltName = typeof ownAlt === 'string' ? normaliseName(ownAlt) : undefined;\n const label =\n ariaLabel ??\n (imageNode === null\n ? (normalisedName ?? slotAltName)\n : roleCarriesName\n ? (imageName ?? normalisedName)\n : undefined);\n let a11yProps: React.HTMLAttributes<HTMLSpanElement>;\n if (decorative) {\n a11yProps = { 'aria-hidden': true, ...visualDescription };\n } else if (label !== undefined || ariaLabelledBy !== undefined) {\n a11yProps = {\n role: role ?? 'img',\n 'aria-label': label,\n 'aria-labelledby': ariaLabelledBy,\n ...visualDescription,\n };\n } else if (imageNode !== null || role !== undefined) {\n a11yProps = { role, ...visualDescription };\n } else {\n a11yProps = { 'aria-hidden': true, ...visualDescription };\n }\n\n // A falsy or empty badge (`badge={count && <CounterBadge … />}` with count 0) is no badge, as in\n // 0.4 and like `icon`: no stray \"0\" in the corner, and no wrapper taking the root props.\n const badgeNode =\n badge && slotRendersContent(badge)\n ? renderSlot(badge, 'span', cn(avatarClassNames.badge, 'absolute bottom-0 end-0 inline-flex'))\n : null;\n const hasBadge = badgeNode !== null;\n\n // An own `size` wins; without one, the box of a surrounding tag's media, else medium. With a\n // badge the visual is sized, not the wrapper.\n const resolvedSize: AvatarSize =\n sizeProp ?? group?.size ?? (box ? (box.size as AvatarSize) : 'medium');\n const resolvedShape = shapeProp ?? box?.shape ?? 'circular';\n const pixels = avatarPixelSize(resolvedSize);\n const stateProps = {\n 'data-size': String(resolvedSize),\n 'data-shape': resolvedShape,\n 'data-color': resolvedColor,\n 'data-active': active,\n 'data-active-appearance': activeAppearance,\n };\n const visualClassName = cn(\n avatarClassNames.visual,\n 'inline-flex items-center justify-center overflow-hidden shrink-0 font-bold',\n avatarShapeClasses(resolvedShape, pixels),\n avatarSizeClassesFor(resolvedSize),\n colorClass,\n active === 'active' && activeClasses[activeAppearance],\n active === 'inactive' && 'opacity-60 transition-opacity motion-reduce:transition-none',\n );\n\n if (!hasBadge) {\n return (\n <span\n ref={rootVisualRef}\n {...a11yProps}\n {...stateProps}\n {...rest}\n className={cn(avatarClassNames.root, visualClassName, className)}\n >\n {content}\n </span>\n );\n }\n\n return (\n <span\n ref={ref}\n {...stateProps}\n {...rest}\n className={cn(avatarClassNames.root, 'relative inline-flex shrink-0', className)}\n >\n <span ref={visualRef} {...a11yProps} className={visualClassName}>\n {content}\n </span>\n <AvatarBadgeSizeContext.Provider value={avatarBadgeSize(pixels)}>\n {badgeNode}\n </AvatarBadgeSizeContext.Provider>\n </span>\n );\n};\n\nAvatar.displayName = 'Avatar';\n"],"mappings":";;;;;;;;;;;;;;;;AAiIiBC,EAAiB,KACzBA,EAAiB,KAChBA,EAAiB,KAClBA,EAAiB,KACTA,EAAiB;AAGlC,IAAMC,IAAc,8BAGdC,KAAsF;CAC1F,MAAM;CACN,eAAe;CACf,QAAQ;CACR,MAAM;AACR;AAGA,SAASC,EAAc,GAA8C;CACnE,OAAOC,GAAM,KAAK,CAAC,CAAC,QAAQ,QAAQ,GAAG,KAAK,KAAA;AAC9C;AA2BA,SAASC,GAAc,GAA2C;CAChE,IAAIN,EAAM,eAAeO,CAAI,GAAG,OAAOA,EAAK;CAC5C,IAAI,OAAOA,KAAS,YAAYA,KAAiB,EAAE,OAAO,YAAYA,IACpE,OAAOA;AAGX;AASA,SAASC,GACP,GACA,GACA,GACU;CACV,IAAIC,MAAc,KAAA,GAAW,OAAO;EAAC,KAAA;EAAW,KAAA;EAAWC,KAAO,KAAA;EAAW,KAAA;CAAS;CACtF,IAAI,OAAOD,KAAc,UAAU,OAAO;EAAC,KAAA;EAAW,KAAA;EAAWA;EAAW,KAAA;CAAS;CACrF,IAAME,IAAUX,EAAM,eAAeS,CAAS,IAAIA,IAAY,KAAA;CAC9D,OAAO;EAACE,GAAS;EAAMA,GAAS;EAAKC,GAAW;EAAKA,GAAW;CAAM;AACxE;AAEA,SAASC,EAAc,GAAkD;CACvE,IAAI,OAAOC,KAAU,aAAYA,GAAgB,OAAO;CACxD,IAAMC,IAAiB,OAAO,eAAeD,CAAK;CAClD,OAAOC,MAAU,OAAO,aAAaA,MAAU;AACjD;AAGA,SAASC,EAAY,GAAY,GAAq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B;CAgBA,OAdKsD,KAeH,mBAAC,QAAD;EACO;EACL,GAAIK;EACJ,GAAItE;EACJ,WAAWgC,EAAGC,EAAiB,MAAM,iCAAiC0C,EAAS;EAJjF,UAAA,CAME,kBAAC,QAAD;GAAM,KAAKlE;GAAW,GAAIqD;GAAW,WAAWU;GAC7C,UAAAjB;EACG,CAAA,GACN,kBAACqB,GAAuB,UAAxB;GAAiC,OAAOC,GAAgBT,EAAM;GAC3D,UAAAL;EAC8B,CAAA,CAC7B;MAzBJ,kBAAC,QAAD;EACE,KAAKhD;EACL,GAAI+C;EACJ,GAAIQ;EACJ,GAAItE;EACJ,WAAWgC,EAAGC,EAAiB,MAAMuC,GAAiBG,EAAS;EAE9D,UAAApB;CACG,CAAA;AAmBZ;AAEA,EAAO,cAAc"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use client";var e={"extra-small":24,small:32,medium:40,large:48,"extra-large":56};function t(t){return typeof t==`number`?t:e[t]}var n={16:`w-4 h-4 text-[10px]`,20:`w-5 h-5 text-[10px]`,24:`w-6 h-6 text-[10px]`,28:`w-7 h-7 text-xs`,32:`w-8 h-8 text-xs`,36:`w-9 h-9 text-sm`,40:`w-10 h-10 text-sm`,48:`w-12 h-12 text-base`,56:`w-14 h-14 text-lg`,64:`w-16 h-16 text-xl`,72:`w-18 h-18 text-2xl`,96:`w-24 h-24 text-3xl`,120:`w-30 h-30 text-4xl`,128:`w-32 h-32 text-4xl`};function r(t){return n[typeof t==`number`?t:e[t]]}function i(e){return e<=24?`extra-small`:e<=32?`small`:e<=56?`medium`:e<=96?`large`:`extra-large`}function a(e,t){return e===`circular`?`rounded-full`:t>=40?`rounded-md`:`rounded-sm`}exports.avatarBadgeSize=i,exports.avatarBoxClasses=n,exports.avatarPixelSize=t,exports.avatarShapeClasses=a,exports.avatarSizeClassesFor=r;
|
|
2
|
+
//# sourceMappingURL=Avatar.sizes.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Avatar.sizes.cjs","names":["NAMED_PIXELS","avatarPixelSize","size","avatarBoxClasses","avatarSizeClassesFor","avatarBadgeSize","pixels","avatarShapeClasses","shape"],"sources":["../../../src/components/data-display/Avatar.sizes.ts"],"sourcesContent":["import type { Size } from '../../lib/types';\n\n/**\n * The numeric sizes of an Avatar, in pixels (Fluent's 14 sizes). A literal union: Tailwind can only\n * generate the classes of {@link avatarBoxClasses}.\n */\nexport type AvatarNumericSize =\n 16 | 20 | 24 | 28 | 32 | 36 | 40 | 48 | 56 | 64 | 72 | 96 | 120 | 128;\n\n/** The size of an Avatar: a named size (24 to 56px) or one of the {@link AvatarNumericSize}s. */\nexport type AvatarSize = Size | AvatarNumericSize;\n\n/** Pixel box of each named size. */\nconst NAMED_PIXELS: Readonly<Record<Size, AvatarNumericSize>> = {\n 'extra-small': 24,\n small: 32,\n medium: 40,\n large: 48,\n 'extra-large': 56,\n};\n\n/** The pixel box of an Avatar size. */\nexport function avatarPixelSize(size: AvatarSize): number {\n return typeof size === 'number' ? size : NAMED_PIXELS[size];\n}\n\n/** Width, height and text size classes per pixel box. Literal strings only. */\nexport const avatarBoxClasses: Readonly<Record<AvatarNumericSize, string>> = {\n 16: 'w-4 h-4 text-[10px]',\n 20: 'w-5 h-5 text-[10px]',\n 24: 'w-6 h-6 text-[10px]',\n 28: 'w-7 h-7 text-xs',\n 32: 'w-8 h-8 text-xs',\n 36: 'w-9 h-9 text-sm',\n 40: 'w-10 h-10 text-sm',\n 48: 'w-12 h-12 text-base',\n 56: 'w-14 h-14 text-lg',\n 64: 'w-16 h-16 text-xl',\n 72: 'w-18 h-18 text-2xl',\n 96: 'w-24 h-24 text-3xl',\n 120: 'w-30 h-30 text-4xl',\n 128: 'w-32 h-32 text-4xl',\n};\n\n/** The box classes of an Avatar size. */\nexport function avatarSizeClassesFor(size: AvatarSize): string {\n return avatarBoxClasses[typeof size === 'number' ? size : NAMED_PIXELS[size]];\n}\n\n/** The size a presence badge takes on an avatar of this pixel box. */\nexport function avatarBadgeSize(pixels: number): Size {\n if (pixels <= 24) return 'extra-small';\n if (pixels <= 32) return 'small';\n if (pixels <= 56) return 'medium';\n if (pixels <= 96) return 'large';\n return 'extra-large';\n}\n\n/** The corner radius of an Avatar shape: a circle, or rounded-md from 40px and rounded-sm below. */\nexport function avatarShapeClasses(shape: 'circular' | 'square', pixels: number): string {\n if (shape === 'circular') return 'rounded-full';\n return pixels >= 40 ? 'rounded-md' : 'rounded-sm';\n}\n"],"mappings":"aAaA,IAAMA,EAA0D,CAC9D,cAAe,GACf,MAAO,GACP,OAAQ,GACR,MAAO,GACP,cAAe,EACjB,EAGA,SAAgBC,EAAgB,EAA0B,CACxD,OAAO,OAAOC,GAAS,SAAWA,EAAOF,EAAaE,EACxD,CAGA,IAAaC,EAAgE,CAC3E,GAAI,sBACJ,GAAI,sBACJ,GAAI,sBACJ,GAAI,kBACJ,GAAI,kBACJ,GAAI,kBACJ,GAAI,oBACJ,GAAI,sBACJ,GAAI,oBACJ,GAAI,oBACJ,GAAI,qBACJ,GAAI,qBACJ,IAAK,qBACL,IAAK,oBACP,EAGA,SAAgBC,EAAqB,EAA0B,CAC7D,OAAOD,EAAiB,OAAOD,GAAS,SAAWA,EAAOF,EAAaE,GACzE,CAGA,SAAgBG,EAAgB,EAAsB,CAKpD,OAJIC,GAAU,GAAW,cACrBA,GAAU,GAAW,QACrBA,GAAU,GAAW,SACrBA,GAAU,GAAW,QAClB,aACT,CAGA,SAAgBC,EAAmB,EAA8B,EAAwB,CAEvF,OADIC,IAAU,WAAmB,eAC1BF,GAAU,GAAK,aAAe,YACvC"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
//#region src/components/data-display/Avatar.sizes.ts
|
|
3
|
+
var e = {
|
|
4
|
+
"extra-small": 24,
|
|
5
|
+
small: 32,
|
|
6
|
+
medium: 40,
|
|
7
|
+
large: 48,
|
|
8
|
+
"extra-large": 56
|
|
9
|
+
};
|
|
10
|
+
function t(t) {
|
|
11
|
+
return typeof t == "number" ? t : e[t];
|
|
12
|
+
}
|
|
13
|
+
var n = {
|
|
14
|
+
16: "w-4 h-4 text-[10px]",
|
|
15
|
+
20: "w-5 h-5 text-[10px]",
|
|
16
|
+
24: "w-6 h-6 text-[10px]",
|
|
17
|
+
28: "w-7 h-7 text-xs",
|
|
18
|
+
32: "w-8 h-8 text-xs",
|
|
19
|
+
36: "w-9 h-9 text-sm",
|
|
20
|
+
40: "w-10 h-10 text-sm",
|
|
21
|
+
48: "w-12 h-12 text-base",
|
|
22
|
+
56: "w-14 h-14 text-lg",
|
|
23
|
+
64: "w-16 h-16 text-xl",
|
|
24
|
+
72: "w-18 h-18 text-2xl",
|
|
25
|
+
96: "w-24 h-24 text-3xl",
|
|
26
|
+
120: "w-30 h-30 text-4xl",
|
|
27
|
+
128: "w-32 h-32 text-4xl"
|
|
28
|
+
};
|
|
29
|
+
function r(t) {
|
|
30
|
+
return n[typeof t == "number" ? t : e[t]];
|
|
31
|
+
}
|
|
32
|
+
function i(e) {
|
|
33
|
+
return e <= 24 ? "extra-small" : e <= 32 ? "small" : e <= 56 ? "medium" : e <= 96 ? "large" : "extra-large";
|
|
34
|
+
}
|
|
35
|
+
function a(e, t) {
|
|
36
|
+
return e === "circular" ? "rounded-full" : t >= 40 ? "rounded-md" : "rounded-sm";
|
|
37
|
+
}
|
|
38
|
+
//#endregion
|
|
39
|
+
export { i as avatarBadgeSize, n as avatarBoxClasses, t as avatarPixelSize, a as avatarShapeClasses, r as avatarSizeClassesFor };
|
|
40
|
+
|
|
41
|
+
//# sourceMappingURL=Avatar.sizes.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Avatar.sizes.mjs","names":["NAMED_PIXELS","avatarPixelSize","size","avatarBoxClasses","avatarSizeClassesFor","avatarBadgeSize","pixels","avatarShapeClasses","shape"],"sources":["../../../src/components/data-display/Avatar.sizes.ts"],"sourcesContent":["import type { Size } from '../../lib/types';\n\n/**\n * The numeric sizes of an Avatar, in pixels (Fluent's 14 sizes). A literal union: Tailwind can only\n * generate the classes of {@link avatarBoxClasses}.\n */\nexport type AvatarNumericSize =\n 16 | 20 | 24 | 28 | 32 | 36 | 40 | 48 | 56 | 64 | 72 | 96 | 120 | 128;\n\n/** The size of an Avatar: a named size (24 to 56px) or one of the {@link AvatarNumericSize}s. */\nexport type AvatarSize = Size | AvatarNumericSize;\n\n/** Pixel box of each named size. */\nconst NAMED_PIXELS: Readonly<Record<Size, AvatarNumericSize>> = {\n 'extra-small': 24,\n small: 32,\n medium: 40,\n large: 48,\n 'extra-large': 56,\n};\n\n/** The pixel box of an Avatar size. */\nexport function avatarPixelSize(size: AvatarSize): number {\n return typeof size === 'number' ? size : NAMED_PIXELS[size];\n}\n\n/** Width, height and text size classes per pixel box. Literal strings only. */\nexport const avatarBoxClasses: Readonly<Record<AvatarNumericSize, string>> = {\n 16: 'w-4 h-4 text-[10px]',\n 20: 'w-5 h-5 text-[10px]',\n 24: 'w-6 h-6 text-[10px]',\n 28: 'w-7 h-7 text-xs',\n 32: 'w-8 h-8 text-xs',\n 36: 'w-9 h-9 text-sm',\n 40: 'w-10 h-10 text-sm',\n 48: 'w-12 h-12 text-base',\n 56: 'w-14 h-14 text-lg',\n 64: 'w-16 h-16 text-xl',\n 72: 'w-18 h-18 text-2xl',\n 96: 'w-24 h-24 text-3xl',\n 120: 'w-30 h-30 text-4xl',\n 128: 'w-32 h-32 text-4xl',\n};\n\n/** The box classes of an Avatar size. */\nexport function avatarSizeClassesFor(size: AvatarSize): string {\n return avatarBoxClasses[typeof size === 'number' ? size : NAMED_PIXELS[size]];\n}\n\n/** The size a presence badge takes on an avatar of this pixel box. */\nexport function avatarBadgeSize(pixels: number): Size {\n if (pixels <= 24) return 'extra-small';\n if (pixels <= 32) return 'small';\n if (pixels <= 56) return 'medium';\n if (pixels <= 96) return 'large';\n return 'extra-large';\n}\n\n/** The corner radius of an Avatar shape: a circle, or rounded-md from 40px and rounded-sm below. */\nexport function avatarShapeClasses(shape: 'circular' | 'square', pixels: number): string {\n if (shape === 'circular') return 'rounded-full';\n return pixels >= 40 ? 'rounded-md' : 'rounded-sm';\n}\n"],"mappings":";;AAaA,IAAMA,IAA0D;CAC9D,eAAe;CACf,OAAO;CACP,QAAQ;CACR,OAAO;CACP,eAAe;AACjB;AAGA,SAAgBC,EAAgB,GAA0B;CACxD,OAAO,OAAOC,KAAS,WAAWA,IAAOF,EAAaE;AACxD;AAGA,IAAaC,IAAgE;CAC3E,IAAI;CACJ,IAAI;CACJ,IAAI;CACJ,IAAI;CACJ,IAAI;CACJ,IAAI;CACJ,IAAI;CACJ,IAAI;CACJ,IAAI;CACJ,IAAI;CACJ,IAAI;CACJ,IAAI;CACJ,KAAK;CACL,KAAK;AACP;AAGA,SAAgBC,EAAqB,GAA0B;CAC7D,OAAOD,EAAiB,OAAOD,KAAS,WAAWA,IAAOF,EAAaE;AACzE;AAGA,SAAgBG,EAAgB,GAAsB;CAKpD,OAJIC,KAAU,KAAW,gBACrBA,KAAU,KAAW,UACrBA,KAAU,KAAW,WACrBA,KAAU,KAAW,UAClB;AACT;AAGA,SAAgBC,EAAmB,GAA8B,GAAwB;CAEvF,OADIC,MAAU,aAAmB,iBAC1BF,KAAU,KAAK,eAAe;AACvC"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use client";const e=require("../../_virtual/_rolldown/runtime.cjs"),t=require("../../lib/cn.cjs"),n=require("../../lib/children.cjs"),r=require("../../lib/dev.cjs"),i=require("../../lib/classNames.cjs"),a=require("
|
|
1
|
+
"use client";const e=require("../../_virtual/_rolldown/runtime.cjs"),t=require("../../lib/cn.cjs"),n=require("../../lib/children.cjs"),r=require("../../lib/dev.cjs"),i=require("../../lib/classNames.cjs"),a=require("./AvatarGroup.context.cjs"),o=require("./Avatar.sizes.cjs"),s=require("./AvatarGroup.partition.cjs"),c=require("./AvatarGroup.parts.cjs");let l=require("react");l=e.__toESM(l,1);let u=require("react/jsx-runtime");var d=[[``],[`[clip-path:inset(0_50%_0_0)]`,`[clip-path:inset(0_0_0_50%)]`],[`[clip-path:inset(0_50%_0_0)]`,`[clip-path:inset(0_0_50%_50%)]`,`[clip-path:inset(50%_0_0_50%)]`]],f=({max:e,size:f,layout:p=`stack`,overflowIndicator:m=`count`,overflowLabel:h,unnamedMemberLabel:g=c.DEFAULT_UNNAMED_MEMBER_LABEL,open:_,defaultOpen:v,onOpenChange:y,className:b,children:x,ref:S,"aria-label":C,"aria-labelledby":w,...T})=>{let E=n.flattenChildren(x),D=E.find(({node:e})=>n.isElementOfType(e,c.AvatarGroupPopover)),O=E.filter(({node:e})=>!n.isElementOfType(e,c.AvatarGroupPopover)),k=f??(p===`pie`?`large`:`medium`),{inlineItems:A,overflowItems:j}=s.partitionAvatarGroupItems({items:O,maxInlineItems:e,layout:p}),M=j??[],N=A.length>0,P=l.useMemo(()=>({size:k,layout:p,hasInlineItems:N}),[k,p,N]),F=C===void 0&&w===void 0;return l.useEffect(()=>{F&&r.warnOnce(`AvatarGroup:unnamed`,"AvatarGroup: the group has no accessible name. Pass `aria-label` (or `aria-labelledby`) describing the people it shows.")},[F]),(0,u.jsx)(`div`,{ref:S,role:`group`,"aria-label":C,"aria-labelledby":w,"data-layout":p,...T,className:t.cn(i.avatarGroupClassNames.root,`inline-flex items-center`,p!==`stack`&&`gap-1`,b),children:(0,u.jsxs)(a.AvatarGroupContext.Provider,{value:P,children:[p===`pie`?A.length>0&&(0,u.jsx)(`span`,{className:t.cn(i.avatarGroupClassNames.pie,`relative inline-block shrink-0 overflow-hidden rounded-full`,o.avatarSizeClassesFor(k)),children:A.map(({key:e,node:n},r)=>(0,u.jsx)(`span`,{"aria-hidden":`true`,className:t.cn(i.avatarGroupClassNames.item,`absolute inset-0 inline-flex`,d[A.length-1]?.[r]),children:n},e))}):A.map(({key:e,node:n},r)=>(0,u.jsx)(`span`,{className:t.cn(i.avatarGroupClassNames.item,`inline-flex rounded-full ring-2 ring-background`,p===`stack`&&r>0&&`-ms-2`),children:n},e)),D?D.node:M.length>0&&(0,u.jsx)(c.AvatarGroupPopover,{count:M.length,indicator:m,label:h,unnamedMemberLabel:g,open:_,defaultOpen:v,onOpenChange:y,children:M.map(({key:e,node:t})=>(0,u.jsx)(l.Fragment,{children:t},e))})]})})};f.displayName=`AvatarGroup`;var p=Object.assign(f,{Item:c.AvatarGroupItem,Popover:c.AvatarGroupPopover});exports.AvatarGroup=p,exports.AvatarGroupItem=c.AvatarGroupItem,exports.AvatarGroupPopover=c.AvatarGroupPopover;
|
|
2
2
|
//# sourceMappingURL=AvatarGroup.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AvatarGroup.cjs","names":["isElementOfType","Avatar","React","flattenChildren","useId","DismissLayerContext","usePopupPosition","useDismiss","useMergedRefs","getTabbableElements","isInsideLayerTree","cn","avatarGroupClassNames","avatarSizeClasses","Portal","require_runtime","require_cn","require_children","require_dev","require_classNames","require_useId","require_focus","require_useMergedRefs","require_layers","require_useDismiss","require_Portal","require_usePopupPosition","require_useRestoreFocus","require_Avatar","react","react_jsx_runtime","DEFAULT_UNNAMED_MEMBER_LABEL","nonBlank","value","getMemberName","member","label","labelledBy","decorative","name","rendersUnnamed","imageProps","image","AvatarGroup","ariaLabel","ariaLabelledBy","props","items","children","limit","max","visible","hidden","overflow","unnamed","popupId","open","setOpen","isOpen","overflowLabel","parentLayerId","triggerRef","surfaceRef","surface","setSurface","triggerRefs","setReference","surfaceRefs","setFloating","handleSurfaceKeyDown","trigger","event","popup","origin","inner","next","el","target","order","index","hasUnnamedMember","node","unnamedMemberLabel","className","i","key","size","floatingProps"],"sources":["../../../src/components/data-display/AvatarGroup.tsx"],"sourcesContent":["import * as React from 'react';\nimport { flattenChildren, isElementOfType } from '../../lib/children';\nimport { cn } from '../../lib/cn';\nimport { avatarGroupClassNames } from '../../lib/classNames';\nimport { warnOnce } from '../../lib/dev';\nimport { getTabbableElements } from '../../lib/focus';\nimport { isInsideLayerTree } from '../../lib/layers';\nimport { focusRing } from '../../lib/styles';\nimport type { Size } from '../../lib/types';\nimport { useId } from '../../hooks/useId';\nimport { DismissLayerContext, useDismiss } from '../../hooks/useDismiss';\nimport { useMergedRefs } from '../../hooks/useMergedRefs';\nimport { usePopupPosition } from '../../hooks/usePopupPosition';\nimport { useRestoreFocus } from '../../hooks/useRestoreFocus';\nimport { Portal } from '../portal/Portal';\nimport { Avatar, avatarSizeClasses } from './Avatar';\nimport type { AvatarProps } from './Avatar';\n\n/** Properties for the AvatarGroup component. */\nexport interface AvatarGroupProps extends React.HTMLAttributes<HTMLDivElement> {\n /**\n * Maximum number of avatars to display. The others are replaced by an overflow button that\n * lists their names. `0` or a negative value shows only the overflow button, a fraction is\n * rounded down, and `NaN` shows every member (as without `max`). The members of a Fragment\n * count one by one.\n */\n max?: number;\n /** Size of the overflow button (match it to the avatars).\n * @default 'medium'\n */\n size?: Size;\n /**\n * Accessible name of the overflow button (and its popup). A function receives the number of\n * hidden members. Localise it here.\n * @default (count) => `${count} more`\n */\n overflowLabel?: string | ((count: number) => string);\n /**\n * Text listed in the overflow popup for a hidden member that has no accessible name (an\n * `Avatar` without `name`, `aria-label`, `aria-labelledby` or image `alt`, or blank text).\n * Localise it here; better still, give every member a name (a development warning asks for it).\n * @default 'Unnamed member'\n */\n unnamedMemberLabel?: string;\n /** Ref to the root `<div>`. */\n ref?: React.Ref<HTMLDivElement>;\n}\n\n/** Default text listed for a hidden member that would render with no accessible name. */\nconst DEFAULT_UNNAMED_MEMBER_LABEL = 'Unnamed member';\n\nconst nonBlank = (value: unknown): value is string =>\n typeof value === 'string' && value.trim() !== '';\n\n/**\n * The text name of a member for the overflow list: the text of a text member, or the accessible\n * name of an `Avatar` given by its props (`aria-label` before `name`). An `Avatar` labelled by\n * `aria-labelledby` (unless `decorative`) and every other element have none: they are rendered as\n * they are, so a link keeps working and keeps its own label.\n */\nfunction getMemberName(member: React.ReactNode): string | undefined {\n if (typeof member === 'string' || typeof member === 'number') {\n return String(member).trim() || undefined;\n }\n if (!isElementOfType<AvatarProps>(member, Avatar)) return undefined;\n const { decorative, name, 'aria-label': label, 'aria-labelledby': labelledBy } = member.props;\n if (!decorative && nonBlank(labelledBy)) return undefined;\n for (const value of [label, name]) {\n if (nonBlank(value)) return value.trim();\n }\n return undefined;\n}\n\n/**\n * Whether a member without a {@link getMemberName} name would render with no accessible name,\n * so its list item would be empty for assistive technology: blank text, or an `Avatar` that is\n * neither labelled by `aria-labelledby` nor named by its image's `alt` (or is `decorative`).\n * Other elements are rendered as they are, since their content is unknown here.\n */\nfunction rendersUnnamed(member: React.ReactNode): boolean {\n if (typeof member === 'string' || typeof member === 'number') return true;\n if (!isElementOfType<AvatarProps>(member, Avatar)) return false;\n const { decorative, image, 'aria-labelledby': labelledBy } = member.props;\n if (decorative) return true;\n if (nonBlank(labelledBy)) return false;\n const imageProps: unknown = React.isValidElement(image) ? image.props : image;\n const alt =\n typeof imageProps === 'object' && imageProps !== null && 'alt' in imageProps\n ? imageProps.alt\n : undefined;\n return !nonBlank(alt);\n}\n\n/**\n * A row of overlapping avatars (`role=\"group\"`; name it with `aria-label`).\n *\n * With `max`, the avatars beyond the limit are replaced by an overflow `<button>` (\"+3\", named\n * \"3 more\", see `overflowLabel`). It toggles a popup that lists the hidden members' names: an\n * `Avatar` by its `aria-label` or `name` prop, text as it is. Other members, such as an `Avatar`\n * inside a link or one labelled by `aria-labelledby`, are rendered as they are, and an `Avatar` or\n * text with no accessible name is listed as `unnamedMemberLabel` with a development warning.\n * Focus moves into the popup; Escape, a press outside or the button close it and focus returns to\n * the button. Tab and Shift+Tab move through the popup's own tab stops (links in rendered\n * members); Tab from the last one closes the popup and moves on to the element after the button,\n * Shift+Tab from the first one closes it and returns to the button. When the button is the last\n * tab stop (of the page, or of the Wave layer the group is in, such as a dialog), Tab is left to\n * the browser or the enclosing focus trap.\n *\n * @example\n * <AvatarGroup aria-label=\"Project team\" max={3}>\n * <Avatar name=\"Ada Lovelace\" />\n * <Avatar name=\"Alan Turing\" />\n * </AvatarGroup>\n */\nexport const AvatarGroup = ({\n max,\n size = 'medium',\n overflowLabel,\n unnamedMemberLabel = DEFAULT_UNNAMED_MEMBER_LABEL,\n className,\n children,\n ref,\n 'aria-label': ariaLabel,\n 'aria-labelledby': ariaLabelledBy,\n ...props\n}: AvatarGroupProps) => {\n // Fragments are flattened, so each member counts, overlaps and is listed on its own (C-COMPOUND).\n const items = flattenChildren(children);\n const limit = max === undefined || Number.isNaN(max) ? Infinity : Math.max(0, Math.floor(max));\n const visible = items.slice(0, limit);\n const hidden = items.slice(visible.length);\n const overflow = hidden.length;\n\n const unnamed = ariaLabel === undefined && ariaLabelledBy === undefined;\n React.useEffect(() => {\n if (unnamed) {\n warnOnce(\n 'AvatarGroup:unnamed',\n 'AvatarGroup: the group has no accessible name. Pass `aria-label` (or `aria-labelledby`) describing the people it shows.',\n );\n }\n }, [unnamed]);\n\n const popupId = useId('avatar-group-overflow');\n const [open, setOpen] = React.useState(false);\n // Nothing is hidden any more: close, so the popup does not reappear when members overflow again.\n if (open && overflow === 0) setOpen(false);\n const isOpen = open && overflow > 0;\n const label =\n typeof overflowLabel === 'function'\n ? overflowLabel(overflow)\n : (overflowLabel ?? `${overflow} more`);\n\n // The layer the group is rendered in (a dialog or popover), if any: the popup's parent layer.\n const parentLayerId = React.useContext(DismissLayerContext);\n const triggerRef = React.useRef<HTMLButtonElement | null>(null);\n const surfaceRef = React.useRef<HTMLDivElement | null>(null);\n const [surface, setSurface] = React.useState<HTMLDivElement | null>(null);\n\n const { setReference, setFloating, floatingProps } = usePopupPosition({\n open: isOpen,\n side: 'bottom',\n align: 'start',\n });\n const { layerId } = useDismiss({\n open: isOpen,\n onDismiss: () => setOpen(false),\n refs: [triggerRef, surfaceRef],\n anchorRef: triggerRef,\n focusOutside: true,\n });\n useRestoreFocus({ enabled: isOpen, container: surface, triggerRef, onlyIfFocusInside: true });\n const triggerRefs = useMergedRefs<HTMLButtonElement>(triggerRef, setReference);\n const surfaceRefs = useMergedRefs<HTMLDivElement>(surfaceRef, setFloating, setSurface);\n\n // Move focus into the popup once it is mounted, so its list is read next.\n React.useEffect(() => {\n if (isOpen && surface) surface.focus({ preventScroll: true });\n }, [isOpen, surface]);\n\n // The popup is portaled, so native tabbing would leave it for the end of the page. Tab moves\n // through the popup's own tab stops (a rendered member can be a link); leaving the last one\n // closes the popup and moves on from the button instead (Shift+Tab before the first one: back to\n // the button), like a focus trap does for a popup anchored in a dialog. When nothing tabbable\n // follows the button, Tab is not prevented: focus returns to the button as the popup closes and\n // the browser (leaving the page) or an enclosing focus trap (wrapping) takes it from there.\n // Inside a parent layer (a dialog, a popover), a tab stop after the button that lies outside that\n // layer is treated the same way: a focus trap that leaves the page outside it interactive would\n // pull focus back from there, while its descendant-layer rule (§2.4) wraps from the button.\n // Tab stops are computed at keydown time, never cached (§2.2 focus utilities). A key that\n // bubbles through React from a portal a member opened is not the popup's: it is ignored.\n const handleSurfaceKeyDown = (event: React.KeyboardEvent<HTMLDivElement>) => {\n const trigger = triggerRef.current;\n if (event.key !== 'Tab' || event.defaultPrevented || !trigger) return;\n const popup = event.currentTarget;\n // Duck typed (`nodeType`), not `instanceof Node`: a popup portaled into another document (an\n // iframe, a popout window) holds nodes of that realm.\n const origin = event.target as Partial<Node> | null;\n if (!origin || typeof origin.nodeType !== 'number' || !popup.contains(origin as Node)) return;\n const inner = getTabbableElements(popup);\n // -1 while focus is on the popup itself (or on something that is not a tab stop).\n const current = inner.findIndex((el) => el.contains(origin as Node));\n const next = current + (event.shiftKey ? -1 : 1);\n if (next >= 0 && next < inner.length) {\n event.preventDefault();\n inner[next]!.focus();\n return;\n }\n let target: HTMLElement | undefined = trigger;\n if (!event.shiftKey) {\n const order = getTabbableElements(trigger.ownerDocument.body).filter(\n (el) => !popup.contains(el),\n );\n const index = order.indexOf(trigger);\n target = index === -1 ? trigger : order[index + 1];\n if (target && parentLayerId !== null && !isInsideLayerTree(parentLayerId, target)) {\n target = undefined;\n }\n }\n setOpen(false);\n if (!target) return;\n event.preventDefault();\n target.focus();\n };\n\n const hasUnnamedMember =\n isOpen && hidden.some(({ node }) => getMemberName(node) === undefined && rendersUnnamed(node));\n React.useEffect(() => {\n if (hasUnnamedMember) {\n warnOnce(\n 'AvatarGroup:unnamed-member',\n `AvatarGroup: a hidden member has no accessible name and is listed as \"${unnamedMemberLabel}\". Give each member a \\`name\\` or \\`aria-label\\`.`,\n );\n }\n }, [hasUnnamedMember, unnamedMemberLabel]);\n\n return (\n <div\n ref={ref}\n role=\"group\"\n aria-label={ariaLabel}\n aria-labelledby={ariaLabelledBy}\n {...props}\n className={cn(avatarGroupClassNames.root, 'inline-flex items-center', className)}\n >\n {visible.map(({ key, node }, i) => (\n <span\n key={key}\n className={cn(\n avatarGroupClassNames.item,\n 'inline-flex rounded-full ring-2 ring-background',\n i > 0 && '-ms-2',\n )}\n >\n {node}\n </span>\n ))}\n {overflow > 0 && (\n <button\n ref={triggerRefs}\n type=\"button\"\n aria-label={label}\n aria-haspopup=\"dialog\"\n aria-expanded={isOpen}\n aria-controls={isOpen ? popupId : undefined}\n className={cn(\n avatarGroupClassNames.overflowButton,\n 'inline-flex shrink-0 cursor-pointer items-center justify-center rounded-full border-0 p-0 font-semibold',\n 'bg-muted text-muted-foreground ring-2 ring-background',\n 'not-disabled:not-aria-disabled:hover:bg-subtle-pressed',\n focusRing,\n visible.length > 0 && '-ms-2',\n avatarSizeClasses[size],\n )}\n onClick={() => setOpen((value) => !value)}\n >\n +{overflow}\n </button>\n )}\n {isOpen && (\n <Portal layerId={layerId}>\n <div\n ref={surfaceRefs}\n id={popupId}\n role=\"dialog\"\n aria-label={label}\n tabIndex={-1}\n data-state=\"open\"\n {...floatingProps}\n className={cn(\n avatarGroupClassNames.surface,\n 'min-w-32 max-w-xs rounded-md border border-border bg-background p-2 text-body-1 text-foreground shadow-16',\n focusRing,\n )}\n onKeyDown={handleSurfaceKeyDown}\n >\n <ul className={cn(avatarGroupClassNames.list, 'm-0 flex list-none flex-col gap-1 p-0')}>\n {hidden.map(({ key, node }) => (\n <li key={key} className={cn(avatarGroupClassNames.listItem, 'px-1 py-0.5')}>\n {getMemberName(node) ?? (rendersUnnamed(node) ? unnamedMemberLabel : node)}\n </li>\n ))}\n </ul>\n </div>\n </Portal>\n )}\n </div>\n );\n};\n\nAvatarGroup.displayName = 'AvatarGroup';\n"],"mappings":"6oBAiDA,IAAM+B,EAA+B,iBAE/BC,EAAY,GAChB,OAAOC,GAAU,UAAYA,EAAM,KAAK,IAAM,GAQhD,SAASC,EAAc,EAA6C,CAClE,GAAI,OAAOC,GAAW,UAAY,OAAOA,GAAW,SAClD,OAAO,OAAOA,CAAM,CAAC,CAAC,KAAK,GAAK,IAAA,GAElC,GAAI,CAACnC,EAAAA,gBAA6BmC,EAAQlC,EAAAA,MAAM,EAAG,OACnD,GAAM,CAAE,aAAY,OAAM,aAAcmC,EAAO,kBAAmBC,GAAeF,EAAO,MACxF,GAAKG,GAAc,GAASD,CAAU,EACtC,KAAK,IAAMJ,IAAS,CAACG,EAAOG,CAAI,EAC9B,GAAIP,EAASC,CAAK,EAAG,OAAOA,EAAM,KAAK,CAAA,CAG3C,CAQA,SAASO,EAAe,EAAkC,CACxD,GAAI,OAAOL,GAAW,UAAY,OAAOA,GAAW,SAAU,MAAO,GACrE,GAAI,CAACnC,EAAAA,gBAA6BmC,EAAQlC,EAAAA,MAAM,EAAG,MAAO,GAC1D,GAAM,CAAE,aAAY,QAAO,kBAAmBoC,GAAeF,EAAO,MACpE,GAAIG,EAAY,MAAO,GACvB,GAAIN,EAASK,CAAU,EAAG,MAAO,GACjC,IAAMI,EAAsBvC,EAAM,eAAewC,CAAK,EAAIA,EAAM,MAAQA,EAKxE,MAAO,CAACV,EAHN,OAAOS,GAAe,UAAYA,GAAuB,QAASA,EAC9DA,EAAW,IACX,IAAA,EACc,CACtB,CAuBA,IAAaE,GAAe,CAC1B,MACA,OAAO,SACP,gBACA,qBAAqBZ,EACrB,YACA,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AWnB,EAAAA,GAAGC,EAAAA,sBAAsB,SAAU,aAAa,EACtE,SAAAsB,EAAc+C,CAAI,IAAMzC,EAAeyC,CAAI,EAAIC,EAAqBD,EACnE,EAFKI,CAEL,CACL,CACC,CAAA,CACD,CAAA,CACC,CAAA,CAEP,GAET,EAEA,EAAY,YAAc"}
|
|
1
|
+
{"version":3,"file":"AvatarGroup.cjs","names":["DEFAULT_UNNAMED_MEMBER_LABEL","flattenChildren","isElementOfType","AvatarGroupPopover","partitionAvatarGroupItems","React","cn","avatarGroupClassNames","AvatarGroupContext","avatarSizeClassesFor","AvatarGroupItem","require_runtime","require_cn","require_children","require_dev","require_classNames","require_AvatarGroup_context","require_Avatar_sizes","require_AvatarGroup_partition","require_AvatarGroup_parts","react","react_jsx_runtime","pieWedgeClasses","AvatarGroupRoot","ariaLabel","ariaLabelledBy","props","parts","children","customPopover","node","items","resolvedSize","size","layout","visible","max","hidden","overflowItems","hasInlineItems","groupContext","unnamed","className","i","key","overflowIndicator","overflowLabel","AvatarGroup"],"sources":["../../../src/components/data-display/AvatarGroup.tsx"],"sourcesContent":["import * as React from 'react';\nimport { flattenChildren, isElementOfType } from '../../lib/children';\nimport { cn } from '../../lib/cn';\nimport { avatarGroupClassNames } from '../../lib/classNames';\nimport { warnOnce } from '../../lib/dev';\nimport { avatarSizeClassesFor, type AvatarSize } from './Avatar.sizes';\nimport { AvatarGroupContext } from './AvatarGroup.context';\nimport { partitionAvatarGroupItems, type AvatarGroupLayout } from './AvatarGroup.partition';\nimport {\n AvatarGroupItem,\n AvatarGroupPopover,\n DEFAULT_UNNAMED_MEMBER_LABEL,\n type AvatarGroupItemProps,\n type AvatarGroupOpenChangeDetails,\n type AvatarGroupPopoverProps,\n} from './AvatarGroup.parts';\n\nexport { AvatarGroupItem, AvatarGroupPopover };\nexport type { AvatarGroupItemProps, AvatarGroupOpenChangeDetails, AvatarGroupPopoverProps };\nexport type { AvatarGroupLayout };\n\n/** Properties for the AvatarGroup component. */\nexport interface AvatarGroupProps extends React.HTMLAttributes<HTMLDivElement> {\n /**\n * Maximum number of avatars to display. The others are replaced by an overflow button that\n * lists their names. `0` or a negative value shows only the overflow button, a fraction is\n * rounded down, and `NaN` shows every member (as without `max`). The members of a Fragment\n * count one by one. A `pie` shows at most three.\n */\n max?: number;\n /**\n * Size of the avatars. It reaches the members that set no `size` of their own, and the overflow\n * button.\n * @default 'medium' ('large' in a `pie`)\n */\n size?: AvatarSize;\n /**\n * How the members are laid out: `stack` overlaps them, `spread` puts them side by side, `pie`\n * draws up to three of them as the wedges of one circle (the group's name is then the only name).\n * @default 'stack'\n */\n layout?: AvatarGroupLayout;\n /**\n * What the overflow button shows: the number of hidden members (`+3`, capped at `99+`), or an\n * icon.\n * @default 'count'\n */\n overflowIndicator?: 'count' | 'icon';\n /**\n * Accessible name of the overflow button (and its popup). A function receives the number of\n * hidden members. Localise it here.\n * @default (count) => `${count} more`\n */\n overflowLabel?: string | ((count: number) => string);\n /**\n * Text listed in the overflow popup for a hidden member that has no accessible name (an\n * `Avatar` without `name`, `aria-label`, `aria-labelledby` or image `alt`, or blank text).\n * Localise it here; better still, give every member a name (a development warning asks for it).\n * @default 'Unnamed member'\n */\n unnamedMemberLabel?: string;\n /** Whether the overflow popup is open (controlled). */\n open?: boolean;\n /**\n * Whether the overflow popup starts open (uncontrolled).\n * @default false\n */\n defaultOpen?: boolean;\n /**\n * Called when the overflow popup asks to open or close, with the reason: `trigger` (the button),\n * `escape`, `outside-press` or `focus-outside`.\n */\n onOpenChange?: (open: boolean, details?: AvatarGroupOpenChangeDetails) => void;\n /** Ref to the root `<div>`. */\n ref?: React.Ref<HTMLDivElement>;\n}\n\n/** The clip of each wedge of a pie, by the number of wedges (one wedge is a full circle). Literal strings only. */\nconst pieWedgeClasses: ReadonlyArray<ReadonlyArray<string>> = [\n [''],\n ['[clip-path:inset(0_50%_0_0)]', '[clip-path:inset(0_0_0_50%)]'],\n [\n '[clip-path:inset(0_50%_0_0)]',\n '[clip-path:inset(0_0_50%_50%)]',\n '[clip-path:inset(50%_0_0_50%)]',\n ],\n];\n\nconst AvatarGroupRoot = ({\n max,\n size,\n layout = 'stack',\n overflowIndicator = 'count',\n overflowLabel,\n unnamedMemberLabel = DEFAULT_UNNAMED_MEMBER_LABEL,\n open,\n defaultOpen,\n onOpenChange,\n className,\n children,\n ref,\n 'aria-label': ariaLabel,\n 'aria-labelledby': ariaLabelledBy,\n ...props\n}: AvatarGroupProps) => {\n // Fragments are flattened, so each member counts, overlaps and is listed on its own (C-COMPOUND).\n // A consumer-written AvatarGroup.Popover is the overflow part, not a member.\n const parts = flattenChildren(children);\n const customPopover = parts.find(({ node }) => isElementOfType(node, AvatarGroupPopover));\n const items = parts.filter(({ node }) => !isElementOfType(node, AvatarGroupPopover));\n const resolvedSize: AvatarSize = size ?? (layout === 'pie' ? 'large' : 'medium');\n const { inlineItems: visible, overflowItems } = partitionAvatarGroupItems({\n items,\n maxInlineItems: max,\n layout,\n });\n const hidden = overflowItems ?? [];\n const hasInlineItems = visible.length > 0;\n const groupContext = React.useMemo(\n () => ({ size: resolvedSize, layout, hasInlineItems }),\n [resolvedSize, layout, hasInlineItems],\n );\n\n const unnamed = ariaLabel === undefined && ariaLabelledBy === undefined;\n React.useEffect(() => {\n if (unnamed) {\n warnOnce(\n 'AvatarGroup:unnamed',\n 'AvatarGroup: the group has no accessible name. Pass `aria-label` (or `aria-labelledby`) describing the people it shows.',\n );\n }\n }, [unnamed]);\n\n return (\n <div\n ref={ref}\n role=\"group\"\n aria-label={ariaLabel}\n aria-labelledby={ariaLabelledBy}\n data-layout={layout}\n {...props}\n className={cn(\n avatarGroupClassNames.root,\n 'inline-flex items-center',\n layout !== 'stack' && 'gap-1',\n className,\n )}\n >\n <AvatarGroupContext.Provider value={groupContext}>\n {layout === 'pie'\n ? visible.length > 0 && (\n <span\n className={cn(\n avatarGroupClassNames.pie,\n 'relative inline-block shrink-0 overflow-hidden rounded-full',\n avatarSizeClassesFor(resolvedSize),\n )}\n >\n {visible.map(({ key, node }, i) => (\n <span\n key={key}\n aria-hidden=\"true\"\n className={cn(\n avatarGroupClassNames.item,\n 'absolute inset-0 inline-flex',\n pieWedgeClasses[visible.length - 1]?.[i],\n )}\n >\n {node}\n </span>\n ))}\n </span>\n )\n : visible.map(({ key, node }, i) => (\n <span\n key={key}\n className={cn(\n avatarGroupClassNames.item,\n 'inline-flex rounded-full ring-2 ring-background',\n layout === 'stack' && i > 0 && '-ms-2',\n )}\n >\n {node}\n </span>\n ))}\n {customPopover\n ? customPopover.node\n : hidden.length > 0 && (\n <AvatarGroupPopover\n count={hidden.length}\n indicator={overflowIndicator}\n label={overflowLabel}\n unnamedMemberLabel={unnamedMemberLabel}\n open={open}\n defaultOpen={defaultOpen}\n onOpenChange={onOpenChange}\n >\n {hidden.map(({ key, node }) => (\n <React.Fragment key={key}>{node}</React.Fragment>\n ))}\n </AvatarGroupPopover>\n )}\n </AvatarGroupContext.Provider>\n </div>\n );\n};\n\nAvatarGroupRoot.displayName = 'AvatarGroup';\n\n/**\n * A row of avatars (`role=\"group\"`; name it with `aria-label`), laid out as a `stack` (overlapping),\n * `spread` or `pie` (`layout`). `size` reaches the members.\n *\n * With `max`, the avatars beyond the limit are replaced by an overflow `<button>` (\"+3\", named\n * \"3 more\", see `overflowLabel`; `overflowIndicator=\"icon\"` shows an icon, and a count above 99\n * reads \"99+\"). It toggles a popup that lists the hidden members: an `AvatarGroup.Item` as a row\n * with its avatar and name, an `Avatar` by its `aria-label` or `name` prop, text as it is. Other\n * members, such as an `Avatar` inside a link or one labelled by `aria-labelledby`, are rendered as\n * they are, and an `Avatar` or text with no accessible name is listed as `unnamedMemberLabel` with\n * a development warning. Focus moves into the popup; Escape, a press outside or the button close\n * it and focus returns to the button (`open`, `defaultOpen` and `onOpenChange(open, details)`\n * control it). Tab and Shift+Tab move through the popup's own tab stops (links in rendered\n * members); Tab from the last one closes the popup and moves on to the element after the button,\n * Shift+Tab from the first one closes it and returns to the button. When the button is the last\n * tab stop (of the page, or of the Wave layer the group is in, such as a dialog), Tab is left to\n * the browser or the enclosing focus trap.\n *\n * To split the members yourself, render `AvatarGroup.Item`s and an `AvatarGroup.Popover` holding\n * the overflow items (see `partitionAvatarGroupItems`).\n *\n * @example\n * <AvatarGroup aria-label=\"Project team\" max={3}>\n * <AvatarGroup.Item name=\"Ada Lovelace\" />\n * <AvatarGroup.Item name=\"Alan Turing\" />\n * </AvatarGroup>\n */\nexport const AvatarGroup = /* @__PURE__ */ Object.assign(AvatarGroupRoot, {\n Item: AvatarGroupItem,\n Popover: AvatarGroupPopover,\n});\n"],"mappings":"4aA8EA,IAAMsB,EAAwD,CAC5D,CAAC,EAAE,EACH,CAAC,+BAAgC,8BAA8B,EAC/D,CACE,+BACA,iCACA,gCACF,CACF,EAEMC,GAAmB,CACvB,MACA,OACA,SAAS,QACT,oBAAoB,QACpB,gBACA,qBAAqBvB,EAAAA,6BACrB,OACA,cACA,eACA,YACA,WACA,MACA,aAAcwB,EACd,kBAAmBC,EACnB,GAAGC,KACmB,CAGtB,IAAMC,EAAQ1B,EAAAA,gBAAgB2B,CAAQ,EAChCC,EAAgBF,EAAM,MAAM,CAAE,UAAWzB,EAAAA,gBAAgB4B,EAAM3B,EAAAA,kBAAkB,CAAC,EAClF4B,EAAQJ,EAAM,QAAQ,CAAE,UAAW,CAACzB,EAAAA,gBAAgB4B,EAAM3B,EAAAA,kBAAkB,CAAC,EAC7E6B,EAA2BC,IAASC,IAAW,MAAQ,QAAU,UACjE,CAAE,YAAaC,EAAS,iBAAkB/B,EAAAA,0BAA0B,CACxE,QACA,eAAgBgC,EAChB,QACF,CAAC,EACKC,EAASC,GAAiB,CAAC,EAC3BC,EAAiBJ,EAAQ,OAAS,EAClCK,EAAenC,EAAM,aAClB,CAAE,KAAM2B,EAAc,SAAQ,gBAAe,GACpD,CAACA,EAAcE,EAAQK,CAAc,CACvC,EAEME,EAAUjB,IAAc,IAAA,IAAaC,IAAmB,IAAA,GAU9D,OATAL,EAA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AAA,CAEC,GAC1B,CAAA,CAET,EAEA,EAAgB,YAAc,cA6B9B,IAAaG,EAA8B,OAAO,OAAOxB,EAAiB,CACxE,KAAMb,EAAAA,gBACN,QAASP,EAAAA,kBACX,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AvatarGroup.context.cjs","names":["React","require_runtime","react","AvatarGroupContext"],"sources":["../../../src/components/data-display/AvatarGroup.context.ts"],"sourcesContent":["import * as React from 'react';\nimport type { AvatarGroupLayout } from './AvatarGroup.partition';\nimport type { AvatarSize } from './Avatar.sizes';\n\n/*\n * What an AvatarGroup gives the Avatars inside it. Internal (never exported from a barrel); imports\n * no component, so an Avatar that reads it holds no AvatarGroup code.\n */\n\n/** The size and layout of the enclosing AvatarGroup. Internal. */\nexport interface AvatarGroupContextValue {\n /** The size an Avatar without its own `size` takes. */\n size: AvatarSize;\n /** The layout of the group. */\n layout: AvatarGroupLayout;\n /** Whether the group shows any member inline (the overflow button overlaps it in a stack). */\n hasInlineItems: boolean;\n}\n\n/** Internal: provided by AvatarGroup around its members; `null` elsewhere. */\nexport const AvatarGroupContext = React.createContext<AvatarGroupContextValue | null>(null);\nAvatarGroupContext.displayName = 'AvatarGroupContext';\n"],"mappings":"6GAoBA,IAAaG,EAAqBH,EAAM,cAA8C,IAAI,EAC1F,EAAmB,YAAc"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import * as e from "react";
|
|
3
|
+
//#region src/components/data-display/AvatarGroup.context.ts
|
|
4
|
+
var t = e.createContext(null);
|
|
5
|
+
t.displayName = "AvatarGroupContext";
|
|
6
|
+
//#endregion
|
|
7
|
+
export { t as AvatarGroupContext };
|
|
8
|
+
|
|
9
|
+
//# sourceMappingURL=AvatarGroup.context.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AvatarGroup.context.mjs","names":["React","AvatarGroupContext"],"sources":["../../../src/components/data-display/AvatarGroup.context.ts"],"sourcesContent":["import * as React from 'react';\nimport type { AvatarGroupLayout } from './AvatarGroup.partition';\nimport type { AvatarSize } from './Avatar.sizes';\n\n/*\n * What an AvatarGroup gives the Avatars inside it. Internal (never exported from a barrel); imports\n * no component, so an Avatar that reads it holds no AvatarGroup code.\n */\n\n/** The size and layout of the enclosing AvatarGroup. Internal. */\nexport interface AvatarGroupContextValue {\n /** The size an Avatar without its own `size` takes. */\n size: AvatarSize;\n /** The layout of the group. */\n layout: AvatarGroupLayout;\n /** Whether the group shows any member inline (the overflow button overlaps it in a stack). */\n hasInlineItems: boolean;\n}\n\n/** Internal: provided by AvatarGroup around its members; `null` elsewhere. */\nexport const AvatarGroupContext = React.createContext<AvatarGroupContextValue | null>(null);\nAvatarGroupContext.displayName = 'AvatarGroupContext';\n"],"mappings":";;;AAoBA,IAAaC,IAAqBD,EAAM,cAA8C,IAAI;AAC1F,EAAmB,cAAc"}
|
|
@@ -3,133 +3,76 @@ import { cn as e } from "../../lib/cn.mjs";
|
|
|
3
3
|
import { flattenChildren as t, isElementOfType as n } from "../../lib/children.mjs";
|
|
4
4
|
import { warnOnce as r } from "../../lib/dev.mjs";
|
|
5
5
|
import { avatarGroupClassNames as i } from "../../lib/classNames.mjs";
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import
|
|
11
|
-
import {
|
|
12
|
-
import "../../lib/styles.mjs";
|
|
13
|
-
import { usePopupPosition as f } from "../../hooks/usePopupPosition.mjs";
|
|
14
|
-
import { useRestoreFocus as p } from "../../hooks/useRestoreFocus.mjs";
|
|
15
|
-
import { Avatar as m, avatarSizeClasses as h } from "./Avatar.mjs";
|
|
16
|
-
import * as g from "react";
|
|
17
|
-
import { jsx as _, jsxs as v } from "react/jsx-runtime";
|
|
6
|
+
import { AvatarGroupContext as a } from "./AvatarGroup.context.mjs";
|
|
7
|
+
import { avatarSizeClassesFor as o } from "./Avatar.sizes.mjs";
|
|
8
|
+
import { partitionAvatarGroupItems as s } from "./AvatarGroup.partition.mjs";
|
|
9
|
+
import { AvatarGroupItem as c, AvatarGroupPopover as l, DEFAULT_UNNAMED_MEMBER_LABEL as u } from "./AvatarGroup.parts.mjs";
|
|
10
|
+
import * as d from "react";
|
|
11
|
+
import { jsx as f, jsxs as p } from "react/jsx-runtime";
|
|
18
12
|
//#region src/components/data-display/AvatarGroup.tsx
|
|
19
|
-
var
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
open: z,
|
|
46
|
-
side: "bottom",
|
|
47
|
-
align: "start"
|
|
48
|
-
}), { layerId: Y } = u({
|
|
49
|
-
open: z,
|
|
50
|
-
onDismiss: () => R(!1),
|
|
51
|
-
refs: [H, U],
|
|
52
|
-
anchorRef: H,
|
|
53
|
-
focusOutside: !0
|
|
54
|
-
});
|
|
55
|
-
p({
|
|
56
|
-
enabled: z,
|
|
57
|
-
container: W,
|
|
58
|
-
triggerRef: H,
|
|
59
|
-
onlyIfFocusInside: !0
|
|
60
|
-
});
|
|
61
|
-
let X = s(H, K), Z = s(U, q, G);
|
|
62
|
-
g.useEffect(() => {
|
|
63
|
-
z && W && W.focus({ preventScroll: !0 });
|
|
64
|
-
}, [z, W]);
|
|
65
|
-
let Q = (e) => {
|
|
66
|
-
let t = H.current;
|
|
67
|
-
if (e.key !== "Tab" || e.defaultPrevented || !t) return;
|
|
68
|
-
let n = e.currentTarget, r = e.target;
|
|
69
|
-
if (!r || typeof r.nodeType != "number" || !n.contains(r)) return;
|
|
70
|
-
let i = o(n), a = i.findIndex((e) => e.contains(r)) + (e.shiftKey ? -1 : 1);
|
|
71
|
-
if (a >= 0 && a < i.length) {
|
|
72
|
-
e.preventDefault(), i[a].focus();
|
|
73
|
-
return;
|
|
74
|
-
}
|
|
75
|
-
let s = t;
|
|
76
|
-
if (!e.shiftKey) {
|
|
77
|
-
let e = o(t.ownerDocument.body).filter((e) => !n.contains(e)), r = e.indexOf(t);
|
|
78
|
-
s = r === -1 ? t : e[r + 1], s && V !== null && !c(V, s) && (s = void 0);
|
|
79
|
-
}
|
|
80
|
-
R(!1), s && (e.preventDefault(), s.focus());
|
|
81
|
-
}, $ = z && N.some(({ node: e }) => x(e) === void 0 && S(e));
|
|
82
|
-
return g.useEffect(() => {
|
|
83
|
-
$ && r("AvatarGroup:unnamed-member", `AvatarGroup: a hidden member has no accessible name and is listed as "${C}". Give each member a \`name\` or \`aria-label\`.`);
|
|
84
|
-
}, [$, C]), /* @__PURE__ */ v("div", {
|
|
85
|
-
ref: E,
|
|
13
|
+
var m = [
|
|
14
|
+
[""],
|
|
15
|
+
["[clip-path:inset(0_50%_0_0)]", "[clip-path:inset(0_0_0_50%)]"],
|
|
16
|
+
[
|
|
17
|
+
"[clip-path:inset(0_50%_0_0)]",
|
|
18
|
+
"[clip-path:inset(0_0_50%_50%)]",
|
|
19
|
+
"[clip-path:inset(50%_0_0_50%)]"
|
|
20
|
+
]
|
|
21
|
+
], h = ({ max: c, size: h, layout: g = "stack", overflowIndicator: _ = "count", overflowLabel: v, unnamedMemberLabel: y = u, open: b, defaultOpen: x, onOpenChange: S, className: C, children: w, ref: T, "aria-label": E, "aria-labelledby": D, ...O }) => {
|
|
22
|
+
let k = t(w), A = k.find(({ node: e }) => n(e, l)), j = k.filter(({ node: e }) => !n(e, l)), M = h ?? (g === "pie" ? "large" : "medium"), { inlineItems: N, overflowItems: P } = s({
|
|
23
|
+
items: j,
|
|
24
|
+
maxInlineItems: c,
|
|
25
|
+
layout: g
|
|
26
|
+
}), F = P ?? [], I = N.length > 0, L = d.useMemo(() => ({
|
|
27
|
+
size: M,
|
|
28
|
+
layout: g,
|
|
29
|
+
hasInlineItems: I
|
|
30
|
+
}), [
|
|
31
|
+
M,
|
|
32
|
+
g,
|
|
33
|
+
I
|
|
34
|
+
]), R = E === void 0 && D === void 0;
|
|
35
|
+
return d.useEffect(() => {
|
|
36
|
+
R && r("AvatarGroup:unnamed", "AvatarGroup: the group has no accessible name. Pass `aria-label` (or `aria-labelledby`) describing the people it shows.");
|
|
37
|
+
}, [R]), /* @__PURE__ */ f("div", {
|
|
38
|
+
ref: T,
|
|
86
39
|
role: "group",
|
|
87
|
-
"aria-label":
|
|
88
|
-
"aria-labelledby":
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
40
|
+
"aria-label": E,
|
|
41
|
+
"aria-labelledby": D,
|
|
42
|
+
"data-layout": g,
|
|
43
|
+
...O,
|
|
44
|
+
className: e(i.root, "inline-flex items-center", g !== "stack" && "gap-1", C),
|
|
45
|
+
children: /* @__PURE__ */ p(a.Provider, {
|
|
46
|
+
value: L,
|
|
47
|
+
children: [g === "pie" ? N.length > 0 && /* @__PURE__ */ f("span", {
|
|
48
|
+
className: e(i.pie, "relative inline-block shrink-0 overflow-hidden rounded-full", o(M)),
|
|
49
|
+
children: N.map(({ key: t, node: n }, r) => /* @__PURE__ */ f("span", {
|
|
50
|
+
"aria-hidden": "true",
|
|
51
|
+
className: e(i.item, "absolute inset-0 inline-flex", m[N.length - 1]?.[r]),
|
|
52
|
+
children: n
|
|
53
|
+
}, t))
|
|
54
|
+
}) : N.map(({ key: t, node: n }, r) => /* @__PURE__ */ f("span", {
|
|
55
|
+
className: e(i.item, "inline-flex rounded-full ring-2 ring-background", g === "stack" && r > 0 && "-ms-2"),
|
|
94
56
|
children: n
|
|
95
|
-
}, t)),
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
}),
|
|
107
|
-
z && /* @__PURE__ */ _(d, {
|
|
108
|
-
layerId: Y,
|
|
109
|
-
children: /* @__PURE__ */ _("div", {
|
|
110
|
-
ref: Z,
|
|
111
|
-
id: I,
|
|
112
|
-
role: "dialog",
|
|
113
|
-
"aria-label": B,
|
|
114
|
-
tabIndex: -1,
|
|
115
|
-
"data-state": "open",
|
|
116
|
-
...J,
|
|
117
|
-
className: e(i.surface, "min-w-32 max-w-xs rounded-md border border-border bg-background p-2 text-body-1 text-foreground shadow-16", "focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-ring"),
|
|
118
|
-
onKeyDown: Q,
|
|
119
|
-
children: /* @__PURE__ */ _("ul", {
|
|
120
|
-
className: e(i.list, "m-0 flex list-none flex-col gap-1 p-0"),
|
|
121
|
-
children: N.map(({ key: t, node: n }) => /* @__PURE__ */ _("li", {
|
|
122
|
-
className: e(i.listItem, "px-1 py-0.5"),
|
|
123
|
-
children: x(n) ?? (S(n) ? C : n)
|
|
124
|
-
}, t))
|
|
125
|
-
})
|
|
126
|
-
})
|
|
127
|
-
})
|
|
128
|
-
]
|
|
57
|
+
}, t)), A ? A.node : F.length > 0 && /* @__PURE__ */ f(l, {
|
|
58
|
+
count: F.length,
|
|
59
|
+
indicator: _,
|
|
60
|
+
label: v,
|
|
61
|
+
unnamedMemberLabel: y,
|
|
62
|
+
open: b,
|
|
63
|
+
defaultOpen: x,
|
|
64
|
+
onOpenChange: S,
|
|
65
|
+
children: F.map(({ key: e, node: t }) => /* @__PURE__ */ f(d.Fragment, { children: t }, e))
|
|
66
|
+
})]
|
|
67
|
+
})
|
|
129
68
|
});
|
|
130
69
|
};
|
|
131
|
-
|
|
70
|
+
h.displayName = "AvatarGroup";
|
|
71
|
+
var g = /* @__PURE__ */ Object.assign(h, {
|
|
72
|
+
Item: c,
|
|
73
|
+
Popover: l
|
|
74
|
+
});
|
|
132
75
|
//#endregion
|
|
133
|
-
export {
|
|
76
|
+
export { g as AvatarGroup, c as AvatarGroupItem, l as AvatarGroupPopover };
|
|
134
77
|
|
|
135
78
|
//# sourceMappingURL=AvatarGroup.mjs.map
|