import React from "react"; import { CheckTreeProps } from "../checktree"; import { StyledProps } from "../_type/StyledProps"; import { EventHandlerProps } from "../_util/merge-event-props"; import { TreeContextValue } from "./TreeContext"; export type TreeNodeEventData = TreeNodeProps & Record; export interface TreeNodeProps extends StyledProps, Omit { /** * 节点 ID,整棵树中唯一 */ id: string; /** * 节点内容 */ content: React.ReactNode; /** * 节点图标 * * @docType React.ReactNode | (context: { expanded: boolean }) => React.ReactNode */ icon?: | ((context: { expanded: boolean }) => React.ReactNode) | React.ReactNode; /** * hover 后展示的操作 * * 推荐使用文字(TreeNode.ActionLink),若超过一项,建议收至 Dropdown 下 */ operation?: React.ReactNode; /** * 当树为 selectable 时,设置当前节点是否展示 Checkbox * * @default true */ selectable?: boolean; /** * 当树为 selectable 时,设置当前节点 Checkbox 是否禁用 * * @default false */ disableSelect?: boolean; /** * 当前节点是否支持展开(用于异步加载) * * @default false */ expandable?: boolean; /** * 当前节点是否不需要附加样式(如 Hover 样式) * * @default false * @since 2.2.4 */ pure?: boolean; /** * 包含的树节点 */ children?: React.ReactNode; /** * 节点高度,可作用于虚拟滚动 * @default 32 */ height?: number; /** * 是否是过滤剩下的 * @default true */ isFiltered?: boolean; } export interface TreeData extends Omit { /** * 子节点数据 */ children?: TreeData[]; } export interface TreeProps extends StyledProps { /** * 树节点数据,如果设置则无需手动构造 */ data?: TreeData[]; /** * 是否默认展开所有树节点 * @default false * @since 2.7.0 */ defaultExpandAll?: boolean; /** * 是否默认展开 `defaultExpandedIds` 中结点的父节点 * @default true * @since 2.7.0 */ defaultExpandParent?: boolean; /** * 默认展开的节点 */ defaultExpandedIds?: string[]; /** * 展开的节点(受控) */ expandedIds?: string[]; /** * 展开/收起事件回调 */ onExpand?: ( expandedIds: string[], context?: { expanded: boolean; nodeId: string; event: React.MouseEvent; data: TreeNodeEventData; } ) => void; /** * 子节点展开时是否强制展开父节点 * * **如果包含展开的子节点,父节点无法收起** * * @default false * @since 2.7.0 */ forceExpandParent?: boolean; /** * 是否点击整个节点范围可控制展开 * * *默认点击范围为图标区域* * * @default false * @since 2.4.0 */ fullExpandable?: boolean; /** * 树节点是否支持选择 * * @default false */ selectable?: boolean; /** * 节点选择是否完全受控(父子节点状态取消关联) * * @default false */ selectStrictly?: boolean; /** * 默认选中的节点 */ defaultSelectedIds?: string[]; /** * 选中的节点(受控) */ selectedIds?: string[]; /** * 选择事件回调 */ onSelect?: ( selectedIds: string[], context?: { selected: boolean; nodeId: string; event: React.MouseEvent } ) => void; /** * 结点选择值的描述方式 * * *影响 `selectedIds` 和 `onSelect` 值的格式* * * - `"all"` - 使用全部层级 * - `"onlyLeaf"` - 仅使用子节点 * - `"parentFirst"` - 当子节点全部选中时,仅使用父节点 * * @default "all" * @since 2.7.0 */ selectValueMode?: CheckTreeProps["valueMode"]; /** * 树节点是否支持点击高亮 * * @default false */ activable?: boolean; /** * 是否点击整个节点范围可控制高亮 * * @default false * @since 2.7.0 */ fullActivable?: boolean; /** * 默认高亮的节点 */ defaultActiveIds?: string[]; /** * 高亮的节点(受控) */ activeIds?: string[]; /** * 点击高亮事件回调 */ onActive?: ( activeIds: string[], context?: { active: boolean; nodeId: string; event: React.MouseEvent; data: TreeNodeEventData; } ) => void; /** * 异步加载数据 * * **需要返回 Promise** * * 节点展开时在 onExpand 前被调用,直到 Promise resolve 后调用 onExpand */ onLoad?: TreeContextValue["onLoad"]; /** * 异步加载数据失败回调 * * onLoad Promise reject 后调用 */ onLoadError?: TreeContextValue["onLoadError"]; /** * 树节点的展开/收起图标 * * @docType React.ReactNode | (context: { expanded: boolean }) => React.ReactNode */ switcherIcon?: TreeContextValue["switcherIcon"]; /** * 包含的树节点 */ children?: React.ReactNode; /** * 虚拟滚动容器高度 * * 可设置统一 height 或 [minHeight, maxHeight] * * @since 2.7.0 */ height?: string | number | [number, number]; /** * 是否处于过滤状态 */ filterState?: boolean; /** * 自定义过滤函数 */ filter?: (node: TreeData) => boolean; }