import * as React from 'react'; import type { AnyObject } from 'antd/es/_util/type'; import type { ColumnGroupType, ColumnsType, ColumnTitleProps, ColumnType, TransformColumns, } from '../interface'; import { renderColumnTitle } from '../util'; const fillTitle = ( columns: ColumnsType, columnTitleProps: ColumnTitleProps, ) => { const finalColumns = columns.map((column) => { const cloneColumn: ColumnGroupType | ColumnType = { ...column }; cloneColumn.title = renderColumnTitle(column.title, columnTitleProps); if ('children' in cloneColumn) { cloneColumn.children = fillTitle(cloneColumn.children, columnTitleProps); } return cloneColumn; }); return finalColumns; }; const useTitleColumns = ( columnTitleProps: ColumnTitleProps, ) => { const filledColumns = React.useCallback>( (columns) => fillTitle(columns, columnTitleProps), [columnTitleProps], ); return [filledColumns] as const; }; export default useTitleColumns;