@@ -34,7 +34,7 @@ import scrollTo from '../_util/scrollTo';
34
34
import defaultLocale from '../locale/en_US' ;
35
35
import type { SizeType } from '../config-provider' ;
36
36
import devWarning from '../vc-util/devWarning' ;
37
- import type { CSSProperties , PropType } from 'vue' ;
37
+ import type { CSSProperties } from 'vue' ;
38
38
import { nextTick , reactive , ref , computed , defineComponent , toRef , watchEffect , watch } from 'vue' ;
39
39
import type { DefaultRecordType } from '../vc-table/interface' ;
40
40
import useBreakpoint from '../_util/hooks/useBreakpoint' ;
@@ -47,6 +47,17 @@ import { useProvideSlots, useProvideTableContext } from './context';
47
47
import type { ContextSlots } from './context' ;
48
48
import useColumns from './hooks/useColumns' ;
49
49
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' ;
50
61
51
62
export type { ColumnsType , TablePaginationConfig } ;
52
63
@@ -107,128 +118,68 @@ export interface TableProps<RecordType = DefaultRecordType>
107
118
108
119
export const tableProps = ( ) => {
109
120
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 ,
168
146
/** @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 ] ) ,
184
153
185
154
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 <
198
164
(
199
165
pagination : TablePaginationConfig ,
200
166
filters : Record < string , FilterValue | null > ,
201
167
sorter : SorterResult | SorterResult [ ] ,
202
168
extra : TableCurrentDataSource ,
203
169
) => 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' ] > ( ) ,
232
183
} ;
233
184
} ;
234
185
@@ -287,6 +238,10 @@ const InteralTable = defineComponent<
287
238
prefixCls,
288
239
configProvider,
289
240
} = useConfigInject ( 'table' , props ) ;
241
+
242
+ // Style
243
+ const [ wrapSSR , hashId ] = useStyle ( prefixCls ) ;
244
+
290
245
const transformCellText = computed (
291
246
( ) => props . transformCellText || configProvider . transformCellText ?. value ,
292
247
) ;
@@ -637,9 +592,10 @@ const InteralTable = defineComponent<
637
592
[ `${ prefixCls . value } -wrapper-rtl` ] : direction . value === 'rtl' ,
638
593
} ,
639
594
attrs . class ,
595
+ hashId . value ,
640
596
) ;
641
597
const tableProps = omit ( props , [ 'columns' ] ) ;
642
- return (
598
+ return wrapSSR (
643
599
< div class = { wrapperClassNames } style = { attrs . style as CSSProperties } >
644
600
< Spin spinning = { false } { ...spinProps } >
645
601
{ topPaginationNode }
@@ -677,7 +633,7 @@ const InteralTable = defineComponent<
677
633
/>
678
634
{ bottomPaginationNode }
679
635
</ Spin >
680
- </ div >
636
+ </ div > ,
681
637
) ;
682
638
} ;
683
639
} ,
0 commit comments