1- import type { CSSProperties , ExtractPropTypes , PropType } from 'vue' ;
1+ import type { CSSProperties , ExtractPropTypes } from 'vue' ;
22import { ref , computed , watchEffect , defineComponent } from 'vue' ;
33import PropTypes from '../_util/vue-types' ;
44import warning from '../_util/warning' ;
55import classNames from '../_util/classNames' ;
66import SlickCarousel from '../vc-slick' ;
7- import { withInstall } from '../_util/type' ;
7+ import { withInstall , booleanType , functionType , stringType } from '../_util/type' ;
88import useConfigInject from '../config-provider/hooks/useConfigInject' ;
99
10+ // CSSINJS
11+ import useStyle from './style' ;
12+
1013export type SwipeDirection = 'left' | 'down' | 'right' | 'up' | string ;
1114
1215export type LazyLoadTypes = 'ondemand' | 'progressive' ;
@@ -24,49 +27,49 @@ export interface CarouselRef {
2427
2528// Carousel
2629export 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 ( ) ,
3134 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 > ( ) ,
3437 // style: PropTypes.React.CSSProperties,
3538 prefixCls : String ,
36- accessibility : { type : Boolean , default : undefined } ,
39+ accessibility : booleanType ( ) ,
3740 nextArrow : PropTypes . any ,
3841 prevArrow : PropTypes . any ,
39- pauseOnHover : { type : Boolean , default : undefined } ,
42+ pauseOnHover : booleanType ( ) ,
4043 // className: String,
41- adaptiveHeight : { type : Boolean , default : undefined } ,
42- arrows : { type : Boolean , default : false } ,
44+ adaptiveHeight : booleanType ( ) ,
45+ arrows : booleanType ( false ) ,
4346 autoplaySpeed : Number ,
44- centerMode : { type : Boolean , default : undefined } ,
47+ centerMode : booleanType ( ) ,
4548 centerPadding : String ,
4649 cssEase : String ,
4750 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 ( ) ,
5255 initialSlide : Number ,
53- lazyLoad : String as PropType < LazyLoadTypes > ,
54- rtl : { type : Boolean , default : undefined } ,
56+ lazyLoad : stringType < LazyLoadTypes > ( ) ,
57+ rtl : booleanType ( ) ,
5558 slide : String ,
5659 slidesToShow : Number ,
5760 slidesToScroll : Number ,
5861 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 ( ) ,
6366 touchThreshold : Number ,
64- variableWidth : { type : Boolean , default : undefined } ,
65- useCSS : { type : Boolean , default : undefined } ,
67+ variableWidth : booleanType ( ) ,
68+ useCSS : booleanType ( ) ,
6669 slickGoTo : Number ,
6770 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 ) ,
7073} ) ;
7174export type CarouselProps = Partial < ExtractPropTypes < ReturnType < typeof carouselProps > > > ;
7275const Carousel = defineComponent ( {
@@ -104,6 +107,10 @@ const Carousel = defineComponent({
104107 ) ;
105108 } ) ;
106109 const { prefixCls, direction } = useConfigInject ( 'carousel' , props ) ;
110+
111+ // style
112+ const [ wrapSSR , hashId ] = useStyle ( prefixCls ) ;
113+
107114 const dotPosition = computed ( ( ) => {
108115 if ( props . dotPosition ) return props . dotPosition ;
109116 if ( props . vertical !== undefined ) return props . vertical ? 'right' : 'bottom' ;
@@ -122,12 +129,16 @@ const Carousel = defineComponent({
122129 const { dots, arrows, draggable, effect } = props ;
123130 const { class : cls , style, ...restAttrs } = attrs ;
124131 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 (
131142 < div class = { className } style = { style as CSSProperties } >
132143 < SlickCarousel
133144 ref = { slickRef }
@@ -141,7 +152,7 @@ const Carousel = defineComponent({
141152 vertical = { vertical . value }
142153 v-slots = { slots }
143154 />
144- </ div >
155+ </ div > ,
145156 ) ;
146157 } ;
147158 } ,
0 commit comments