@payfit/unity-components
Version:
25 lines (24 loc) • 867 B
TypeScript
import { Key } from 'react-aria-components/Breadcrumbs';
import { Selection } from 'react-aria-components/GridList';
/**
* Hook to manage controlled/uncontrolled selection state.
* Follows React's controlled component pattern.
* @param value - Controlled value (undefined for uncontrolled mode)
* @param onChange - Callback when selection changes
* @returns Tuple of [currentSelection, handleSelectionChange]
* @example
* ```tsx
* // Controlled mode
* const [selection, setSelection] = useControlledSelection(
* selectedKeys,
* handleChange
* )
*
* // Uncontrolled mode
* const [selection, setSelection] = useControlledSelection(
* undefined,
* handleChange
* )
* ```
*/
export declare function useControlledSelection(value: 'all' | Iterable<Key> | undefined, onChange?: (keys: Selection) => void): [Selection, (keys: Selection) => void];