Skip to content

Commit 8472c25

Browse files
refactor:table (#6267)
* refactor:table * docs:update & refactor: table type --------- Co-authored-by: tangjinzhou <[email protected]>
1 parent c1ed77f commit 8472c25

28 files changed

+1635
-1338
lines changed

components/style.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ import './time-picker/style';
3737
import './calendar/style';
3838
// import './date-picker/style';
3939
// import './slider/style';
40-
import './table/style';
40+
// import './table/style';
41+
4142
// import './progress/style';
4243
// import './timeline/style';
4344
// import './input-number/style';

components/table/Table.tsx

+72-116
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ import scrollTo from '../_util/scrollTo';
3434
import defaultLocale from '../locale/en_US';
3535
import type { SizeType } from '../config-provider';
3636
import devWarning from '../vc-util/devWarning';
37-
import type { CSSProperties, PropType } from 'vue';
37+
import type { CSSProperties } from 'vue';
3838
import { nextTick, reactive, ref, computed, defineComponent, toRef, watchEffect, watch } from 'vue';
3939
import type { DefaultRecordType } from '../vc-table/interface';
4040
import useBreakpoint from '../_util/hooks/useBreakpoint';
@@ -47,6 +47,17 @@ import { useProvideSlots, useProvideTableContext } from './context';
4747
import type { ContextSlots } from './context';
4848
import useColumns from './hooks/useColumns';
4949
import { convertChildrenToColumns } from './util';
50+
import {
51+
stringType,
52+
booleanType,
53+
arrayType,
54+
someType,
55+
functionType,
56+
objectType,
57+
} from '../_util/type';
58+
59+
// CSSINJS
60+
import useStyle from './style';
5061

5162
export type { ColumnsType, TablePaginationConfig };
5263

@@ -107,128 +118,68 @@ export interface TableProps<RecordType = DefaultRecordType>
107118

108119
export const tableProps = () => {
109120
return {
110-
prefixCls: { type: String as PropType<string>, default: undefined },
111-
columns: { type: Array as PropType<ColumnsType>, default: undefined },
112-
rowKey: { type: [String, Function] as PropType<TableProps['rowKey']>, default: undefined },
113-
tableLayout: { type: String as PropType<TableProps['tableLayout']>, default: undefined },
114-
rowClassName: {
115-
type: [String, Function] as PropType<TableProps['rowClassName']>,
116-
default: undefined,
117-
},
118-
title: { type: Function as PropType<TableProps['title']>, default: undefined },
119-
footer: { type: Function as PropType<TableProps['footer']>, default: undefined },
120-
id: { type: String as PropType<TableProps['id']>, default: undefined },
121-
showHeader: { type: Boolean as PropType<TableProps['showHeader']>, default: undefined },
122-
components: { type: Object as PropType<TableProps['components']>, default: undefined },
123-
customRow: { type: Function as PropType<TableProps['customRow']>, default: undefined },
124-
customHeaderRow: {
125-
type: Function as PropType<TableProps['customHeaderRow']>,
126-
default: undefined,
127-
},
128-
direction: { type: String as PropType<TableProps['direction']>, default: undefined },
129-
expandFixed: {
130-
type: [Boolean, String] as PropType<TableProps['expandFixed']>,
131-
default: undefined,
132-
},
133-
expandColumnWidth: {
134-
type: Number as PropType<TableProps['expandColumnWidth']>,
135-
default: undefined,
136-
},
137-
expandedRowKeys: {
138-
type: Array as PropType<TableProps['expandedRowKeys']>,
139-
default: undefined as TableProps['expandedRowKeys'],
140-
},
141-
defaultExpandedRowKeys: {
142-
type: Array as PropType<TableProps['defaultExpandedRowKeys']>,
143-
default: undefined as TableProps['defaultExpandedRowKeys'],
144-
},
145-
expandedRowRender: {
146-
type: Function as PropType<TableProps['expandedRowRender']>,
147-
default: undefined,
148-
},
149-
expandRowByClick: {
150-
type: Boolean as PropType<TableProps['expandRowByClick']>,
151-
default: undefined,
152-
},
153-
expandIcon: { type: Function as PropType<TableProps['expandIcon']>, default: undefined },
154-
onExpand: { type: Function as PropType<TableProps['onExpand']>, default: undefined },
155-
onExpandedRowsChange: {
156-
type: Function as PropType<TableProps['onExpandedRowsChange']>,
157-
default: undefined,
158-
},
159-
'onUpdate:expandedRowKeys': {
160-
type: Function as PropType<TableProps['onExpandedRowsChange']>,
161-
default: undefined,
162-
},
163-
defaultExpandAllRows: {
164-
type: Boolean as PropType<TableProps['defaultExpandAllRows']>,
165-
default: undefined,
166-
},
167-
indentSize: { type: Number as PropType<TableProps['indentSize']>, default: undefined },
121+
prefixCls: stringType<string>(),
122+
columns: arrayType<ColumnsType>(),
123+
rowKey: someType<TableProps['rowKey']>([String, Function]),
124+
tableLayout: stringType<TableProps['tableLayout']>(),
125+
rowClassName: someType<TableProps['rowClassName']>([String, Function]),
126+
title: functionType<TableProps['title']>(),
127+
footer: functionType<TableProps['footer']>(),
128+
id: stringType<TableProps['id']>(),
129+
showHeader: booleanType(),
130+
components: objectType<TableProps['components']>(),
131+
customRow: functionType<TableProps['customRow']>(),
132+
customHeaderRow: functionType<TableProps['customHeaderRow']>(),
133+
direction: stringType<TableProps['direction']>(),
134+
expandFixed: someType<TableProps['expandFixed']>([Boolean, String]),
135+
expandColumnWidth: Number,
136+
expandedRowKeys: arrayType<TableProps['expandedRowKeys']>(),
137+
defaultExpandedRowKeys: arrayType<TableProps['defaultExpandedRowKeys']>(),
138+
expandedRowRender: functionType<TableProps['expandedRowRender']>(),
139+
expandRowByClick: booleanType(),
140+
expandIcon: functionType<TableProps['expandIcon']>(),
141+
onExpand: functionType<TableProps['onExpand']>(),
142+
onExpandedRowsChange: functionType<TableProps['onExpandedRowsChange']>(),
143+
'onUpdate:expandedRowKeys': functionType<TableProps['onExpandedRowsChange']>(),
144+
defaultExpandAllRows: booleanType(),
145+
indentSize: Number,
168146
/** @deprecated Please use `EXPAND_COLUMN` in `columns` directly */
169-
expandIconColumnIndex: {
170-
type: Number as PropType<TableProps['expandIconColumnIndex']>,
171-
default: undefined,
172-
},
173-
showExpandColumn: { type: Boolean, default: undefined },
174-
expandedRowClassName: {
175-
type: Function as PropType<TableProps['expandedRowClassName']>,
176-
default: undefined,
177-
},
178-
childrenColumnName: {
179-
type: String as PropType<TableProps['childrenColumnName']>,
180-
default: undefined,
181-
},
182-
rowExpandable: { type: Function as PropType<TableProps['rowExpandable']>, default: undefined },
183-
sticky: { type: [Boolean, Object] as PropType<TableProps['sticky']>, default: undefined },
147+
expandIconColumnIndex: Number,
148+
showExpandColumn: booleanType(),
149+
expandedRowClassName: functionType<TableProps['expandedRowClassName']>(),
150+
childrenColumnName: stringType<TableProps['childrenColumnName']>(),
151+
rowExpandable: functionType<TableProps['rowExpandable']>(),
152+
sticky: someType<TableProps['sticky']>([Boolean, Object]),
184153

185154
dropdownPrefixCls: String,
186-
dataSource: { type: Array as PropType<RcTableProps['data']>, default: undefined },
187-
pagination: {
188-
type: [Boolean, Object] as PropType<false | TablePaginationConfig>,
189-
default: undefined,
190-
},
191-
loading: { type: [Boolean, Object] as PropType<boolean | SpinProps>, default: undefined },
192-
size: { type: String as PropType<SizeType>, default: undefined },
193-
bordered: Boolean,
194-
locale: { type: Object as PropType<TableLocale>, default: undefined },
195-
196-
onChange: {
197-
type: Function as PropType<
155+
dataSource: arrayType<RcTableProps['data']>(),
156+
pagination: someType<false | TablePaginationConfig>([Boolean, Object]),
157+
loading: someType<boolean | SpinProps>([Boolean, Object]),
158+
size: stringType<SizeType>(),
159+
bordered: booleanType(),
160+
locale: objectType<TableLocale>(),
161+
162+
onChange:
163+
functionType<
198164
(
199165
pagination: TablePaginationConfig,
200166
filters: Record<string, FilterValue | null>,
201167
sorter: SorterResult | SorterResult[],
202168
extra: TableCurrentDataSource,
203169
) => void
204-
>,
205-
default: undefined,
206-
},
207-
onResizeColumn: {
208-
type: Function as PropType<(w: number, col: ColumnType) => void>,
209-
default: undefined,
210-
},
211-
rowSelection: { type: Object as PropType<TableRowSelection>, default: undefined },
212-
getPopupContainer: { type: Function as PropType<GetPopupContainer>, default: undefined },
213-
scroll: {
214-
type: Object as PropType<
215-
RcTableProps['scroll'] & {
216-
scrollToFirstRowOnChange?: boolean;
217-
}
218-
>,
219-
default: undefined,
220-
},
221-
sortDirections: { type: Array as PropType<SortOrder[]>, default: undefined },
222-
showSorterTooltip: {
223-
type: [Boolean, Object] as PropType<boolean | TooltipProps>,
224-
default: true,
225-
},
226-
contextSlots: {
227-
type: Object as PropType<ContextSlots>,
228-
},
229-
transformCellText: {
230-
type: Function as PropType<TableProps['transformCellText']>,
231-
},
170+
>(),
171+
onResizeColumn: functionType<(w: number, col: ColumnType) => void>(),
172+
rowSelection: objectType<TableRowSelection>(),
173+
getPopupContainer: functionType<GetPopupContainer>(),
174+
scroll: objectType<
175+
RcTableProps['scroll'] & {
176+
scrollToFirstRowOnChange?: boolean;
177+
}
178+
>(),
179+
sortDirections: arrayType<SortOrder[]>(),
180+
showSorterTooltip: someType<boolean | TooltipProps>([Boolean, Object], true),
181+
contextSlots: objectType<ContextSlots>(),
182+
transformCellText: functionType<TableProps['transformCellText']>(),
232183
};
233184
};
234185

@@ -287,6 +238,10 @@ const InteralTable = defineComponent<
287238
prefixCls,
288239
configProvider,
289240
} = useConfigInject('table', props);
241+
242+
// Style
243+
const [wrapSSR, hashId] = useStyle(prefixCls);
244+
290245
const transformCellText = computed(
291246
() => props.transformCellText || configProvider.transformCellText?.value,
292247
);
@@ -637,9 +592,10 @@ const InteralTable = defineComponent<
637592
[`${prefixCls.value}-wrapper-rtl`]: direction.value === 'rtl',
638593
},
639594
attrs.class,
595+
hashId.value,
640596
);
641597
const tableProps = omit(props, ['columns']);
642-
return (
598+
return wrapSSR(
643599
<div class={wrapperClassNames} style={attrs.style as CSSProperties}>
644600
<Spin spinning={false} {...spinProps}>
645601
{topPaginationNode}
@@ -677,7 +633,7 @@ const InteralTable = defineComponent<
677633
/>
678634
{bottomPaginationNode}
679635
</Spin>
680-
</div>
636+
</div>,
681637
);
682638
};
683639
},

