import React, { createContext, useContext } from 'react'; import { TreeViewNodeData } from './TreeView'; interface TransitionProps { in: boolean; children: React.ReactNode; } export type TreeItemComponent = React.ComponentType; export interface TreeViewContextType { // State expandedIds: Set; selectedIds: Set; nodesById: Map; nodeParents: Map; itemRefs: React.MutableRefObject>; // Handlers toggleExpand: (id: string) => void; toggleSelect: (event: React.MouseEvent, id: string) => void; // Customization expandIcon?: React.ReactNode; collapseIcon?: React.ReactNode; defaultEndIcon?: React.ReactNode; groupTransition?: React.ComponentType; item?: TreeItemComponent; } export const TreeViewContext = createContext(null); export const useTreeViewContext = () => { const context = useContext(TreeViewContext); if (!context) { throw new Error('useTreeViewContext must be used within a TreeView provider.'); } return context; }; // Props that will be passed to custom item components export interface TreeItemProps { node: TreeViewNodeData; isExpanded: boolean; isExpandable: boolean; isSelected: boolean; level: number; getTreeItemProps: (props?: React.HTMLAttributes) => React.HTMLAttributes; getToggleProps: (props?: React.HTMLAttributes) => React.HTMLAttributes; }