1
- import type { CSSProperties , ExtractPropTypes , PropType } from 'vue' ;
1
+ import type { CSSProperties , ExtractPropTypes } from 'vue' ;
2
2
import { ref , computed , watchEffect , defineComponent } from 'vue' ;
3
3
import PropTypes from '../_util/vue-types' ;
4
4
import warning from '../_util/warning' ;
5
5
import classNames from '../_util/classNames' ;
6
6
import SlickCarousel from '../vc-slick' ;
7
- import { withInstall } from '../_util/type' ;
7
+ import { withInstall , booleanType , functionType , stringType } from '../_util/type' ;
8
8
import useConfigInject from '../config-provider/hooks/useConfigInject' ;
9
9
10
+ // CSSINJS
11
+ import useStyle from './style' ;
12
+
10
13
export type SwipeDirection = 'left' | 'down' | 'right' | 'up' | string ;
11
14
12
15
export type LazyLoadTypes = 'ondemand' | 'progressive' ;
@@ -24,49 +27,49 @@ export interface CarouselRef {
24
27
25
28
// Carousel
26
29
export const carouselProps = ( ) => ( {
27
- effect : String as PropType < CarouselEffect > ,
28
- dots : { type : Boolean , default : true } ,
29
- vertical : { type : Boolean , default : undefined } ,
30
- autoplay : { type : Boolean , default : undefined } ,
30
+ effect : stringType < CarouselEffect > ( ) ,
31
+ dots : booleanType ( true ) ,
32
+ vertical : booleanType ( ) ,
33
+ autoplay : booleanType ( ) ,
31
34
easing : String ,
32
- beforeChange : Function as PropType < ( currentSlide : number , nextSlide : number ) => void > ,
33
- afterChange : Function as PropType < ( currentSlide : number ) => void > ,
35
+ beforeChange : functionType < ( currentSlide : number , nextSlide : number ) => void > ( ) ,
36
+ afterChange : functionType < ( currentSlide : number ) => void > ( ) ,
34
37
// style: PropTypes.React.CSSProperties,
35
38
prefixCls : String ,
36
- accessibility : { type : Boolean , default : undefined } ,
39
+ accessibility : booleanType ( ) ,
37
40
nextArrow : PropTypes . any ,
38
41
prevArrow : PropTypes . any ,
39
- pauseOnHover : { type : Boolean , default : undefined } ,
42
+ pauseOnHover : booleanType ( ) ,
40
43
// className: String,
41
- adaptiveHeight : { type : Boolean , default : undefined } ,
42
- arrows : { type : Boolean , default : false } ,
44
+ adaptiveHeight : booleanType ( ) ,
45
+ arrows : booleanType ( false ) ,
43
46
autoplaySpeed : Number ,
44
- centerMode : { type : Boolean , default : undefined } ,
47
+ centerMode : booleanType ( ) ,
45
48
centerPadding : String ,
46
49
cssEase : String ,
47
50
dotsClass : String ,
48
- draggable : { type : Boolean , default : false } ,
49
- fade : { type : Boolean , default : undefined } ,
50
- focusOnSelect : { type : Boolean , default : undefined } ,
51
- infinite : { type : Boolean , default : undefined } ,
51
+ draggable : booleanType ( false ) ,
52
+ fade : booleanType ( ) ,
53
+ focusOnSelect : booleanType ( ) ,
54
+ infinite : booleanType ( ) ,
52
55
initialSlide : Number ,
53
- lazyLoad : String as PropType < LazyLoadTypes > ,
54
- rtl : { type : Boolean , default : undefined } ,
56
+ lazyLoad : stringType < LazyLoadTypes > ( ) ,
57
+ rtl : booleanType ( ) ,
55
58
slide : String ,
56
59
slidesToShow : Number ,
57
60
slidesToScroll : Number ,
58
61
speed : Number ,
59
- swipe : { type : Boolean , default : undefined } ,
60
- swipeToSlide : { type : Boolean , default : undefined } ,
61
- swipeEvent : Function as PropType < ( swipeDirection : SwipeDirection ) => void > ,
62
- touchMove : { type : Boolean , default : undefined } ,
62
+ swipe : booleanType ( ) ,
63
+ swipeToSlide : booleanType ( ) ,
64
+ swipeEvent : functionType < ( swipeDirection : SwipeDirection ) => void > ( ) ,
65
+ touchMove : booleanType ( ) ,
63
66
touchThreshold : Number ,
64
- variableWidth : { type : Boolean , default : undefined } ,
65
- useCSS : { type : Boolean , default : undefined } ,
67
+ variableWidth : booleanType ( ) ,
68
+ useCSS : booleanType ( ) ,
66
69
slickGoTo : Number ,
67
70
responsive : Array ,
68
- dotPosition : { type : String as PropType < DotPosition > , default : undefined } ,
69
- verticalSwiping : { type : Boolean , default : false } ,
71
+ dotPosition : stringType < DotPosition > ( ) ,
72
+ verticalSwiping : booleanType ( false ) ,
70
73
} ) ;
71
74
export type CarouselProps = Partial < ExtractPropTypes < ReturnType < typeof carouselProps > > > ;
72
75
const Carousel = defineComponent ( {
@@ -104,6 +107,10 @@ const Carousel = defineComponent({
104
107
) ;
105
108
} ) ;
106
109
const { prefixCls, direction } = useConfigInject ( 'carousel' , props ) ;
110
+
111
+ // style
112
+ const [ wrapSSR , hashId ] = useStyle ( prefixCls ) ;
113
+
107
114
const dotPosition = computed ( ( ) => {
108
115
if ( props . dotPosition ) return props . dotPosition ;
109
116
if ( props . vertical !== undefined ) return props . vertical ? 'right' : 'bottom' ;
@@ -122,12 +129,16 @@ const Carousel = defineComponent({
122
129
const { dots, arrows, draggable, effect } = props ;
123
130
const { class : cls , style, ...restAttrs } = attrs ;
124
131
const fade = effect === 'fade' ? true : props . fade ;
125
- const className = classNames ( prefixCls . value , {
126
- [ `${ prefixCls . value } -rtl` ] : direction . value === 'rtl' ,
127
- [ `${ prefixCls . value } -vertical` ] : vertical . value ,
128
- [ `${ cls } ` ] : ! ! cls ,
129
- } ) ;
130
- return (
132
+ const className = classNames (
133
+ prefixCls . value ,
134
+ {
135
+ [ `${ prefixCls . value } -rtl` ] : direction . value === 'rtl' ,
136
+ [ `${ prefixCls . value } -vertical` ] : vertical . value ,
137
+ [ `${ cls } ` ] : ! ! cls ,
138
+ } ,
139
+ hashId . value ,
140
+ ) ;
141
+ return wrapSSR (
131
142
< div class = { className } style = { style as CSSProperties } >
132
143
< SlickCarousel
133
144
ref = { slickRef }
@@ -141,7 +152,7 @@ const Carousel = defineComponent({
141
152
vertical = { vertical . value }
142
153
v-slots = { slots }
143
154
/>
144
- </ div >
155
+ </ div > ,
145
156
) ;
146
157
} ;
147
158
} ,
0 commit comments