interface.d.ts 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. import * as React from 'react';
  2. export type { ScrollTo } from 'rc-virtual-list/lib/List';
  3. export interface TreeNodeProps<TreeDataType extends BasicDataNode = DataNode> {
  4. eventKey?: Key;
  5. prefixCls?: string;
  6. className?: string;
  7. style?: React.CSSProperties;
  8. id?: string;
  9. expanded?: boolean;
  10. selected?: boolean;
  11. checked?: boolean;
  12. loaded?: boolean;
  13. loading?: boolean;
  14. halfChecked?: boolean;
  15. title?: React.ReactNode | ((data: TreeDataType) => React.ReactNode);
  16. dragOver?: boolean;
  17. dragOverGapTop?: boolean;
  18. dragOverGapBottom?: boolean;
  19. pos?: string;
  20. domRef?: React.Ref<HTMLDivElement>;
  21. /** New added in Tree for easy data access */
  22. data?: TreeDataType;
  23. isStart?: boolean[];
  24. isEnd?: boolean[];
  25. active?: boolean;
  26. onMouseMove?: React.MouseEventHandler<HTMLDivElement>;
  27. isLeaf?: boolean;
  28. checkable?: boolean;
  29. selectable?: boolean;
  30. disabled?: boolean;
  31. disableCheckbox?: boolean;
  32. icon?: IconType;
  33. switcherIcon?: IconType;
  34. children?: React.ReactNode;
  35. }
  36. /** For fieldNames, we provides a abstract interface */
  37. export interface BasicDataNode {
  38. checkable?: boolean;
  39. disabled?: boolean;
  40. disableCheckbox?: boolean;
  41. icon?: IconType;
  42. isLeaf?: boolean;
  43. selectable?: boolean;
  44. switcherIcon?: IconType;
  45. /** Set style of TreeNode. This is not recommend if you don't have any force requirement */
  46. className?: string;
  47. style?: React.CSSProperties;
  48. }
  49. /** Provide a wrap type define for developer to wrap with customize fieldNames data type */
  50. export type FieldDataNode<T, ChildFieldName extends string = 'children'> = BasicDataNode & T & Partial<Record<ChildFieldName, FieldDataNode<T, ChildFieldName>[]>>;
  51. export type Key = React.Key;
  52. /**
  53. * Typescript not support `bigint` as index type yet.
  54. * We use this to mark the `bigint` type is for `Key` usage.
  55. * It's safe to remove this when typescript fix:
  56. * https://github.com/microsoft/TypeScript/issues/50217
  57. */
  58. export type SafeKey = Exclude<Key, bigint>;
  59. export type KeyEntities<DateType extends BasicDataNode = any> = Record<SafeKey, DataEntity<DateType>>;
  60. export type DataNode = FieldDataNode<{
  61. key: Key;
  62. title?: React.ReactNode | ((data: DataNode) => React.ReactNode);
  63. }>;
  64. export type EventDataNode<TreeDataType> = {
  65. key: Key;
  66. expanded: boolean;
  67. selected: boolean;
  68. checked: boolean;
  69. loaded: boolean;
  70. loading: boolean;
  71. halfChecked: boolean;
  72. dragOver: boolean;
  73. dragOverGapTop: boolean;
  74. dragOverGapBottom: boolean;
  75. pos: string;
  76. active: boolean;
  77. } & TreeDataType & BasicDataNode;
  78. export type IconType = React.ReactNode | ((props: TreeNodeProps) => React.ReactNode);
  79. export type NodeElement = React.ReactElement<TreeNodeProps> & {
  80. selectHandle?: HTMLSpanElement;
  81. type: {
  82. isTreeNode: boolean;
  83. };
  84. };
  85. export type NodeInstance<TreeDataType extends BasicDataNode = DataNode> = React.Component<TreeNodeProps<TreeDataType>> & {
  86. selectHandle?: HTMLSpanElement;
  87. };
  88. export interface Entity {
  89. node: NodeElement;
  90. index: number;
  91. key: Key;
  92. pos: string;
  93. parent?: Entity;
  94. children?: Entity[];
  95. }
  96. export interface DataEntity<TreeDataType extends BasicDataNode = DataNode> extends Omit<Entity, 'node' | 'parent' | 'children'> {
  97. node: TreeDataType;
  98. nodes: TreeDataType[];
  99. parent?: DataEntity<TreeDataType>;
  100. children?: DataEntity<TreeDataType>[];
  101. level: number;
  102. }
  103. export interface FlattenNode<TreeDataType extends BasicDataNode = DataNode> {
  104. parent: FlattenNode<TreeDataType> | null;
  105. children: FlattenNode<TreeDataType>[];
  106. pos: string;
  107. data: TreeDataType;
  108. title: React.ReactNode;
  109. key: Key;
  110. isStart: boolean[];
  111. isEnd: boolean[];
  112. }
  113. export type GetKey<RecordType> = (record: RecordType, index?: number) => Key;
  114. export type GetCheckDisabled<RecordType> = (record: RecordType) => boolean;
  115. export type Direction = 'ltr' | 'rtl' | undefined;
  116. export interface FieldNames {
  117. title?: string;
  118. /** @private Internal usage for `rc-tree-select`, safe to remove if no need */
  119. _title?: string[];
  120. key?: string;
  121. children?: string;
  122. }