import { type ReactElement, type ReactNode } from 'react'; import type { ItemRenderer, Key } from '@react-types/shared'; import { type KeyedItem, type SelectionT } from '@deephaven/utils'; import { type ItemElementOrPrimitive, type ItemProps, type SectionProps } from '../shared'; import { type PopperOptions } from '../../popper'; /** * `Item.textValue` prop needs to be a non-empty string for accessibility * purposes. This is not displayed in the UI. */ export declare const ITEM_EMPTY_STRING_TEXT_VALUE = "Empty"; /** * React Spectrum
supports an `ItemRenderer` function as a child. The * DH picker makes use of this internally, but we don't want to support it as * an incoming prop. */ type SectionPropsNoItemRenderer = Omit, 'children'> & { children: Exclude['children'], ItemRenderer>; }; export type ItemElement = ReactElement>; export type SectionElement = ReactElement>; export type ItemOrSection = ItemElementOrPrimitive | SectionElement; export type ItemIconSlot = 'icon' | 'image' | 'illustration'; /** * Augment the Spectrum selection key type to include boolean values. * Spectrum collection components already supports this, but the built in types * don't reflect it. */ export type ItemKey = Key | boolean; export type ItemSelection = SelectionT; /** * Augment the Spectrum selection change handler type to include boolean keys. * Spectrum components already supports this, but the built in types don't * reflect it. */ export type ItemSelectionChangeHandler = (key: ItemKey) => void; export interface MultipleItemSelectionProps { selectedKeys?: 'all' | Iterable; defaultSelectedKeys?: 'all' | Iterable; disabledKeys?: Iterable; /** * Handler that is called when the selection change. * Note that under the hood, this is just an alias for Spectrum's * `onSelectionChange`. We are renaming for better consistency with other * components. */ onChange?: (keys: ItemSelection) => void; /** * Handler that is called when the selection changes. * @deprecated Use `onChange` instead */ onSelectionChange?: (keys: ItemSelection) => void; } export interface NormalizedItemData { key?: ItemKey; content: ReactNode; description?: ReactNode; icon?: ReactNode; textValue: string | undefined; } export interface NormalizedSectionData { key?: Key; title?: ReactNode; items: NormalizedItem[]; } /** * Spectrum collection components support a variety of item types, including * strings, numbers, booleans, and more complex React elements. This type * represents a normalized form to make rendering items simpler and keep the * logic of transformation in separate util methods. It also adheres to the * `KeyedItem` interface to be compatible with Windowed data utils * (e.g. `useViewportData`). */ export type NormalizedItem = KeyedItem; export type NormalizedSection = KeyedItem; export type NormalizedItemOrSection = TItemOrSection extends SectionElement ? NormalizedSection : NormalizedItem; export type TooltipOptions = { placement: PopperOptions['placement']; }; /** * DH wrappers of Spectrum collection components use a normalized item that * includes a `key` prop and an optional `item` prop. This is mostly to support * Windowed data where items are created before their data has been loaded (data * gets set in the `item` prop). If data has loaded, return its `key`. If not, * return the top-level `key` on the normalized item. * @param item The normalized item or section * @returns The `key` of the item or section */ export declare function getItemKey(item: TItem | null | undefined): TKey; /** * Determine Item `textValue` based on the `textValue` prop or primitive children * value. * @param item The item to get the text value for * @returns The text value of the item */ export declare function getItemTextValue(item: ItemElement): string | undefined; /** * Get the position of the item with the given selected key in a list of items. * @param items The items to search * @param itemHeight The height of each item * @param selectedKey The key of the selected item * @param topOffset The top offset of the list * @returns The position of the selected item or the top offset if not found */ export declare function getPositionOfSelectedItemElement({ items, itemHeight, selectedKey, topOffset, }: { items: ItemElement[]; selectedKey: TKey | null | undefined; itemHeight: number; topOffset: number; }): Promise; /** * Determine if a node is a Section element. * @param node The node to check * @returns True if the node is a Section element */ export declare function isSectionElement(node: ReactNode): node is SectionElement; /** * Determine if a node is an Item element. * @param node The node to check * @returns True if the node is an Item element */ export declare function isItemElement(node: ReactNode): node is ItemElement; /** * Determine if a node is an Item element containing a child `Text` element with * a `slot` prop set to `description`. * @param node The node to check * @returns True if the node is an Item element with a description */ export declare function isItemElementWithDescription(node: ReactNode): node is ReactElement>; /** * Determine if a node is an array containing normalized items or sections with * keys. Note that this only checks the first node in the array. * @param node The node to check * @returns True if the node is a normalized item or section with keys array */ export declare function isNormalizedItemsWithKeysList(node: TItemOrSection | TItemOrSection[] | NormalizedItemOrSection[]): node is NormalizedItemOrSection[]; /** * Determine if an object is a normalized section. * @param maybeNormalizedSection The object to check * @returns True if the object is a normalized section */ export declare function isNormalizedSection(maybeNormalizedSection: NormalizedItem | NormalizedSection): maybeNormalizedSection is NormalizedSection; /** * Determine if a node is an item or section. Valid types include strings, * numbers, booleans, Item elements, and Section elements. * @param node The node to check * @returns True if the node is an item or section */ export declare function isItemOrSection(node: ReactNode): node is ItemOrSection; /** * Returns a TooltipOptions object or null if options is false or null. * @param options Tooltip options * @param placement Default placement for the tooltip if `options` is set * explicitly to `true` * @returns TooltipOptions or null */ export declare function normalizeTooltipOptions(options?: boolean | TooltipOptions | null, placement?: TooltipOptions['placement']): TooltipOptions | null; /** * Convert a selection of `ItemKey`s to a selection of strings. * @param itemKeys The selection of `ItemKey`s * @returns The selection of strings */ export declare function itemSelectionToStringSet | undefined, TResult extends TKeys extends 'all' ? 'all' : TKeys extends Iterable ? Set : undefined>(itemKeys: TKeys): TResult; export {}; //# sourceMappingURL=itemUtils.d.ts.map