@itwin/presentation-hierarchies-react
Version:
React components based on `@itwin/presentation-hierarchies`
46 lines • 1.88 kB
TypeScript
import { PresentationHierarchyNode } from "./TreeNode.js";
import { useTree } from "./UseTree.js";
/**
* A union of different supported selection modes in a tree component:
* - `none` - no selection is allowed,
* - `single` - only one node can be selected at a time,
* - `extended` - multiple nodes can be selected using shift and ctrl keys,
* - `multiple` - multiple nodes can be selected without using shift or ctrl keys.
*
* @public
*/
export type SelectionMode = "none" | "single" | "extended" | "multiple";
/**
* Type of selection change.
* - `add` - a node was added to the selection,
* - `replace` - a selected node was replaced with a different one,
* - `remove` - a node was removed from the selection.
*
* @public
*/
export type SelectionChangeType = "add" | "replace" | "remove";
/**
* Props for `useSelectionHandler` hook.
* @public
*/
type UseSelectionHandlerProps = Pick<ReturnType<typeof useTree>, "rootNodes" | "selectNodes"> & {
/** Selection mode that the component is working in. */
selectionMode: SelectionMode;
};
/**
* Result of `useSelectionHandler` hook.
* @public
*/
interface UseSelectionHandlerResult {
/** Should be called by node renderer when a node component is clicked. */
onNodeClick: (node: PresentationHierarchyNode, isSelected: boolean, event: React.MouseEvent<HTMLElement, MouseEvent>) => void;
/** Should be called by node renderer when a keyboard event happens on a node. */
onNodeKeyDown: (node: PresentationHierarchyNode, isSelected: boolean, event: React.KeyboardEvent<HTMLElement>) => void;
}
/**
* A react hook that helps implement different selection modes in a tree component created using `useTree` hook.
* @public
*/
export declare function useSelectionHandler(props: UseSelectionHandlerProps): UseSelectionHandlerResult;
export {};
//# sourceMappingURL=UseSelectionHandler.d.ts.map