mirror of
https://gitee.com/ant-design/ant-design.git
synced 2024-12-04 21:18:01 +08:00
1719748a29
* chore: eslint add consistent-type-imports * fix avatar * Update Item.tsx
32 lines
911 B
TypeScript
32 lines
911 B
TypeScript
import * as React from 'react';
|
|
import type { TransformColumns, ColumnTitleProps, ColumnsType } from '../interface';
|
|
import { renderColumnTitle } from '../util';
|
|
|
|
function fillTitle<RecordType>(
|
|
columns: ColumnsType<RecordType>,
|
|
columnTitleProps: ColumnTitleProps<RecordType>,
|
|
) {
|
|
return columns.map(column => {
|
|
const cloneColumn = { ...column };
|
|
|
|
cloneColumn.title = renderColumnTitle(column.title, columnTitleProps);
|
|
|
|
if ('children' in cloneColumn) {
|
|
cloneColumn.children = fillTitle(cloneColumn.children, columnTitleProps);
|
|
}
|
|
|
|
return cloneColumn;
|
|
});
|
|
}
|
|
|
|
export default function useTitleColumns<RecordType>(
|
|
columnTitleProps: ColumnTitleProps<RecordType>,
|
|
): [TransformColumns<RecordType>] {
|
|
const filledColumns = React.useCallback(
|
|
(columns: ColumnsType<RecordType>) => fillTitle(columns, columnTitleProps),
|
|
[columnTitleProps],
|
|
);
|
|
|
|
return [filledColumns];
|
|
}
|