8f76d0ed347c1ad6fe8f9214d8e0cff79cd4fa3d503f5c94346dc44cedc731b162b790d10d8e2840cb40957b6a64278db10c19badced8a30666ddbde81408c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. import type { CSSProperties, FunctionalComponent, RendererElement, RendererNode, VNode } from 'vue';
  2. import type { ColumnAlignment } from 'element-plus/es/constants';
  3. import type { FixedDir, SortOrder } from './constants';
  4. export type Alignment = ColumnAlignment;
  5. export type FixedDirection = FixedDir;
  6. export type KeyType = string | number | symbol;
  7. /**
  8. * Param types
  9. */
  10. export type CellRendererParams<T> = {
  11. cellData: T;
  12. } & RowCommonParams & ColumnCommonParams<T>;
  13. export type ColumnCommonParams<T> = {
  14. columns: Column<T>[];
  15. column: Column<T>;
  16. columnIndex: number;
  17. };
  18. export type HeaderCellRendererParams<T> = {
  19. headerIndex: number;
  20. } & ColumnCommonParams<T>;
  21. export type RowCommonParams = {
  22. rowData: any;
  23. rowIndex: number;
  24. };
  25. export type ClassNameGetterParams<T> = {
  26. cellData: T;
  27. } & RowCommonParams & ColumnCommonParams<T>;
  28. export type DataGetterParams<T> = {
  29. columns: Column<T>[];
  30. column: Column<T>;
  31. columnIndex: number;
  32. } & RowCommonParams;
  33. export type DataGetter<T> = (params: DataGetterParams<T>) => T;
  34. export type ClassNameGetter<T> = (params: ClassNameGetterParams<T>) => string;
  35. export type HeaderClassGetter<T> = (params: ColumnCommonParams<T> & {
  36. headerIndex: number;
  37. }) => string;
  38. /**
  39. * Renderer/Getter types
  40. */
  41. export type CellRenderer<T> = (params: CellRendererParams<T>) => VNode;
  42. export type HeaderCellRenderer<T> = (params: HeaderCellRendererParams<T>) => VNode;
  43. export type Column<T = any> = {
  44. /**
  45. * Attributes
  46. */
  47. align?: Alignment;
  48. class?: string | ClassNameGetter<T>;
  49. key?: KeyType;
  50. dataKey?: KeyType;
  51. fixed?: true | FixedDirection;
  52. flexGrow?: CSSProperties['flexGrow'];
  53. flexShrink?: CSSProperties['flexShrink'];
  54. title?: string;
  55. hidden?: boolean;
  56. headerClass?: HeaderClassGetter<T> | string;
  57. maxWidth?: number;
  58. minWidth?: number;
  59. style?: CSSProperties;
  60. sortable?: boolean;
  61. width: number;
  62. /**
  63. * Renderers
  64. */
  65. cellRenderer?: CellRenderer<T>;
  66. headerCellRenderer?: HeaderCellRenderer<T>;
  67. /**
  68. * Extendable sections
  69. */
  70. [key: string]: any;
  71. };
  72. export type Columns<T> = Column<T>[];
  73. export type AnyColumns = Columns<any>;
  74. export type SortBy = {
  75. key: KeyType;
  76. order: SortOrder;
  77. };
  78. export type SortState = {
  79. [key: KeyType]: SortOrder;
  80. };
  81. export type CustomizedCellsType = VNode<RendererNode, RendererElement, {
  82. [key: string]: any;
  83. }>[];
  84. export type DefaultCellsType = VNode<RendererNode, RendererElement, {
  85. [key: string]: any;
  86. }>[][];
  87. export type ColumnCellsType = DefaultCellsType | CustomizedCellsType;
  88. export type TableV2CustomizedHeaderSlotParam<T = any> = {
  89. cells: VNode[];
  90. columns: Columns<T>;
  91. headerIndex: number;
  92. };
  93. export type SimpleFunctionalComponentProps<T extends object> = {
  94. class?: JSX.IntrinsicAttributes['class'];
  95. style?: CSSProperties;
  96. } & T;
  97. export type SimpleFunctionalComponent<E extends object = {
  98. [key: string]: any;
  99. }> = FunctionalComponent<SimpleFunctionalComponentProps<E>>;