components/table/hooks/useFilter/FilterSearch.tsx

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
1-
import type { PropType } from 'vue';
21
import { defineComponent } from 'vue';
32
import SearchOutlined from '@ant-design/icons-vue/SearchOutlined';
43
import type { FilterSearchType, TableLocale } from '../../interface';
54
import Input from '../../../input';
5+
import { stringType, someType, functionType, objectType } from '../../../_util/type';
66

77
export default defineComponent({
88
compatConfig: { MODE: 3 },
99
name: 'FilterSearch',
1010
inheritAttrs: false,
1111
props: {
12-
value: String,
13-
onChange: Function as PropType<(e: InputEvent) => void>,
14-
filterSearch: [Boolean, Function] as PropType<FilterSearchType>,
15-
tablePrefixCls: String,
16-
locale: { type: Object as PropType<TableLocale>, default: undefined as TableLocale },
12+
value: stringType(),
13+
onChange: functionType<(e: InputEvent) => void>(),
14+
filterSearch: someType<FilterSearchType>([Boolean, Function]),
15+
tablePrefixCls: stringType(),
16+
locale: objectType<TableLocale>(),
1717
},
1818
setup(props) {
1919
return () => {

components/table/index.en-US.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ category: Components
33
cols: 1
44
type: Data Display
55
title: Table
6-
cover: https://gw.alipayobjects.com/zos/alicdn/f-SbcX2Lx/Table.svg
6+
cover: https://mdn.alipayobjects.com/huamei_7uahnr/afts/img/A*3yz3QqMlShYAAAAAAAAAAAAADrJ8AQ/original
77
---
88

99
A table displays rows of data.

components/table/index.zh-CN.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ cols: 1
44
type: 数据展示
55
title: Table
66
subtitle: 表格
7-
cover: https://gw.alipayobjects.com/zos/alicdn/f-SbcX2Lx/Table.svg
7+
cover: https://mdn.alipayobjects.com/huamei_7uahnr/afts/img/A*3yz3QqMlShYAAAAAAAAAAAAADrJ8AQ/original
88
---
99

1010
展示行列数据。

0 commit comments

Comments
 (0)