import type { Dispatch, KeyboardEventHandler, RefObject, SetStateAction } from "react"; export interface UsePanelsOptions { /** * The prefix to use for all of the panel ids. This is used to generate the id * for each panel as well as determine if a panel is expanded. */ idPrefix: string; /** * The number of panels that will be used by this expansion logic and * generates the number of panel props to be used in the return value. This * should be a number greater than 0 and will throw a `RangeError` if it is * not in development. */ count: number; /** * Boolean if multiple panels can be expanded at a time. The default behavior * is to only allow one panel to be expanded and will close the previous panel * when a new one is expanded. */ multiple?: boolean; /** * Boolean if the expansion logic should prevent all the panels from being * closed. */ preventAllClosed?: boolean; /** * Either the index that should be expanded by default, a list of indexes that * should be expanded by default, or `-1` which will expand all panels by * default. * * When this is omitted and `undefined`, no panels will be expanded by * default. */ defaultExpandedIndex?: number | readonly number[]; } /** * An object of props that gets generated for each panel within the hook. */ export interface ProvidedPanelProps { /** * The DOM id for the panel which is really just `${idPrefix}-${index + 1}`. */ id: string; /** * A ref object for the panel. This is required so that the parent keyboard * event handler can focus the next/previous/first/last panel when the correct * arrow key or home/end key is pressed. If there is only one panel and the * keydown event handler isn't being used, this prop is not required to be * passed to the expansion panel. */ headerRef: RefObject; /** * This will be `true` when the panel is expanded or the previous panel was * expanded and the panel is not the first panel in the list. */ marginTop: boolean; /** * Boolean if the panel's expansion state should be disabled. This will only * be true when the `preventAllClosed` option has been enabled and the panel * is the last remaining expanded panel. */ disabled: boolean; /** * Boolean if the panel is currently expanded. */ expanded: boolean; /** * A function that will toggle the expansion of this panel in the list. */ onExpandClick(): void; } declare type ExpandedIds = readonly string[]; declare type CreateExpandById = (panelId: string) => () => void; declare type ExpansionDispatcher = Dispatch>; declare type ExpansionPanelKeyDownHandler = KeyboardEventHandler; declare type ReturnValue = [ readonly ProvidedPanelProps[], ExpansionPanelKeyDownHandler, ExpandedIds, ExpansionDispatcher, CreateExpandById ]; /** * This hook is used to control the expansion of a list of panels along with * providing some of the required props for each panel. This hook will provide * an ordered list of: * * - the list of panel props that include the `id`, `key`, `expanded`, and * `onExpandChange`. * - a keydown event handler to pass to a parent component (normally the * ExpansionList) to allow keyboard movement with the arrow keys, and home+end * keys. This should only be used when there are multiple panels. * - the current list of panel ids that are expanded * - the React setState dispatcher for controlling the expanded list of ids * manually if desired * - a function to create a handler for toggling the expansion of a specific * panel * * This hook is usually used to control a list of expansion panels, but can also * control a single panel if desired. * * Examples: * * Single panel: * * ```tsx * const [panels] = usePanels({ count: 1, idPrefix: "my-panel" }); * // since the count is one, it'll just be a list of only one panel props * const [panelProps] = panels; * * return ( * * Content within the panel... * * ); * ``` * * Multiple Panels: * * ```tsx * const [panels, onKeyDown] = usePanels({ count: 3, idPrefix: "panel-list" }); * * const [panel1Props, panel2Props, panel3Props] = panels; * * return ( * * * Panel 1 Content... * * * Panel 2 Content... * * * Panel 3 Content... * * * ); * ``` */ export declare function usePanels({ idPrefix, count, multiple, preventAllClosed, defaultExpandedIndex, }: UsePanelsOptions): ReturnValue; export {};