UNPKG

@douyinfe/semi-ui

Version:

A modern, comprehensive, flexible design system and UI library. Connect DesignOps & DevOps. Quickly build beautiful React apps. Maintained by Douyin-fe team.

129 lines (128 loc) 5.4 kB
import React, { ReactNode } from 'react'; import PropTypes from 'prop-types'; import { TableCellAdapter } from '@douyinfe/semi-foundation/lib/cjs/table/cellFoundation'; import BaseComponent, { BaseProps } from '../_base/baseComponent'; import { TableContextProps } from './table-context'; import { ColumnProps, ExpandIcon } from './interface'; export interface TableCellProps extends BaseProps { record?: Record<string, any>; prefixCls?: string; index?: number; fixedLeft?: boolean | number; lastFixedLeft?: boolean; fixedRight?: boolean | number; firstFixedRight?: boolean; indent?: number; indentSize?: number; column?: ColumnProps; /** * Does the first column include expandIcon * When hideExpandedColumn is true or isSection is true * expandIcon is a custom icon or true */ expandIcon?: ExpandIcon; renderExpandIcon?: (record: Record<string, any>) => ReactNode; hideExpandedColumn?: boolean; component?: any; onClick?: (record: Record<string, any>, e: React.MouseEvent) => void; onDidUpdate?: (ref: React.MutableRefObject<any>) => void; isSection?: boolean; width?: string | number; height?: string | number; selected?: boolean; expanded?: boolean; disabled?: boolean; colIndex?: number; } export default class TableCell extends BaseComponent<TableCellProps, Record<string, any>> { static contextType: React.Context<TableContextProps>; static defaultProps: { indent: number; indentSize: 20; onClick: (...args: any[]) => void; prefixCls: "semi-table"; component: string; onDidUpdate: (...args: any[]) => void; column: {}; }; static propTypes: { record: PropTypes.Requireable<object>; prefixCls: PropTypes.Requireable<string>; index: PropTypes.Requireable<number>; fixedLeft: PropTypes.Requireable<NonNullable<number | boolean>>; lastFixedLeft: PropTypes.Requireable<boolean>; fixedRight: PropTypes.Requireable<NonNullable<number | boolean>>; firstFixedRight: PropTypes.Requireable<boolean>; indent: PropTypes.Requireable<number>; indentSize: PropTypes.Requireable<number>; column: PropTypes.Requireable<object>; expandIcon: PropTypes.Requireable<any>; renderExpandIcon: PropTypes.Requireable<(...args: any[]) => any>; hideExpandedColumn: PropTypes.Requireable<boolean>; component: PropTypes.Requireable<any>; onClick: PropTypes.Requireable<(...args: any[]) => any>; onDidUpdate: PropTypes.Requireable<(...args: any[]) => any>; isSection: PropTypes.Requireable<boolean>; width: PropTypes.Requireable<NonNullable<string | number>>; height: PropTypes.Requireable<NonNullable<string | number>>; selected: PropTypes.Requireable<boolean>; expanded: PropTypes.Requireable<boolean>; colIndex: PropTypes.Requireable<number>; }; get adapter(): TableCellAdapter; ref: React.MutableRefObject<any>; context: TableContextProps; constructor(props: TableCellProps); /** * Control whether to execute the render function of the cell * 1. Scenes that return true * - The cell contains the selection state, you need to calculate whether its selection state has changed during selection * - The cell contains the folding state, it needs to be calculated when the folding state has changed * 2. Scenarios that return false * - Cells without table operation operation status, only need to judge that their props have changed * At this time, the update of the table cell is controlled by the user. At this time, its update will not affect other cells * * 控制是否执行cell的render函数 * 1. 返回true的场景 * - cell内包含选择状态,需要在选择时计算它的选择态是否发生变化 * - cell内包含折叠状态,需要在折叠时计算它的折叠态是否发生了变化 * 2. 返回false的场景 * - 没有table操作操作状态的cell,只需判断自己的props发生了变化 * 此时table cell的更新由用户自己控制,此时它的更新不会影响其他cell * * @param {*} nextProps * @returns */ shouldComponentUpdate(nextProps: TableCellProps): boolean; componentDidUpdate(): void; setRef: (ref: React.MutableRefObject<any>) => React.MutableRefObject<any>; handleClick: (e: React.MouseEvent) => void; getTdProps(): { tdProps: { style?: Partial<React.CSSProperties>; }; customCellProps: {}; }; /** * We should return undefined if no dataIndex is specified, but in order to * be compatible with object-path's behavior, we return the record object instead. */ renderText(tdProps: { style?: React.CSSProperties; colSpan?: number; rowSpan?: number; }): { text: any; indentText: React.JSX.Element; rowSpan: number; colSpan: number; realExpandIcon: React.ReactNode; tdProps: { style?: React.CSSProperties; colSpan?: number; rowSpan?: number; }; }; renderInner(text: ReactNode, indentText: ReactNode, realExpandIcon: ReactNode): any; render(): React.JSX.Element; }