import type { FocusEventHandler, ForwardedRef, HTMLAttributes, KeyboardEvent, KeyboardEventHandler, MouseEventHandler, PropsWithChildren, ReactNode, Ref, RefObject } from "react"; import type { CollectionHookResult, CollectionItem, ListHandlers, NavigationHookResult, ScrollingAPI, SelectHandler, SelectionChangeHandler, SelectionHookResult, SelectionProps, SelectionStrategy, ViewportTrackingResult } from "../common-hooks"; export type ComponentType = (props: PropsWithChildren) => JSX.Element; export type ListItemType = ComponentType & { ref?: Ref; }>; export interface ListItemProps extends HTMLAttributes { children?: ReactNode; disabled?: boolean; item?: T; itemHeight?: number | string; itemTextHighlightPattern?: RegExp | string; label?: string; showCheckbox?: boolean; /** * selectable is a marker, used by List, not used by ListItem itself */ selectable?: boolean; selected?: boolean; } export interface ListScrollHandles { scrollToIndex: (itemIndex: number) => void; scrollToItem: (item: Item) => void; scrollTo: (scrollOffset: number) => void; } export interface ListProps extends SelectionProps, Omit, "onSelect" | "defaultValue"> { /** * The component used to render a ListItem instead of the default. This must itself render a ListItem, * must implement props that extend ListItemProps and must forward ListItem props to the ListItem. */ ListItem?: ListItemType; /** * The component used when there are no items. */ ListPlaceholder?: ComponentType>; borderless?: boolean; /** * Adds checkbox to list. Defaults to true for multiselect strategy. Only supported for * multiple select strategies (multi selection and extended selection) */ checkable?: boolean; className?: string; collapsibleHeaders?: boolean; defaultHighlightedIndex?: number; disabled?: boolean; disableFocus?: boolean; /** * Use to turn off typeahead search functionality within List. Defaulst to false; */ disableTypeToSelect?: boolean; displayedItemCount?: number; emptyMessage?: string; focusVisible?: number; /** * Used for providing customized item height. It should return a number or a string if item height * is in percentage. . * * @param {number} index The item index. */ getItemHeight?: (index: number) => number; /** * Used for providing customized item ids. * deprecated * @param {number} index The item index. */ getItemId?: (index: number) => string; /** * Height of the component. */ height?: number | string; highlightedIndex?: number; /** * The total number of items. * * Used for keyboard navigation (when `End` key is pressed) and when the list is virtualized. */ itemCount?: number; /** * Size of the gap between list items. Defaults to zero. */ itemGapSize?: number; /** * Height of an item. I can be a number or a string if item height is in percentage. If omitted * default height values from Salt theme will be used. * * Note that when using a percentage value, the list must have a height. */ itemHeight?: number | string; /** * Used for providing text highlight. * * It can be a capturing regex or a string for a straightforward string matching. */ itemTextHighlightPattern?: RegExp | string; /** * Item `toString` function when list is not used declaratively and its items are objects * instead of strings. The string value is also used in tooltip when item text is truncated. * * If omitted, component will look for a `label` property on the data object. * * @param {object} item The item. */ itemToString?: (item: Item) => string; listHandlers?: ListHandlers; /** * Maximum list height. */ maxHeight?: number | string; /** * Maximum list width. */ maxWidth?: number | string; /** * Minimum list height. */ minHeight?: number | string; /** * Minimum list width. */ minWidth?: number | string; onHighlight?: (index: number) => void; /** * If `true`, the component will remember the last keyboard-interacted position * and highlight it when list is focused again. */ restoreLastFocus?: boolean; scrollingApiRef?: ForwardedRef>; /** * The keyboard keys used to effect selection, defaults to SPACE and ENTER * TODO maybe this belongs on the SelectionProps interface ? */ selectionKeys?: string[]; showEmptyMessage?: boolean; source?: ReadonlyArray; stickyHeaders?: boolean; /** * When set to `true`, 'Tab' key selects current highlighted item before focus is blurred away * from the component. This would be the desirable behaviour for any dropdown menu based * components like dropdown, combobox. * * @default false */ tabToSelect?: boolean; /** * Width of the component. */ width?: number | string; } export interface ListControlProps { "aria-activedescendant"?: string; onBlur: FocusEventHandler; onFocus: FocusEventHandler; onKeyDown: KeyboardEventHandler; onMouseDownCapture: MouseEventHandler; onMouseLeave: MouseEventHandler; } export interface ListHookProps extends Omit, Selection>, "onSelect" | "onSelectionChange"> { collapsibleHeaders?: boolean; collectionHook: CollectionHookResult; containerRef: RefObject; contentRef?: RefObject; defaultHighlightedIndex?: number; disabled?: boolean; disableAriaActiveDescendant?: boolean; disableHighlightOnFocus?: boolean; disableTypeToSelect?: boolean; focusVisible?: boolean; highlightedIndex?: number; label?: string; listHandlers?: ListHandlers; onHighlight?: (index: number) => void; onKeyboardNavigation?: (event: KeyboardEvent, currentIndex: number) => void; onKeyDown?: (evt: KeyboardEvent) => void; onSelect?: SelectHandler; onSelectionChange?: SelectionChangeHandler; restoreLastFocus?: boolean; selectionKeys?: string[]; stickyHeaders?: boolean; tabToSelect?: boolean; } export interface ListHookResult extends Partial>, Pick, "selected" | "setSelected">, Partial> { keyboardNavigation: RefObject; listHandlers: ListHandlers; listItemHeaderHandlers: Partial; listControlProps: ListControlProps; setHighlightedIndex: (index: number) => void; setIgnoreFocus: (ignoreFocus: boolean) => void; }