'use client'; import React, { Children, forwardRef, isValidElement, useState, } from 'react'; import { Surface, cn, surfaceClasses, useEffectiveSurface, } from '../common'; import { PixelPopover } from '../overlay-foundation/PixelPopover'; /* ────────────────────────────────────────────────────────────────────────── PixelBadgeGroup — inline row of badges with +N overflow popover. When the number of children exceeds `max`, renders the first `max - 1` inline and a "+N" trigger that opens a PixelPopover containing the remaining badges. Wraps badges in a horizontally-flowing `flex` row. ────────────────────────────────────────────────────────────────────────── */ export interface PixelBadgeGroupProps extends React.HTMLAttributes { max?: number; surface?: Surface; /** * Optional accessible name for the group. When provided, the wrapper renders * `role="group"` so SR users can navigate the landmark; otherwise it stays a * plain div to avoid an unlabeled group announcement. */ 'aria-label'?: string; 'aria-labelledby'?: string; children: React.ReactNode; } export const PixelBadgeGroup = forwardRef( function PixelBadgeGroup( { max = 5, surface: surfaceProp, className, children, ...rest }, ref, ) { const surface = useEffectiveSurface(surfaceProp); const s = surfaceClasses(surface); const [open, setOpen] = useState(false); const items = Children.toArray(children).filter(isValidElement); const count = items.length; const overflowing = count > max; const visibleCount = overflowing ? Math.max(0, max - 1) : count; const visible = items.slice(0, visibleCount); const hidden = items.slice(visibleCount); const remainder = hidden.length; const ariaLabel = (rest as { 'aria-label'?: string })['aria-label']; const ariaLabelledBy = (rest as { 'aria-labelledby'?: string })['aria-labelledby']; const hasName = !!(ariaLabel || ariaLabelledBy); return (
{visible.map((child, idx) => ( {child} ))} {overflowing && (
{hidden.map((child, idx) => ( {child} ))}
)}
); }, ); PixelBadgeGroup.displayName = 'PixelBadgeGroup'; // PixelChipGroup moved to its own file; re-exported so this module's API // stays unchanged. export { PixelChipGroup, type PixelChipGroupProps } from './PixelChipGroup';