import { CSSProperties, ReactNode } from 'react'; import { IconContent } from '../types/icon.types.js'; import { SlotClassNames, SlotStyles, HtmlProps } from '../types/slots.types.js'; export type TreeValue = string | number; export interface TreeNode { key: TreeValue; label: ReactNode; /** Icon shown before the label. */ icon?: IconContent; /** Child nodes. An empty array still renders a toggle, for a branch whose children load later. */ children?: TreeNode[]; disabled?: boolean; } /** One visible row produced by `flattenTree`. */ export interface FlatTreeNode { node: TreeNode; /** Depth from the roots, 0-based. */ level: number; parentKey: TreeValue | null; isBranch: boolean; isExpanded: boolean; /** Number of siblings at this level, for `aria-setsize`. */ setSize: number; /** 1-based position among those siblings, for `aria-posinset`. */ posInSet: number; } export type TreeSlots = 'root' | 'node' | 'toggle' | 'icon' | 'label' | 'empty'; /** Text Tree renders of its own, for translating it. */ export interface TreeLabels { /** Shown when `nodes` is empty (default `Nothing here`). */ empty?: string; } export interface TreeProps extends Omit, 'onSelect'> { nodes: TreeNode[]; /** Controlled set of expanded branch keys. Omit for uncontrolled. */ expandedKeys?: TreeValue[]; /** Branches expanded initially when uncontrolled (default `[]`). */ defaultExpandedKeys?: TreeValue[]; onExpandedChange?: (keys: TreeValue[]) => void; /** Controlled selected key. Omit for uncontrolled. */ selectedKey?: TreeValue | null; /** Key selected initially when uncontrolled. */ defaultSelectedKey?: TreeValue; onSelect?: (key: TreeValue, node: TreeNode) => void; /** Clicking a branch's label toggles it as well as selecting it (default `true`). */ expandOnSelect?: boolean; /** Indent per level in px (default `20`). */ indent?: number; /** Icon for the expand/collapse toggle. Rotates 90° when open (default a right chevron). */ toggleIcon?: IconContent; /** * Sets a fixed viewport height and windows the rows through `VirtualList`, so only the visible * ones are in the DOM. Use it past a few hundred visible nodes. Rows must then be uniform * height: set `--tree-node-height` rather than sizing individual rows. */ height?: number | string; /** Row height used by the windowed renderer before measurement (default `32`). */ estimatedRowHeight?: number; disabled?: boolean; 'aria-label'?: string; className?: string; style?: CSSProperties; classNames?: SlotClassNames; styles?: SlotStyles; /** Overrides the text Tree renders of its own. Merged per key. */ labels?: TreeLabels; }