@vtex/admin-ui
Version:
> VTEX admin component library
42 lines (41 loc) • 1.07 kB
TypeScript
import { useCheckboxState } from '../Checkbox';
/**
* SelectionTree state
* @example
* const state = useSelectionTreeState({
* items: []
* })
*
* console.log(state.selectedItems) // to display the currently selected items
*/
export declare function useSelectionTreeState<T>(params: UseSelectionTreeStateParams<T>): SelectionTreeState<T>;
export interface SelectionTreeState<T> {
/**
* currently selected items
*/
selectedItems: T[];
/**
* Root state
*/
root: ReturnType<typeof useCheckboxState>;
/**
* Items state
*/
items: ReturnType<typeof useCheckboxState>;
}
export interface UseSelectionTreeStateParams<T> {
/**
* Collection of items
*/
items: T[];
/**
* Maps the unique key (id) for the collection
* @default (item) => item.id
*/
mapId?: (item: T) => string | number;
/**
* Condition that makes an item initially selected
* @default () => false
*/
isInitiallySelected?: (item: T) => boolean;
}