1
- import type { CSSProperties , ExtractPropTypes , PropType } from 'vue' ;
1
+ import type { CSSProperties , ExtractPropTypes } from 'vue' ;
2
2
import { computed , watchEffect , defineComponent , ref , watch , toRaw } from 'vue' ;
3
3
import PropTypes from '../_util/vue-types' ;
4
4
import { getPropsSlot } from '../_util/props-util' ;
@@ -8,7 +8,15 @@ import Operation from './operation';
8
8
import LocaleReceiver from '../locale-provider/LocaleReceiver' ;
9
9
import defaultLocale from '../locale/en_US' ;
10
10
import type { VueNode } from '../_util/type' ;
11
- import { withInstall } from '../_util/type' ;
11
+ import {
12
+ withInstall ,
13
+ stringType ,
14
+ arrayType ,
15
+ someType ,
16
+ booleanType ,
17
+ objectType ,
18
+ functionType ,
19
+ } from '../_util/type' ;
12
20
import useConfigInject from '../config-provider/hooks/useConfigInject' ;
13
21
import type { TransferListBodyProps } from './ListBody' ;
14
22
import type { PaginationType } from './interface' ;
@@ -17,6 +25,9 @@ import type { RenderEmptyHandler } from '../config-provider/renderEmpty';
17
25
import type { InputStatus } from '../_util/statusUtils' ;
18
26
import { getStatusClassNames , getMergedStatus } from '../_util/statusUtils' ;
19
27
28
+ // CSSINJS
29
+ import useStyle from './style' ;
30
+
20
31
export type { TransferListProps } from './list' ;
21
32
export type { TransferOperationProps } from './operation' ;
22
33
export type { TransferSearchProps } from './search' ;
@@ -69,40 +80,41 @@ export interface TransferLocale {
69
80
export const transferProps = ( ) => ( {
70
81
id : String ,
71
82
prefixCls : String ,
72
- dataSource : { type : Array as PropType < TransferItem [ ] > , default : [ ] } ,
73
- disabled : { type : Boolean , default : undefined } ,
74
- targetKeys : { type : Array as PropType < string [ ] > , default : undefined } ,
75
- selectedKeys : { type : Array as PropType < string [ ] > , default : undefined } ,
76
- render : { type : Function as PropType < TransferRender < TransferItem > > } ,
77
- listStyle : {
78
- type : [ Function , Object ] as PropType < ( ( style : ListStyle ) => CSSProperties ) | CSSProperties > ,
79
- default : ( ) => ( { } ) ,
80
- } ,
81
- operationStyle : { type : Object as PropType < CSSProperties > , default : undefined as CSSProperties } ,
82
- titles : { type : Array as PropType < string [ ] > } ,
83
- operations : { type : Array as PropType < string [ ] > } ,
84
- showSearch : { type : Boolean , default : false } ,
85
- filterOption : { type : Function as PropType < ( inputValue : string , item : TransferItem ) => boolean > } ,
83
+ dataSource : arrayType < TransferItem [ ] > ( [ ] ) ,
84
+ disabled : booleanType ( ) ,
85
+ targetKeys : arrayType < string [ ] > ( ) ,
86
+ selectedKeys : arrayType < string [ ] > ( ) ,
87
+ render : functionType < TransferRender < TransferItem > > ( ) ,
88
+ listStyle : someType < ( ( style : ListStyle ) => CSSProperties ) | CSSProperties > (
89
+ [ Function , Object ] ,
90
+ ( ) => ( { } ) ,
91
+ ) ,
92
+ operationStyle : objectType < CSSProperties > ( undefined as CSSProperties ) ,
93
+ titles : arrayType < string [ ] > ( ) ,
94
+ operations : arrayType < string [ ] > ( ) ,
95
+ showSearch : booleanType ( false ) ,
96
+ filterOption : functionType < ( inputValue : string , item : TransferItem ) => boolean > ( ) ,
86
97
searchPlaceholder : String ,
87
98
notFoundContent : PropTypes . any ,
88
- locale : { type : Object as PropType < Partial < TransferLocale > > , default : ( ) => ( { } ) } ,
89
- rowKey : { type : Function as PropType < ( record : TransferItem ) => string > } ,
90
- showSelectAll : { type : Boolean , default : undefined } ,
91
- selectAllLabels : { type : Array as PropType < SelectAllLabel [ ] > } ,
92
- children : { type : Function as PropType < ( props : TransferListBodyProps ) => VueNode > } ,
93
- oneWay : { type : Boolean , default : undefined } ,
94
- pagination : { type : [ Object , Boolean ] as PropType < PaginationType > , default : undefined } ,
95
- status : String as PropType < InputStatus > ,
96
- onChange : Function as PropType <
97
- ( targetKeys : string [ ] , direction : TransferDirection , moveKeys : string [ ] ) => void
98
- > ,
99
- onSelectChange : Function as PropType <
99
+ locale : objectType ( ) ,
100
+ rowKey : functionType < ( record : TransferItem ) => string > ( ) ,
101
+ showSelectAll : booleanType ( ) ,
102
+ selectAllLabels : arrayType < SelectAllLabel [ ] > ( ) ,
103
+ children : functionType < ( props : TransferListBodyProps ) => VueNode > ( ) ,
104
+ oneWay : booleanType ( ) ,
105
+ pagination : someType < PaginationType > ( [ Object , Boolean ] ) ,
106
+ status : stringType < InputStatus > ( ) ,
107
+ onChange :
108
+ functionType <
109
+ ( targetKeys : string [ ] , direction : TransferDirection , moveKeys : string [ ] ) => void
110
+ > ( ) ,
111
+ onSelectChange : functionType <
100
112
( sourceSelectedKeys : string [ ] , targetSelectedKeys : string [ ] ) => void
101
113
> ,
102
- onSearch : Function as PropType < ( direction : TransferDirection , value : string ) => void > ,
103
- onScroll : Function as PropType < ( direction : TransferDirection , e : UIEvent ) => void > ,
104
- 'onUpdate:targetKeys' : Function as PropType < ( keys : string [ ] ) => void > ,
105
- 'onUpdate:selectedKeys' : Function as PropType < ( keys : string [ ] ) => void > ,
114
+ onSearch : functionType < ( direction : TransferDirection , value : string ) => void > ( ) ,
115
+ onScroll : functionType < ( direction : TransferDirection , e : UIEvent ) => void > ( ) ,
116
+ 'onUpdate:targetKeys' : functionType < ( keys : string [ ] ) => void > ( ) ,
117
+ 'onUpdate:selectedKeys' : functionType < ( keys : string [ ] ) => void > ( ) ,
106
118
} ) ;
107
119
108
120
export type TransferProps = Partial < ExtractPropTypes < ReturnType < typeof transferProps > > > ;
@@ -125,6 +137,10 @@ const Transfer = defineComponent({
125
137
// emits: ['update:targetKeys', 'update:selectedKeys', 'change', 'search', 'scroll', 'selectChange'],
126
138
setup ( props , { emit, attrs, slots, expose } ) {
127
139
const { configProvider, prefixCls, direction } = useConfigInject ( 'transfer' , props ) ;
140
+
141
+ // style
142
+ const [ wrapSSR , hashId ] = useStyle ( prefixCls ) ;
143
+
128
144
const sourceSelectedKeys = ref ( [ ] ) ;
129
145
const targetSelectedKeys = ref ( [ ] ) ;
130
146
@@ -349,14 +365,15 @@ const Transfer = defineComponent({
349
365
[ `${ prefixCls . value } -rtl` ] : direction . value === 'rtl' ,
350
366
} ,
351
367
getStatusClassNames ( prefixCls . value , mergedStatus . value , formItemInputContext . hasFeedback ) ,
368
+ hashId . value ,
352
369
) ;
353
370
const titles = props . titles ;
354
371
const leftTitle =
355
372
( titles && titles [ 0 ] ) ?? slots . leftTitle ?.( ) ?? ( locale . titles || [ '' , '' ] ) [ 0 ] ;
356
373
const rightTitle =
357
374
( titles && titles [ 1 ] ) ?? slots . rightTitle ?.( ) ?? ( locale . titles || [ '' , '' ] ) [ 1 ] ;
358
375
return (
359
- < div class = { cls } style = { style as CSSProperties } id = { id } >
376
+ < div { ... attrs } class = { cls } style = { style as CSSProperties } id = { id } >
360
377
< List
361
378
key = "leftList"
362
379
prefixCls = { `${ prefixCls . value } -list` }
@@ -422,13 +439,14 @@ const Transfer = defineComponent({
422
439
</ div >
423
440
) ;
424
441
} ;
425
- return ( ) => (
426
- < LocaleReceiver
427
- componentName = "Transfer"
428
- defaultLocale = { defaultLocale . Transfer }
429
- children = { renderTransfer }
430
- />
431
- ) ;
442
+ return ( ) =>
443
+ wrapSSR (
444
+ < LocaleReceiver
445
+ componentName = "Transfer"
446
+ defaultLocale = { defaultLocale . Transfer }
447
+ children = { renderTransfer }
448
+ /> ,
449
+ ) ;
432
450
} ,
433
451
} ) ;
434
452
0 commit comments