Tree.d.ts 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. import type { Component } from 'react';
  2. import React from 'react';
  3. import type { BasicDataNode, TreeProps as RcTreeProps } from 'rc-tree';
  4. import RcTree from 'rc-tree';
  5. import type { DataNode, Key } from 'rc-tree/lib/interface';
  6. export type SwitcherIcon = React.ReactNode | ((props: AntTreeNodeProps) => React.ReactNode);
  7. export type TreeLeafIcon = React.ReactNode | ((props: AntTreeNodeProps) => React.ReactNode);
  8. type TreeIcon = React.ReactNode | ((props: AntdTreeNodeAttribute) => React.ReactNode);
  9. export interface AntdTreeNodeAttribute {
  10. eventKey: string;
  11. prefixCls: string;
  12. className: string;
  13. expanded: boolean;
  14. selected: boolean;
  15. checked: boolean;
  16. halfChecked: boolean;
  17. children: React.ReactNode;
  18. title: React.ReactNode;
  19. pos: string;
  20. dragOver: boolean;
  21. dragOverGapTop: boolean;
  22. dragOverGapBottom: boolean;
  23. isLeaf: boolean;
  24. selectable: boolean;
  25. disabled: boolean;
  26. disableCheckbox: boolean;
  27. }
  28. export interface AntTreeNodeProps {
  29. className?: string;
  30. checkable?: boolean;
  31. disabled?: boolean;
  32. disableCheckbox?: boolean;
  33. title?: React.ReactNode | ((data: DataNode) => React.ReactNode);
  34. key?: Key;
  35. eventKey?: Key;
  36. isLeaf?: boolean;
  37. checked?: boolean;
  38. expanded?: boolean;
  39. loading?: boolean;
  40. selected?: boolean;
  41. selectable?: boolean;
  42. icon?: TreeIcon;
  43. children?: React.ReactNode;
  44. [customProp: string]: any;
  45. }
  46. export interface AntTreeNode extends Component<AntTreeNodeProps> {
  47. }
  48. export interface AntTreeNodeBaseEvent {
  49. node: AntTreeNode;
  50. nativeEvent: MouseEvent;
  51. }
  52. export interface AntTreeNodeCheckedEvent extends AntTreeNodeBaseEvent {
  53. event: 'check';
  54. checked?: boolean;
  55. checkedNodes?: AntTreeNode[];
  56. }
  57. export interface AntTreeNodeSelectedEvent extends AntTreeNodeBaseEvent {
  58. event: 'select';
  59. selected?: boolean;
  60. selectedNodes?: DataNode[];
  61. }
  62. export interface AntTreeNodeExpandedEvent extends AntTreeNodeBaseEvent {
  63. expanded?: boolean;
  64. }
  65. export interface AntTreeNodeMouseEvent {
  66. node: AntTreeNode;
  67. event: React.DragEvent<HTMLElement>;
  68. }
  69. export interface AntTreeNodeDragEnterEvent extends AntTreeNodeMouseEvent {
  70. expandedKeys: Key[];
  71. }
  72. export interface AntTreeNodeDropEvent {
  73. node: AntTreeNode;
  74. dragNode: AntTreeNode;
  75. dragNodesKeys: Key[];
  76. dropPosition: number;
  77. dropToGap?: boolean;
  78. event: React.MouseEvent<HTMLElement>;
  79. }
  80. export type TreeNodeNormal = DataNode;
  81. type DraggableFn = (node: DataNode) => boolean;
  82. interface DraggableConfig {
  83. icon?: React.ReactNode;
  84. nodeDraggable?: DraggableFn;
  85. }
  86. export interface TreeProps<T extends BasicDataNode = DataNode> extends Omit<RcTreeProps<T>, 'prefixCls' | 'showLine' | 'direction' | 'draggable' | 'icon' | 'switcherIcon'> {
  87. showLine?: boolean | {
  88. showLeafIcon: boolean | TreeLeafIcon;
  89. };
  90. className?: string;
  91. /** Whether to support multiple selection */
  92. multiple?: boolean;
  93. /** Whether to automatically expand the parent node */
  94. autoExpandParent?: boolean;
  95. /** Node selection in Checkable state is fully controlled (the selected state of parent and child nodes is no longer associated) */
  96. checkStrictly?: boolean;
  97. /** Whether to support selection */
  98. checkable?: boolean;
  99. /** whether to disable the tree */
  100. disabled?: boolean;
  101. /** Expand all tree nodes by default */
  102. defaultExpandAll?: boolean;
  103. /** Expand the corresponding tree node by default */
  104. defaultExpandParent?: boolean;
  105. /** Expand the specified tree node by default */
  106. defaultExpandedKeys?: Key[];
  107. /** (Controlled) Expand the specified tree node */
  108. expandedKeys?: Key[];
  109. /** (Controlled) Tree node with checked checkbox */
  110. checkedKeys?: Key[] | {
  111. checked: Key[];
  112. halfChecked: Key[];
  113. };
  114. /** Tree node with checkbox checked by default */
  115. defaultCheckedKeys?: Key[];
  116. /** (Controlled) Set the selected tree node */
  117. selectedKeys?: Key[];
  118. /** Tree node selected by default */
  119. defaultSelectedKeys?: Key[];
  120. selectable?: boolean;
  121. /** Click on the tree node to trigger */
  122. filterAntTreeNode?: (node: AntTreeNode) => boolean;
  123. loadedKeys?: Key[];
  124. /** Set the node to be draggable (IE>8) */
  125. draggable?: DraggableFn | boolean | DraggableConfig;
  126. style?: React.CSSProperties;
  127. showIcon?: boolean;
  128. icon?: TreeIcon;
  129. switcherIcon?: SwitcherIcon;
  130. switcherLoadingIcon?: React.ReactNode;
  131. prefixCls?: string;
  132. children?: React.ReactNode;
  133. blockNode?: boolean;
  134. }
  135. declare const Tree: React.ForwardRefExoticComponent<TreeProps<DataNode> & React.RefAttributes<RcTree<DataNode>>>;
  136. export default Tree;