An open source design system that's fully customizable and agent ready
TypeScript
feat(core): add XDSAvatarGroup component (#2183)
Andrey Goder641294e12c80
diff --git a/apps/storybook/stories/AvatarGroup.stories.tsx b/apps/storybook/stories/AvatarGroup.stories.tsxnew file mode 100644index 0000000000..f4ab9134c8--- /dev/null+++ b/apps/storybook/stories/AvatarGroup.stories.tsx@@ -0,0 +1,150 @@+// Copyright (c) Meta Platforms, Inc. and affiliates.+import type {Meta, StoryObj} from '@storybook/react';+import * as stylex from '@stylexjs/stylex';+import {XDSAvatarGroup, XDSAvatarGroupOverflow} from '@xds/core/AvatarGroup';+import {XDSAvatar} from '@xds/core/Avatar';+import {spacingVars, typographyVars} from '@xds/core/theme/tokens.stylex';++const USERS = [+ {name: 'Alice Johnson', src: 'https://i.pravatar.cc/150?img=1', key: 'alice'},+ {name: 'Bob Smith', src: 'https://i.pravatar.cc/150?img=2', key: 'bob'},+ {+ name: 'Charlie Davis',+ src: 'https://i.pravatar.cc/150?img=3',+ key: 'charlie',+ },+ {name: 'Diana Lee', src: 'https://i.pravatar.cc/150?img=4', key: 'diana'},+ {name: 'Eve Park', src: 'https://i.pravatar.cc/150?img=5', key: 'eve'},+];++const storyStyles = stylex.create({+ storyWrapper: {+ display: 'flex',+ flexDirection: 'column',+ gap: spacingVars['--spacing-6'],+ },+ heading: {+ margin: `0 0 ${spacingVars['--spacing-2']} 0`,+ fontFamily: typographyVars['--font-family-body'],+ },+});++const meta: Meta<typeof XDSAvatarGroup> = {+ title: 'Core/AvatarGroup',+ component: XDSAvatarGroup,+ tags: ['autodocs'],+ argTypes: {+ size: {+ control: 'select',+ options: ['tiny', 'xsmall', 'small', 'medium', 'large'],+ description: 'Size applied to all child avatars',+ },+ },+};++export default meta;+type Story = StoryObj<typeof XDSAvatarGroup>;++/** Basic avatar group showing all members. */+export const Default: Story = {+ render: () => (+ <XDSAvatarGroup size="medium">+ {USERS.slice(0, 3).map(u => (+ <XDSAvatar key={u.key} src={u.src} name={u.name} />+ ))}+ </XDSAvatarGroup>+ ),+};++/** Sliced to 3 with "+N" overflow indicator. */+export const WithOverflow: Story = {+ render: () => (+ <XDSAvatarGroup size="medium">+ {USERS.slice(0, 3).map(u => (+ <XDSAvatar key={u.key} src={u.src} name={u.name} />+ ))}+ <XDSAvatarGroupOverflow count={USERS.length - 3} />+ </XDSAvatarGroup>+ ),+};++/** Clickable overflow indicator. */+export const ClickableOverflow: Story = {+ render: () => (+ <XDSAvatarGroup size="medium">+ {USERS.slice(0, 3).map(u => (+ <XDSAvatar key={u.key} src={u.src} name={u.name} />+ ))}+ <XDSAvatarGroupOverflow+ count={USERS.length - 3}+ onClick={() => alert('Show all participants')}+ />+ </XDSAvatarGroup>+ ),+};++/** Server-side total count (47 participants, only 3 rendered). */+export const ServerSideCount: Story = {+ render: () => (+ <XDSAvatarGroup size="medium">+ {USERS.slice(0, 3).map(u => (+ <XDSAvatar key={u.key} src={u.src} name={u.name} />+ ))}+ <XDSAvatarGroupOverflow count={44} />+ </XDSAvatarGroup>+ ),+};++/** Per-avatar status dots — just works with compositional API. */+export const WithStatusDots: Story = {+ render: () => (+ <XDSAvatarGroup size="medium">+ <XDSAvatar+ src="https://i.pravatar.cc/150?img=1"+ name="Alice"+ statusDot={{color: 'positive'}}+ />+ <XDSAvatar+ src="https://i.pravatar.cc/150?img=2"+ name="Bob"+ statusDot={{color: 'warning'}}+ />+ <XDSAvatar+ src="https://i.pravatar.cc/150?img=3"+ name="Charlie"+ statusDot={{color: 'negative'}}+ />+ </XDSAvatarGroup>+ ),+};++/** All sizes side by side. */+export const AllSizes: Story = {+ render: () => (+ <div {...stylex.props(storyStyles.storyWrapper)}>+ {(['tiny', 'xsmall', 'small', 'medium', 'large'] as const).map(size => (+ <div key={size}>+ <h4 {...stylex.props(storyStyles.heading)}>{size}</h4>+ <XDSAvatarGroup size={size}>+ {USERS.slice(0, 3).map(u => (+ <XDSAvatar key={u.key} src={u.src} name={u.name} />+ ))}+ <XDSAvatarGroupOverflow count={USERS.length - 3} />+ </XDSAvatarGroup>+ </div>+ ))}+ </div>+ ),+};++/** Initials fallback when no images provided. */+export const InitialsFallback: Story = {+ render: () => (+ <XDSAvatarGroup size="medium">+ {USERS.slice(0, 4).map(u => (+ <XDSAvatar key={u.key} name={u.name} />+ ))}+ <XDSAvatarGroupOverflow count={1} />+ </XDSAvatarGroup>+ ),+};diff --git a/packages/cli/templates/blocks/components/AvatarGroup/AvatarGroupShowcase.doc.mjs b/packages/cli/templates/blocks/components/AvatarGroup/AvatarGroupShowcase.doc.mjsnew file mode 100644index 0000000000..65eb1752e5--- /dev/null+++ b/packages/cli/templates/blocks/components/AvatarGroup/AvatarGroupShowcase.doc.mjs@@ -0,0 +1,13 @@+// Copyright (c) Meta Platforms, Inc. and affiliates.+/** @type {import('../../../../../core/src/docs-types').TemplateDoc} */+export const doc = {+ type: 'block',+ exampleFor: 'AvatarGroup',+ name: 'AvatarGroup',+ description:+ 'Overlapping avatar rows with max limit and server-side overflow count. Shows team members in a compact facepile layout.',+ isReady: true,+ isShowcase: true,+ aspectRatio: 16 / 9,+ componentsUsed: ['AvatarGroup', 'Avatar', 'Layout', 'Text'],+};diff --git a/packages/cli/templates/blocks/components/AvatarGroup/AvatarGroupShowcase.tsx b/packages/cli/templates/blocks/components/AvatarGroup/AvatarGroupShowcase.tsxnew file mode 100644index 0000000000..27adc643a4--- /dev/null+++ b/packages/cli/templates/blocks/components/AvatarGroup/AvatarGroupShowcase.tsx@@ -0,0 +1,63 @@+// Copyright (c) Meta Platforms, Inc. and affiliates.+'use client';++import {XDSAvatarGroup, XDSAvatarGroupOverflow} from '@xds/core/AvatarGroup';+import {XDSAvatar} from '@xds/core/Avatar';+import {XDSStack} from '@xds/core/Layout';+import {XDSText} from '@xds/core/Text';++const USERS = [+ {+ name: 'Alex Daniels',+ src: 'https://lookaside.facebook.com/assets/vs_datakit_profile_photos_t66173184/VS-Design-Tools-Datakit-05.jpg',+ key: 'alex',+ },+ {+ name: 'Ann Smith',+ src: 'https://lookaside.facebook.com/assets/vs_datakit_profile_photos_t66173184/VS-Design-Tools-Datakit-30.jpg',+ key: 'ann',+ },+ {+ name: 'Carol Davis',+ src: 'https://lookaside.facebook.com/assets/vs_datakit_profile_photos_t66173184/VS-Design-Tools-Datakit-60.jpg',+ key: 'carol',+ },+ {+ name: 'Gina Wilson',+ src: 'https://lookaside.facebook.com/assets/vs_datakit_profile_photos_t66173184/VS-Design-Tools-Datakit-98.jpg',+ key: 'gina',+ },+ {+ name: 'Eve Park',+ src: 'https://lookaside.facebook.com/assets/vs_datakit_profile_photos_t66173184/VS-Design-Tools-Datakit-125.jpg',+ key: 'eve',+ },+];++export default function AvatarGroupShowcase() {+ return (+ <XDSStack direction="vertical" gap={8}>+ <XDSStack direction="vertical" gap={3}>+ <XDSText type="supporting" color="secondary">+ Team members+ </XDSText>+ <XDSAvatarGroup size="medium">+ {USERS.map(u => (+ <XDSAvatar key={u.key} src={u.src} name={u.name} />+ ))}+ </XDSAvatarGroup>+ </XDSStack>+ <XDSStack direction="vertical" gap={3}>+ <XDSText type="supporting" color="secondary">+ With overflow+ </XDSText>+ <XDSAvatarGroup size="medium">+ {USERS.slice(0, 3).map(u => (+ <XDSAvatar key={u.key} src={u.src} name={u.name} />+ ))}+ <XDSAvatarGroupOverflow count={USERS.length - 3} />+ </XDSAvatarGroup>+ </XDSStack>+ </XDSStack>+ );+}diff --git a/packages/core/package.json b/packages/core/package.jsonindex 482d554d47..485e3dd865 100644--- a/packages/core/package.json+++ b/packages/core/package.json@@ -91,6 +91,12 @@"import": "./dist/Avatar/index.mjs","require": "./dist/Avatar/index.js"},+ "./AvatarGroup": {+ "source": "./src/AvatarGroup/index.ts",+ "types": "./dist/AvatarGroup/index.d.ts",+ "import": "./dist/AvatarGroup/index.mjs",+ "require": "./dist/AvatarGroup/index.js"+ },"./Badge": {"source": "./src/Badge/index.ts","types": "./dist/Badge/index.d.ts",diff --git a/packages/core/src/Avatar/XDSAvatar.tsx b/packages/core/src/Avatar/XDSAvatar.tsxindex 07669dfba0..5a15d229bb 100644--- a/packages/core/src/Avatar/XDSAvatar.tsx+++ b/packages/core/src/Avatar/XDSAvatar.tsx@@ -25,6 +25,7 @@ import {radiusVars,} from '../theme/tokens.stylex';import {XDSAvatarSizeContext} from './XDSAvatarSizeContext';+import {useXDSAvatarGroup} from '../AvatarGroup/XDSAvatarGroupContext';import {xdsClassName, mergeProps} from '../utils';/**@@ -84,7 +85,7 @@ export type XDSAvatarSize = XDSAvatarNamedSize | XDSAvatarNumericSize;/*** Resolves named sizes to their numeric pixel values*/-function resolveSize(size: XDSAvatarSize): number {+export function resolveSize(size: XDSAvatarSize): number {if (typeof size === 'number') {return size;}@@ -156,11 +157,35 @@ const dynamicStyles = stylex.create({statusPosition: (size: number) => ({bottom: size * CIRCLE_EDGE_OFFSET_RATIO,right: size * CIRCLE_EDGE_OFFSET_RATIO,- // Shift by half the element's size to center it on the circle edgetransform: 'translate(50%, 50%)',}),});+const BORDER_WIDTH = 2;++const groupStyles = stylex.create({+ ring: {+ borderRadius: radiusVars['--radius-full'],+ borderWidth: BORDER_WIDTH,+ borderStyle: 'solid',+ borderColor: colorVars['--color-background-surface'],+ backgroundColor: colorVars['--color-background-surface'],+ boxSizing: 'content-box',+ },+ overlap: {+ marginInlineStart: {+ default: null,+ ':not(:first-child)': 'var(--_avatar-group-overlap)',+ },+ },+});++const groupDynamicStyles = stylex.create({+ overlap: (offset: number) => ({+ '--_avatar-group-overlap': `${offset}px`,+ }),+});+export interface XDSAvatarProps extends XDSBaseProps<HTMLDivElement> {/** Ref forwarded to the root element */ref?: React.Ref<HTMLDivElement>;@@ -268,7 +293,9 @@ export function XDSAvatar({const showIcon = !showImage && !showFallbackImage && !name;const accessibleName = alt || name || 'Avatar';- const numericSize = useMemo(() => resolveSize(size), [size]);+ const avatarGroup = useXDSAvatarGroup();+ const resolvedSize = avatarGroup?.size ?? size;+ const numericSize = useMemo(() => resolveSize(resolvedSize), [resolvedSize]);return (<XDSAvatarSizeContext.Provider value={numericSize}>@@ -278,8 +305,14 @@ export function XDSAvatar({aria-label={accessibleName}data-testid={testId}{...mergeProps(- xdsClassName('avatar', {size}),- stylex.props(styles.wrapper, xstyle),+ xdsClassName('avatar', {size: resolvedSize}),+ stylex.props(+ styles.wrapper,+ avatarGroup && groupStyles.ring,+ avatarGroup && groupStyles.overlap,+ avatarGroup && groupDynamicStyles.overlap(-avatarGroup.overlap),+ xstyle,+ ),className,style,)}diff --git a/packages/core/src/Avatar/index.ts b/packages/core/src/Avatar/index.tsindex fcc31a727f..46e8fbefaa 100644--- a/packages/core/src/Avatar/index.ts+++ b/packages/core/src/Avatar/index.ts@@ -11,7 +11,7 @@* SYNC: When modified, update this header and /packages/core/src/Avatar/Avatar.doc.mjs*/-export {XDSAvatar} from './XDSAvatar';+export {XDSAvatar, resolveSize} from './XDSAvatar';export type {XDSAvatarProps, XDSAvatarSize} from './XDSAvatar';export {XDSAvatarStatusDot} from './XDSAvatarStatusDot';export type {diff --git a/packages/core/src/AvatarGroup/AvatarGroup.doc.mjs b/packages/core/src/AvatarGroup/AvatarGroup.doc.mjsnew file mode 100644index 0000000000..0b34ec4eca--- /dev/null+++ b/packages/core/src/AvatarGroup/AvatarGroup.doc.mjs@@ -0,0 +1,118 @@+// Copyright (c) Meta Platforms, Inc. and affiliates.+/** @type {import('../docs-types').ComponentDoc} */++export const docs = {+ name: 'AvatarGroup',+ group: 'Avatar',+ keywords: ['avatar', 'group', 'facepile', 'stack', 'overlap', 'participants', 'assignees', 'members', 'team'],+ usage: {+ description:+ 'AvatarGroup displays multiple avatars in an overlapping row with an optional overflow indicator. Uses a compositional API — pass XDSAvatar children directly so each avatar can carry its own props (status dots, click handlers, etc.).',+ bestPractices: [+ {guidance: true, description: 'Set max to limit visible avatars when the list is long — 3-5 is typical.'},+ {guidance: true, description: 'Use XDSAvatarGroupOverflow for custom overflow content like a popover trigger or "add member" button.'},+ {guidance: true, description: 'Pass status dots, click handlers, or tooltips directly on each XDSAvatar child.'},+ {guidance: false, description: "Don't nest AvatarGroups — use a single group with all avatars."},+ ],+ anatomy: [+ {name: 'Avatar children', required: true, description: 'XDSAvatar elements that form the overlapping row. Each can have its own props.'},+ {name: 'Overflow indicator', required: false, description: 'A "+N" circle at the end showing hidden count, or a custom XDSAvatarGroupOverflow slot.'},+ ],+ },+ theming: {+ targets: [+ {className: 'xds-avatar-group', visualProps: ['size']},+ ],+ },+ components: [+ {+ name: 'XDSAvatarGroup',+ description: 'Stacked avatar display with overlapping layout and optional overflow indicator. Children are XDSAvatar elements.',+ props: [+ {name: 'children', type: 'ReactNode', description: 'XDSAvatar children, optionally followed by one XDSAvatarGroupOverflow. Consumers handle slicing to the desired visible count.', required: true, slotElements: [{__element: 'XDSAvatar', props: {name: 'User'}}]},+ {name: 'size', type: 'XDSAvatarSize', description: 'Size applied to all avatars via context.', default: "'small'"},+ {name: 'ref', type: 'React.Ref<HTMLDivElement>', description: 'Ref forwarded to the root element.'},+ {name: 'xstyle', type: 'StyleXStyles', description: 'StyleX styles for layout customization.'},+ {name: 'data-testid', type: 'string', description: 'Test selector for automated testing frameworks.'},+ ],+ },+ {+ name: 'XDSAvatarGroupOverflow',+ description: 'Slot for custom overflow content inside XDSAvatarGroup. Replaces the default "+N" indicator when present.',+ props: [+ {name: 'children', type: 'ReactNode', description: 'Custom overflow content (button, popover trigger, etc.).', required: true},+ ],+ },+ ],+};++/** @type {import('../docs-types').TranslationDoc} */+export const docsZh = {+ usage: {+ description:+ 'AvatarGroup 以重叠排列方式显示多个头像,并可选择显示溢出指示器。使用组合式 API — 直接传入 XDSAvatar 子元素,每个头像可携带自己的属性。',+ bestPractices: [+ {guidance: true, description: '当列表较长时设置 max 来限制可见头像数量 — 通常 3-5 个为佳。'},+ {guidance: true, description: '使用 XDSAvatarGroupOverflow 自定义溢出内容,如弹出触发器或"添加成员"按钮。'},+ {guidance: true, description: '直接在每个 XDSAvatar 子元素上传递状态点、点击处理器或工具提示。'},+ {guidance: false, description: '不要嵌套 AvatarGroup — 使用单个组包含所有头像。'},+ ],+ },+ components: [+ {+ name: 'XDSAvatarGroup',+ description: '重叠布局的堆叠头像显示,带可选溢出指示器。子元素为 XDSAvatar。',+ propDescriptions: {+ children: 'XDSAvatar 子元素,可选地后跟一个 XDSAvatarGroupOverflow。',+ max: '溢出指示器出现前显示的最大头像数。',+ size: '应用于所有头像的大小。',+ ref: '转发到根元素的引用。',+ xstyle: 'StyleX 样式,用于布局自定义。',+ 'data-testid': '自动化测试的选择器。',+ },+ },+ {+ name: 'XDSAvatarGroupOverflow',+ description: 'XDSAvatarGroup 内的自定义溢出内容插槽。存在时替换默认的 "+N" 指示器。',+ propDescriptions: {+ children: '自定义溢出内容(按钮、弹出触发器等)。',+ },+ },+ ],+};++/** @type {import('../docs-types').TranslationDoc} */+export const docsDense = {+ description: 'compositional overlapping avatar row w/ +N overflow or custom slot',+ usage: {+ description:+ 'Stacked avatar display with overlapping layout. Compositional API — XDSAvatar children with per-avatar props (status dots, clicks). Optional XDSAvatarGroupOverflow slot for custom overflow.',+ bestPractices: [+ {guidance: true, description: 'Set max to limit visible avatars (3-5 typical).'},+ {guidance: true, description: 'Use XDSAvatarGroupOverflow for custom overflow (popover, add button).'},+ {guidance: true, description: 'Pass status dots / click handlers directly on each XDSAvatar.'},+ {guidance: false, description: "Don't nest AvatarGroups."},+ ],+ },+ components: [+ {+ name: 'XDSAvatarGroup',+ description: 'overlapping avatar row w/ max truncation',+ propDescriptions: {+ children: 'XDSAvatar children + optional XDSAvatarGroupOverflow',+ max: 'max avatars before overflow',+ size: 'size for all avatars',+ ref: 'ref to root element',+ xstyle: 'StyleX layout styles',+ 'data-testid': 'test selector',+ },+ },+ {+ name: 'XDSAvatarGroupOverflow',+ description: 'custom overflow slot, replaces default +N',+ propDescriptions: {+ children: 'custom overflow content',+ },+ },+ ],+};diff --git a/packages/core/src/AvatarGroup/XDSAvatarGroup.test.tsx b/packages/core/src/AvatarGroup/XDSAvatarGroup.test.tsxnew file mode 100644index 0000000000..2c8f324217--- /dev/null+++ b/packages/core/src/AvatarGroup/XDSAvatarGroup.test.tsx@@ -0,0 +1,151 @@+// Copyright (c) Meta Platforms, Inc. and affiliates.+import {describe, it, expect, vi} from 'vitest';+import {render, screen} from '@testing-library/react';+import userEvent from '@testing-library/user-event';+import {XDSAvatarGroup} from './XDSAvatarGroup';+import {XDSAvatarGroupOverflow} from './XDSAvatarGroupOverflow';+import {XDSAvatar} from '../Avatar';++describe('XDSAvatarGroup', () => {+ it('renders all avatar children', () => {+ render(+ <XDSAvatarGroup>+ <XDSAvatar name="Alice" />+ <XDSAvatar name="Bob" />+ <XDSAvatar name="Charlie" />+ </XDSAvatarGroup>,+ );++ expect(screen.getByLabelText('Alice')).toBeInTheDocument();+ expect(screen.getByLabelText('Bob')).toBeInTheDocument();+ expect(screen.getByLabelText('Charlie')).toBeInTheDocument();+ });++ it('renders with role="group" and default aria-label', () => {+ render(+ <XDSAvatarGroup>+ <XDSAvatar name="Alice" />+ </XDSAvatarGroup>,+ );++ expect(screen.getByRole('group')).toHaveAttribute('aria-label', 'Avatars');+ });++ it('accepts a custom aria-label', () => {+ render(+ <XDSAvatarGroup aria-label="Team members">+ <XDSAvatar name="Alice" />+ </XDSAvatarGroup>,+ );++ expect(screen.getByRole('group')).toHaveAttribute(+ 'aria-label',+ 'Team members',+ );+ });++ it('applies data-testid', () => {+ render(+ <XDSAvatarGroup data-testid="avatar-group">+ <XDSAvatar name="Alice" />+ </XDSAvatarGroup>,+ );++ expect(screen.getByTestId('avatar-group')).toBeInTheDocument();+ });++ it('applies size class to the group', () => {+ render(+ <XDSAvatarGroup size="medium">+ <XDSAvatar name="Alice" />+ </XDSAvatarGroup>,+ );++ const group = screen.getByRole('group');+ expect(group.className).toContain('xds-avatar-group');+ expect(group.className).toContain('medium');+ });++ it('renders empty group when no children', () => {+ render(<XDSAvatarGroup data-testid="empty">{[]}</XDSAvatarGroup>);++ expect(screen.getByTestId('empty')).toBeInTheDocument();+ expect(screen.queryByRole('img')).not.toBeInTheDocument();+ });+});++describe('XDSAvatarGroupOverflow', () => {+ it('renders overflow count as span by default', () => {+ render(+ <XDSAvatarGroup>+ <XDSAvatar name="Alice" />+ <XDSAvatarGroupOverflow count={5} />+ </XDSAvatarGroup>,+ );++ const overflow = screen.getByLabelText('5 more');+ expect(overflow.tagName).toBe('SPAN');+ expect(overflow).toHaveTextContent('+5');+ });++ it('renders as button when onClick is provided', () => {+ render(+ <XDSAvatarGroup>+ <XDSAvatar name="Alice" />+ <XDSAvatarGroupOverflow count={3} onClick={() => {}} />+ </XDSAvatarGroup>,+ );++ const overflow = screen.getByLabelText('3 more');+ expect(overflow.tagName).toBe('BUTTON');+ });++ it('calls onClick when clicked', async () => {+ const user = userEvent.setup();+ const handleClick = vi.fn();++ render(+ <XDSAvatarGroup>+ <XDSAvatar name="Alice" />+ <XDSAvatarGroupOverflow count={3} onClick={handleClick} />+ </XDSAvatarGroup>,+ );++ await user.click(screen.getByLabelText('3 more'));+ expect(handleClick).toHaveBeenCalledOnce();+ });++ it('renders custom children instead of default label', () => {+ render(+ <XDSAvatarGroup>+ <XDSAvatar name="Alice" />+ <XDSAvatarGroupOverflow count={5}>+ <span data-testid="custom">more</span>+ </XDSAvatarGroupOverflow>+ </XDSAvatarGroup>,+ );++ expect(screen.getByTestId('custom')).toBeInTheDocument();+ });++ it('works with sliced avatar list and server-side count', () => {+ const users = ['Alice', 'Bob', 'Charlie', 'Diana', 'Eve'];+ const serverTotal = 47;+ const visibleCount = 3;++ render(+ <XDSAvatarGroup size="medium">+ {users.slice(0, visibleCount).map(name => (+ <XDSAvatar key={name} name={name} />+ ))}+ <XDSAvatarGroupOverflow count={serverTotal - visibleCount} />+ </XDSAvatarGroup>,+ );++ expect(screen.getByLabelText('Alice')).toBeInTheDocument();+ expect(screen.getByLabelText('Bob')).toBeInTheDocument();+ expect(screen.getByLabelText('Charlie')).toBeInTheDocument();+ expect(screen.getByLabelText('44 more')).toBeInTheDocument();+ expect(screen.getByText('+44')).toBeInTheDocument();+ });+});diff --git a/packages/core/src/AvatarGroup/XDSAvatarGroup.tsx b/packages/core/src/AvatarGroup/XDSAvatarGroup.tsxnew file mode 100644index 0000000000..63972503e4--- /dev/null+++ b/packages/core/src/AvatarGroup/XDSAvatarGroup.tsx@@ -0,0 +1,113 @@+// Copyright (c) Meta Platforms, Inc. and affiliates.+'use client';++/**+ * @file XDSAvatarGroup.tsx+ * @input Uses React, StyleX, theme tokens, XDSAvatarGroupContext+ * @output Exports XDSAvatarGroup component and XDSAvatarGroupProps+ * @position Core implementation; consumed by index.ts+ *+ * Compositional API: children are XDSAvatar elements (and optionally+ * one XDSAvatarGroupOverflow). The group provides overlap styling via+ * context — no child introspection needed.+ *+ * SYNC: When modified, update these files to stay in sync:+ * - /packages/core/src/AvatarGroup/AvatarGroup.doc.mjs (props table, features)+ * - /packages/core/src/AvatarGroup/index.ts (exports if types change)+ * - /apps/storybook/stories/AvatarGroup.stories.tsx (storybook stories)+ * - /packages/cli/templates/blocks/components/AvatarGroup/ (showcase blocks)+ */++import {useMemo, type ReactNode} from 'react';+import type {XDSBaseProps} from '../XDSBaseProps';+import {resolveSize, type XDSAvatarSize} from '../Avatar';+import * as stylex from '@stylexjs/stylex';+import {xdsClassName, mergeProps} from '../utils';+import {XDSAvatarGroupContext} from './XDSAvatarGroupContext';++const OVERLAP_RATIO = 0.25;++export interface XDSAvatarGroupProps extends XDSBaseProps<HTMLDivElement> {+ /** Ref forwarded to the root element. */+ ref?: React.Ref<HTMLDivElement>;+ /**+ * XDSAvatar children, optionally followed by one XDSAvatarGroupOverflow.+ * Consumers are responsible for slicing to the desired visible count.+ */+ children: ReactNode;+ /**+ * Size applied to all avatars via context.+ * @default 'small'+ */+ size?: XDSAvatarSize;+ /**+ * Test ID for integration testing.+ */+ 'data-testid'?: string;+}++const styles = stylex.create({+ root: {+ display: 'inline-flex',+ alignItems: 'center',+ },+});++/**+ * Stacked avatar display showing multiple avatars overlapping with an+ * optional overflow indicator. Uses a compositional children-based API+ * so each avatar can carry its own props (status dots, click handlers, etc.).+ *+ * Consumers handle slicing — pass only the avatars you want visible,+ * then add an XDSAvatarGroupOverflow for the "+N" indicator.+ *+ * @example+ * ```+ * <XDSAvatarGroup size="medium">+ * {users.slice(0, 3).map(u => (+ * <XDSAvatar key={u.id} src={u.src} name={u.name} />+ * ))}+ * <XDSAvatarGroupOverflow count={users.length - 3} />+ * </XDSAvatarGroup>+ * ```+ */+export function XDSAvatarGroup({+ children,+ size = 'small',+ 'data-testid': testId,+ 'aria-label': ariaLabel = 'Avatars',+ xstyle,+ className,+ style,+ ref,+ ...props+}: XDSAvatarGroupProps): ReactNode {+ const numericSize = resolveSize(size);+ const overlap = Math.round(numericSize * OVERLAP_RATIO);++ const contextValue = useMemo(+ () => ({size, overlap, numericSize}),+ [size, overlap, numericSize],+ );++ return (+ <XDSAvatarGroupContext.Provider value={contextValue}>+ <div+ ref={ref}+ role="group"+ aria-label={ariaLabel}+ data-testid={testId}+ {...mergeProps(+ xdsClassName('avatar-group', {size}),+ stylex.props(styles.root, xstyle),+ className,+ style,+ )}+ {...props}>+ {children}+ </div>+ </XDSAvatarGroupContext.Provider>+ );+}++XDSAvatarGroup.displayName = 'XDSAvatarGroup';diff --git a/packages/core/src/AvatarGroup/XDSAvatarGroupContext.ts b/packages/core/src/AvatarGroup/XDSAvatarGroupContext.tsnew file mode 100644index 0000000000..c7319a82c1--- /dev/null+++ b/packages/core/src/AvatarGroup/XDSAvatarGroupContext.ts@@ -0,0 +1,25 @@+// Copyright (c) Meta Platforms, Inc. and affiliates.+'use client';++/**+ * @file XDSAvatarGroupContext.ts+ * @input None (pure context definition)+ * @output Exports AvatarGroup context and useXDSAvatarGroup hook+ * @position Shared context; consumed by children for group-aware styling+ */++import {createContext, useContext} from 'react';+import type {XDSAvatarSize} from '../Avatar';++export interface XDSAvatarGroupContextValue {+ size: XDSAvatarSize;+ overlap: number;+ numericSize: number;+}++export const XDSAvatarGroupContext =+ createContext<XDSAvatarGroupContextValue | null>(null);++export function useXDSAvatarGroup(): XDSAvatarGroupContextValue | null {+ return useContext(XDSAvatarGroupContext);+}diff --git a/packages/core/src/AvatarGroup/XDSAvatarGroupOverflow.tsx b/packages/core/src/AvatarGroup/XDSAvatarGroupOverflow.tsxnew file mode 100644index 0000000000..ab71370906--- /dev/null+++ b/packages/core/src/AvatarGroup/XDSAvatarGroupOverflow.tsx@@ -0,0 +1,146 @@+// Copyright (c) Meta Platforms, Inc. and affiliates.+'use client';++/**+ * @file XDSAvatarGroupOverflow.tsx+ * @input Uses React, StyleX, AvatarGroupContext+ * @output Exports XDSAvatarGroupOverflow for overflow indicator+ * @position Slot component used inside XDSAvatarGroup+ *+ * SYNC: When modified, update these files to stay in sync:+ * - /packages/core/src/AvatarGroup/AvatarGroup.doc.mjs+ * - /packages/core/src/AvatarGroup/index.ts+ * - /packages/cli/templates/blocks/components/AvatarGroup/ (showcase blocks)+ */++import type {ReactNode} from 'react';+import * as stylex from '@stylexjs/stylex';+import {+ colorVars,+ typographyVars,+ fontWeightVars,+ radiusVars,+} from '../theme/tokens.stylex';+import {useXDSAvatarGroup} from './XDSAvatarGroupContext';++const BORDER_WIDTH = 2;+const OVERFLOW_FONT_RATIO = 0.35;++export interface XDSAvatarGroupOverflowProps {+ /**+ * The overflow count to display.+ */+ count: number;++ /**+ * Callback fired when the overflow indicator is clicked.+ * When provided, the indicator renders as a focusable button.+ */+ onClick?: () => void;++ /**+ * Custom content to render instead of the default "+N" label.+ */+ children?: ReactNode;+}++const styles = stylex.create({+ base: {+ position: 'relative',+ display: 'flex',+ alignItems: 'center',+ justifyContent: 'center',+ borderRadius: radiusVars['--radius-full'],+ backgroundColor: colorVars['--color-neutral'],+ color: colorVars['--color-text-secondary'],+ fontFamily: typographyVars['--font-family-body'],+ fontWeight: fontWeightVars['--font-weight-medium'],+ userSelect: 'none',+ borderWidth: BORDER_WIDTH,+ borderStyle: 'solid',+ borderColor: colorVars['--color-background-surface'],+ boxSizing: 'content-box',+ },+ button: {+ cursor: 'pointer',+ padding: 0,+ },+ overlap: {+ marginInlineStart: 'var(--_avatar-group-overlap)',+ },+});++const dynamicStyles = stylex.create({+ size: (s: number) => ({+ width: s,+ height: s,+ }),+ fontSize: (s: number) => ({+ fontSize: s * OVERFLOW_FONT_RATIO,+ }),+ overlap: (offset: number) => ({+ '--_avatar-group-overlap': `${offset}px`,+ }),+});++/**+ * Overflow indicator for XDSAvatarGroup. Shows a "+N" count and+ * optionally handles clicks.+ *+ * @example+ * ```+ * <XDSAvatarGroup size="medium">+ * {users.slice(0, 3).map(u => (+ * <XDSAvatar key={u.id} src={u.src} name={u.name} />+ * ))}+ * <XDSAvatarGroupOverflow count={users.length - 3} onClick={showAll} />+ * </XDSAvatarGroup>+ * ```+ */+export function XDSAvatarGroupOverflow({+ count,+ onClick,+ children,+}: XDSAvatarGroupOverflowProps): ReactNode {+ const group = useXDSAvatarGroup();+ const numericSize = group?.numericSize ?? 36;+ const overlap = group?.overlap ?? 0;++ const label = `${count} more`;+ const content = children ?? `+${count}`;++ if (onClick) {+ return (+ <button+ type="button"+ onClick={onClick}+ aria-label={label}+ {...stylex.props(+ styles.base,+ styles.button,+ styles.overlap,+ dynamicStyles.size(numericSize),+ dynamicStyles.fontSize(numericSize),+ dynamicStyles.overlap(-overlap),+ )}>+ {content}+ </button>+ );+ }++ return (+ <span+ aria-label={label}+ {...stylex.props(+ styles.base,+ styles.overlap,+ dynamicStyles.size(numericSize),+ dynamicStyles.fontSize(numericSize),+ dynamicStyles.overlap(-overlap),+ )}>+ {content}+ </span>+ );+}++XDSAvatarGroupOverflow.displayName = 'XDSAvatarGroupOverflow';diff --git a/packages/core/src/AvatarGroup/index.ts b/packages/core/src/AvatarGroup/index.tsnew file mode 100644index 0000000000..e22f2ccd30--- /dev/null+++ b/packages/core/src/AvatarGroup/index.ts@@ -0,0 +1,19 @@+// Copyright (c) Meta Platforms, Inc. and affiliates.+'use client';++/**+ * @file index.ts+ * @input Imports from XDSAvatarGroup.tsx, XDSAvatarGroupOverflow.tsx, XDSAvatarGroupContext.ts+ * @output Exports XDSAvatarGroup, XDSAvatarGroupOverflow, context hook, and types+ * @position Component entry point; re-exported by /packages/core/src/index.ts+ *+ * SYNC: When modified, update this header and /packages/core/src/AvatarGroup/AvatarGroup.doc.mjs+ */++export {XDSAvatarGroup} from './XDSAvatarGroup';+export type {XDSAvatarGroupProps} from './XDSAvatarGroup';++export {XDSAvatarGroupOverflow} from './XDSAvatarGroupOverflow';+export type {XDSAvatarGroupOverflowProps} from './XDSAvatarGroupOverflow';++export {useXDSAvatarGroup} from './XDSAvatarGroupContext';diff --git a/packages/core/src/index.ts b/packages/core/src/index.tsindex 5f7a3c10d1..0a4048dae9 100644--- a/packages/core/src/index.ts+++ b/packages/core/src/index.ts@@ -18,6 +18,7 @@ export type {XDSBaseProps} from './XDSBaseProps';export * from './AppShell';export * from './AspectRatio';export * from './Avatar';+export * from './AvatarGroup';export * from './Badge';export * from './Banner';export * from './Blockquote';