import { type ComponentProps, type RefObject } from 'react'; /** * Unstyled Carbon `TreeView` (APG tree), the behaviour of the styled TreeView without a single class: * a `role="tree"` of nested `Node`s (`role="treeitem"`), each a `Row` (what the user sees and clicks: * its `Toggle` caret, icon and label) and a `Group` holding its child nodes. One Tab stop (roving * tabindex). Click or Space selects (and makes the node active); `multiselect` toggles with Ctrl / ⌘ + * click or Space and selects all with Ctrl / ⌘ + A. Up / Down move through the visible nodes, Home / * End jump, Right / Left expand / collapse (or move to the first child / the parent), Enter toggles, * selects and follows the node's link, typing jumps to a label (core/tree, core/typeahead). A `lazy` * node asks `onLazyLoad` for its children the first time it opens. * * State shows as data attributes to style on: `data-multiselect` on `Root`; `data-selected`, * `data-active`, `data-disabled`, `data-branch`, `data-expanded` and `data-loading` on a `Node` and its * `Row`; `data-expanded` on its `Toggle` and `Group`. * * ```tsx * * * ▾src * * index.ts * * * * ``` */ /** What the tree needs to know about a node it finds in the DOM. */ interface NodeHandle { value: string; label: string; branch: boolean; expanded: boolean; disabled: boolean; toggle: (expanded: boolean) => void; } interface TreeViewContextValue { multiselect: boolean; selected: readonly string[]; active: string; /** The node that holds the tree's one Tab stop. */ tabStop: string | undefined; register: (el: HTMLElement, handle: RefObject) => () => void; } /** The state of the enclosing `TreeView.Root` (selection, active node, Tab stop). */ export declare function useTreeViewContext(part?: string): TreeViewContextValue; export interface RootProps extends Omit, 'role' | 'onSelect' | 'defaultValue'> { /** Ctrl / ⌘ + click and Space toggle nodes in and out of the selection; Ctrl / ⌘ + A selects all. */ multiselect?: boolean; /** Selected node values (controlled). */ selected?: readonly string[]; defaultSelected?: readonly string[]; /** After the user changed the selection; `value` is the node that did it. */ onSelect?: (selected: string[], value: string) => void; /** The node last activated (controlled). */ active?: string; defaultActive?: string; onActivate?: (value: string) => void; } export declare function Root({ multiselect, selected: selectedProp, defaultSelected, onSelect, active: activeProp, defaultActive, onActivate, ref, children, ...rest }: Readonly): import("react").JSX.Element; export interface NodeProps extends Omit, 'role' | 'onToggle'> { /** Identifies the node in `selected` / `active`. */ value: string; /** The text typeahead matches (default: `value`). */ label?: string; /** It has child nodes (in its `Group`): a branch. */ hasChildren?: boolean; disabled?: boolean; /** Open (controlled). */ expanded?: boolean; defaultExpanded?: boolean; onToggle?: (expanded: boolean) => void; /** * A branch whose children aren't loaded yet (Shoelace's `lazy`; Carbon has no pattern): expanding it * the first time marks it loading (`aria-busy`, `data-loading`) and calls `onLazyLoad` — render the * children when they arrive. A returned promise that resolves with no children makes it a leaf; one * that rejects closes it to retry. */ lazy?: boolean; onLazyLoad?: (value: string) => void | Promise; } interface NodeContextValue { value: string; /** Child nodes, or a lazy node that may still get some. */ branch: boolean; expanded: boolean; /** A lazy node waiting for its children. */ loading: boolean; selected: boolean; active: boolean; disabled: boolean; /** 0 at the top level. */ depth: number; /** The id of its `Row`, which names its `Group`. */ rowId: string; /** Opens or closes a branch (not when disabled). */ toggle: (expanded: boolean) => void; } /** The state of the enclosing `TreeView.Node` (branch, expanded, loading, selected, depth …). */ export declare function useNodeContext(part?: string): NodeContextValue; /** One node (`role="treeitem"`): the tree's Tab stop when it holds it; put its `Row` and `Group` inside. */ export declare function Node({ value, label, hasChildren, disabled, expanded: expandedProp, defaultExpanded, onToggle, lazy, onLazyLoad, ref, children, ...rest }: Readonly): import("react").JSX.Element; /** What the user sees of a node (caret, icon, label): it names the node's `Group`. */ export declare function Row(props: Readonly>): import("react").JSX.Element; export type ToggleProps = Omit, 'type'>; /** * The caret that opens and closes a branch — only it: a click on the rest of the row selects. Out of the * tab order and hidden from assistive tech (the node takes the keyboard: Right / Left / Enter). */ export declare function Toggle(props: Readonly): import("react").JSX.Element; /** A node's child nodes: a `role="group"` named by its row, hidden while the branch is closed. */ export declare function Group({ children, ...rest }: Readonly>): import("react").JSX.Element; export {};