Skip to content

Commit c9a7126

Browse files
committed
refactor: move rowClass in
1 parent ba03688 commit c9a7126

File tree

4 files changed

+20
-15
lines changed

4 files changed

+20
-15
lines changed

docs/examples/virtual.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,8 @@ const Demo = () => {
205205
expandedRowRender: () => 2333,
206206
columnWidth: 60,
207207
}}
208-
onRow={() => ({ className: 'rowed' })}
208+
// onRow={() => ({ className: 'rowed' })}
209+
rowClassName="nice-try"
209210
/>
210211
</div>
211212
);

src/Body/BodyRow.tsx

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -103,11 +103,10 @@ function BodyRow<RecordType extends { children?: readonly RecordType[] }>(
103103
cellComponent,
104104
scopeCellComponent,
105105
} = props;
106-
const rowInfo = useRowInfo(record, rowKey, index);
106+
const rowInfo = useRowInfo(record, rowKey, index, indent);
107107
const {
108108
prefixCls,
109109
flattenColumns,
110-
rowClassName,
111110
expandedRowClassName,
112111
expandedRowRender,
113112
rowProps,
@@ -130,13 +129,6 @@ function BodyRow<RecordType extends { children?: readonly RecordType[] }>(
130129
}, [expanded]);
131130

132131
// ======================== Base tr row ========================
133-
let computeRowClassName: string;
134-
if (typeof rowClassName === 'string') {
135-
computeRowClassName = rowClassName;
136-
} else if (typeof rowClassName === 'function') {
137-
computeRowClassName = rowClassName(record, index, indent);
138-
}
139-
140132
const baseRowNode = (
141133
<RowComponent
142134
{...rowProps}
@@ -145,7 +137,6 @@ function BodyRow<RecordType extends { children?: readonly RecordType[] }>(
145137
className,
146138
`${prefixCls}-row`,
147139
`${prefixCls}-row-level-${indent}`,
148-
computeRowClassName,
149140
rowProps?.className,
150141
)}
151142
style={{

src/StaticTable/BodyLine.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@ const BodyLine = React.forwardRef<HTMLDivElement, BodyLineProps>((props, ref) =>
3131
]);
3232
const { scrollX } = useContext(StaticContext, ['scrollX']);
3333

34-
const rowInfo = useRowInfo(record, rowKey, index);
34+
const rowInfo = useRowInfo(record, rowKey, index, indent);
3535

3636
// ========================== Expand ==========================
37-
const { rowSupportExpand, expanded } = rowInfo;
37+
const { rowSupportExpand, expanded, rowProps } = rowInfo;
3838

3939
let expandRowNode: React.ReactElement;
4040
if (rowSupportExpand && expanded) {
@@ -55,12 +55,13 @@ const BodyLine = React.forwardRef<HTMLDivElement, BodyLineProps>((props, ref) =>
5555

5656
const rowNode = (
5757
<div
58+
{...rowProps}
5859
{...restProps}
5960
ref={rowSupportExpand ? null : ref}
60-
className={classNames(className, `${prefixCls}-row`, {
61+
className={classNames(className, `${prefixCls}-row`, rowProps?.className, {
6162
[`${prefixCls}-row-extra`]: extra,
6263
})}
63-
style={rowStyle}
64+
style={{ ...rowStyle, ...rowProps?.style }}
6465
>
6566
{flattenColumns.map((column, colIndex) => {
6667
return (

src/hooks/useRowInfo.tsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@ import type { TableContextProps } from '../context/TableContext';
33
import TableContext from '../context/TableContext';
44
import { getColumnsKey } from '../utils/valueUtil';
55
import { useEvent } from 'rc-util';
6+
import classNames from 'classnames';
67

78
export default function useRowInfo<RecordType>(
89
record: RecordType,
910
rowKey: React.Key,
1011
recordIndex: number,
12+
indent: number,
1113
): Pick<
1214
TableContextProps,
1315
| 'prefixCls'
@@ -63,6 +65,7 @@ export default function useRowInfo<RecordType>(
6365
rowExpandable,
6466
onRow,
6567
expandRowByClick,
68+
rowClassName,
6669
} = context;
6770

6871
// ======================= Expandable =======================
@@ -90,6 +93,14 @@ export default function useRowInfo<RecordType>(
9093
onRowClick?.(event, ...args);
9194
};
9295

96+
// ====================== RowClassName ======================
97+
let computeRowClassName: string;
98+
if (typeof rowClassName === 'string') {
99+
computeRowClassName = rowClassName;
100+
} else if (typeof rowClassName === 'function') {
101+
computeRowClassName = rowClassName(record, recordIndex, indent);
102+
}
103+
93104
// ========================= Column =========================
94105
const columnsKey = getColumnsKey(flattenColumns);
95106

@@ -105,6 +116,7 @@ export default function useRowInfo<RecordType>(
105116
expandable: mergedExpandable,
106117
rowProps: {
107118
...rowProps,
119+
className: classNames(computeRowClassName, rowProps?.className),
108120
onClick,
109121
},
110122
};

0 commit comments

Comments
 (0)