Skip to content

Commit

Permalink
feat: table组件增加泛型 (#11309)
Browse files Browse the repository at this point in the history
  • Loading branch information
hzh11012 authored Dec 3, 2024
1 parent fcf07ff commit fb49ae4
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 7 deletions.
4 changes: 3 additions & 1 deletion packages/amis/src/renderers/Table/TableBody.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,9 @@ export interface TableBodyProps extends LocaleProps {
}

@observer
export class TableBody extends React.Component<TableBodyProps> {
export class TableBody<
T extends TableBodyProps = TableBodyProps
> extends React.Component<T> {
componentDidMount(): void {
this.props.store.initTableWidth();
}
Expand Down
4 changes: 3 additions & 1 deletion packages/amis/src/renderers/Table/TableContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,9 @@ export function renderItemActions(
);
}

export class TableContent extends React.PureComponent<TableContentProps> {
export class TableContent<
T extends TableContentProps = TableContentProps
> extends React.PureComponent<T> {
render() {
const {
placeholder,
Expand Down
8 changes: 5 additions & 3 deletions packages/amis/src/renderers/Table/TableRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {Action} from '../Action';
import {isClickOnInput} from 'amis-core';
import {useInView} from 'react-intersection-observer';

interface TableRowProps extends Pick<RendererProps, 'render'> {
export interface TableRowProps extends Pick<RendererProps, 'render'> {
store: ITableStore;
onCheck: (item: IRow, value: boolean, shift?: boolean) => Promise<void>;
onRowClick: (item: IRow, index: number) => Promise<RendererEvent<any> | void>;
Expand Down Expand Up @@ -51,8 +51,10 @@ interface TableRowProps extends Pick<RendererProps, 'render'> {
[propName: string]: any;
}

export class TableRow extends React.PureComponent<
TableRowProps & {
export class TableRow<
T extends TableRowProps = TableRowProps
> extends React.PureComponent<
T & {
// 这些属性纯粹是为了监控变化,不要在 render 里面使用
expanded: boolean;
parentExpanded?: boolean;
Expand Down
6 changes: 4 additions & 2 deletions packages/amis/src/renderers/Table/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,9 @@ export type TableRendererAction =
| 'initDrag'
| 'cancelDrag';

export default class Table extends React.Component<TableProps, object> {
export default class Table<
T extends TableProps = TableProps
> extends React.Component<T, object> {
static contextType = ScopedContext;

static propsList: Array<string> = [
Expand Down Expand Up @@ -573,7 +575,7 @@ export default class Table extends React.Component<TableProps, object> {
}
);

constructor(props: TableProps, context: IScopedContext) {
constructor(props: T, context: IScopedContext) {
super(props);

const scoped = context;
Expand Down

0 comments on commit fb49ae4

Please sign in to comment.