Skip to content

Commit 2e316a0

Browse files
committed
chore: optimize code
1 parent b32e21c commit 2e316a0

File tree

3 files changed

+14
-14
lines changed

3 files changed

+14
-14
lines changed

packages/components/table/Cell.tsx

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
import React, { MouseEvent, MutableRefObject, ReactNode } from 'react';
22
import classNames from 'classnames';
3-
import { isFunction, get } from 'lodash-es';
3+
import { get, isFunction } from 'lodash-es';
4+
45
import TEllipsis from './Ellipsis';
5-
import { BaseTableCellParams, RowspanColspan, TableRowData, TdBaseTableProps } from './type';
6-
import { RowAndColFixedPosition } from './interface';
6+
import useClassName from './hooks/useClassName';
77
import { getColumnFixedStyles } from './hooks/useFixed';
8-
import { TableClassName } from './hooks/useClassName';
98
import { formatClassNames } from './utils';
10-
import { TooltipProps } from '../tooltip';
11-
import { PaginationProps } from '../pagination';
9+
10+
import type { PaginationProps } from '../pagination';
11+
import type { TooltipProps } from '../tooltip';
12+
import type { RowAndColFixedPosition } from './interface';
13+
import type { BaseTableCellParams, RowspanColspan, TableRowData, TdBaseTableProps } from './type';
1214

1315
export interface RenderEllipsisCellParams {
1416
cellNode: ReactNode;
@@ -25,7 +27,6 @@ export interface CellProps {
2527
dataLength: number;
2628
cellSpans: RowspanColspan;
2729
cellEmptyContent: TdBaseTableProps['cellEmptyContent'];
28-
tableClassNames: TableClassName;
2930
tableRef?: MutableRefObject<HTMLDivElement>;
3031
classPrefix?: string;
3132
overlayClassName?: string;
@@ -94,11 +95,11 @@ function renderEllipsisCell(cellParams: BaseTableCellParams<TableRowData>, param
9495
}
9596

9697
const Cell = (props: CellProps) => {
97-
const { cellParams, tableClassNames, tableRef, columnLength, classPrefix, overlayClassName, pagination } = props;
98+
const { cellParams, tableRef, columnLength, classPrefix, overlayClassName, pagination } = props;
9899
const { col, colIndex, rowIndex } = cellParams;
99100
const { cellSpans, dataLength, rowAndColFixedPosition, cellEmptyContent, rowspanAndColspan, onClick } = props;
100101
const { tableColFixedClasses, tdEllipsisClass, tableBaseClass, tdAlignClasses, tableDraggableClasses } =
101-
tableClassNames;
102+
useClassName();
102103

103104
const cellNode = renderCell(cellParams, { cellEmptyContent, pagination });
104105
const tdStyles = getColumnFixedStyles(col, colIndex, rowAndColFixedPosition, tableColFixedClasses);

packages/components/table/TBody.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* eslint-disable no-underscore-dangle */
2-
import React, { type CSSProperties, type MutableRefObject, type ReactNode, useMemo } from 'react';
32
import classNames from 'classnames';
43
import { camelCase, get, pick } from 'lodash-es';
4+
import React, { type CSSProperties, type MutableRefObject, type ReactNode, useMemo } from 'react';
55
import { useLocaleReceiver } from '../locale/LocalReceiver';
66
import { TableClassName } from './hooks/useClassName';
77
import useRowspanAndColspan from './hooks/useRowspanAndColspan';
@@ -217,7 +217,7 @@ export default function TBody(props: TableBodyProps) {
217217

218218
// 垫上隐藏的 tr 元素高度
219219
const translate = `translateY(${virtualConfig.translateY}px)`;
220-
const posStyle: CSSProperties = isVirtualScroll
220+
const posStyle = isVirtualScroll
221221
? ({
222222
transform: translate,
223223
msTransform: translate,

packages/components/table/TR.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ export default function TR(props: TrProps) {
8787
const classNames = useClassName();
8888

8989
const trStyles = getRowFixedStyles(
90-
get(row, rowKey || 'id'),
90+
get(row, rowKey),
9191
rowIndex,
9292
dataLength,
9393
fixedRows,
@@ -102,7 +102,7 @@ export default function TR(props: TrProps) {
102102
);
103103

104104
const classes = useMemo(() => {
105-
const customClasses = formatRowClassNames(rowClassName, { row, rowIndex, rowKey, type: 'body' }, rowKey || 'id');
105+
const customClasses = formatRowClassNames(rowClassName, { row, rowIndex, rowKey, type: 'body' }, rowKey);
106106
return [trStyles?.classes, customClasses];
107107
}, [row, rowClassName, rowIndex, rowKey, trStyles?.classes]);
108108

@@ -151,7 +151,6 @@ export default function TR(props: TrProps) {
151151
columnLength={props.columns.length}
152152
cellSpans={cellSpans}
153153
cellEmptyContent={props.cellEmptyContent}
154-
tableClassNames={classNames}
155154
rowspanAndColspan={props.rowspanAndColspan}
156155
onClick={onClick}
157156
tableRef={props.tableRef}

0 commit comments

Comments
 (0)