1 import type { ReactNode } from 'react';
2 import { createContext, useContext } from 'react';
4 import type { SelectionState } from '../hooks/useSelectionControls';
5 import { useSelectionControls } from '../hooks/useSelectionControls';
6 import type { BrowserItemId } from '../interface';
8 interface SelectionFunctions {
9 selectedItemIds: BrowserItemId[];
10 toggleSelectItem: (id: BrowserItemId) => void;
11 toggleAllSelected: () => void;
12 selectItem: (id: BrowserItemId) => void;
13 clearSelections: () => void;
14 toggleRange: (selectedBrowserItemId: BrowserItemId) => void;
15 isSelected: (linkId: string) => boolean;
16 selectionState: SelectionState;
19 const SelectionContext = createContext<SelectionFunctions | null>(null);
26 export function SelectionProvider({ itemIds, children }: Props) {
27 const selectionFunction = useSelectionControls({ itemIds });
29 return <SelectionContext.Provider value={selectionFunction}>{children}</SelectionContext.Provider>;
32 export function useSelection() {
33 const state = useContext(SelectionContext);