UNPKG

@carbon/react

Version:

React components for the Carbon Design System

30 lines (29 loc) 1.53 kB
/** * Copyright IBM Corp. 2025, 2025 * * This source code is licensed under the Apache-2.0 license found in the * LICENSE file in the root directory of this source tree. */ import { ReactNode, RefObject } from 'react'; type Item = { id: string; }; /** * Manages overflow items in a container by automatically hiding items that don't fit. * @param items - Array of items to manage for overflow, each must have an `id` property. * @param containerRef - React ref to the container element that holds the items. * @param offsetRef - Optional ref to an offset element (like a "more" button) whose width is reserved when calculating available space. * @param maxItems - Optional maximum number of visible items. If undefined, only container space constrains visibility. * @param onChange - Optional callback called when hidden items change. Receives array of currently hidden items. * @returns Object with `visibleItems` (items to display), `hiddenItems` (items that don't fit), and `itemRefHandler` (function to attach refs to items for width measurement). */ declare const useOverflowItems: <T extends Item>(items: T[] | ReactNode, containerRef: RefObject<HTMLDivElement>, offsetRef?: RefObject<HTMLDivElement>, maxItems?: number, onChange?: (hiddenItems: T[]) => void) => { visibleItems: T[]; hiddenItems: T[]; itemRefHandler: () => void; } | { visibleItems: T[]; itemRefHandler: (id: string, node: HTMLDivElement | null) => () => void; hiddenItems: T[]; }; export default useOverflowItems;