-
-
Notifications
You must be signed in to change notification settings - Fork 3.8k
/
Copy pathindex.tsx
160 lines (149 loc) · 4.81 KB
/
index.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
import type { CSSProperties, ExtractPropTypes } from 'vue';
import { ref, computed, watchEffect, defineComponent } from 'vue';
import PropTypes from '../_util/vue-types';
import warning from '../_util/warning';
import classNames from '../_util/classNames';
import SlickCarousel from '../vc-slick';
import { withInstall, booleanType, functionType, stringType } from '../_util/type';
import useConfigInject from '../config-provider/hooks/useConfigInject';
// CSSINJS
import useStyle from './style';
export type SwipeDirection = 'left' | 'down' | 'right' | 'up' | string;
export type LazyLoadTypes = 'ondemand' | 'progressive';
export type CarouselEffect = 'scrollx' | 'fade';
export type DotPosition = 'top' | 'bottom' | 'left' | 'right';
export interface CarouselRef {
goTo: (slide: number, dontAnimate?: boolean) => void;
next: () => void;
prev: () => void;
autoplay: (palyType?: 'update' | 'leave' | 'blur') => void;
innerSlider: any;
}
// Carousel
export const carouselProps = () => ({
effect: stringType<CarouselEffect>(),
dots: booleanType(true),
vertical: booleanType(),
autoplay: booleanType(),
easing: String,
beforeChange: functionType<(currentSlide: number, nextSlide: number) => void>(),
afterChange: functionType<(currentSlide: number) => void>(),
// style: PropTypes.React.CSSProperties,
prefixCls: String,
accessibility: booleanType(),
nextArrow: PropTypes.any,
prevArrow: PropTypes.any,
pauseOnHover: booleanType(),
// className: String,
adaptiveHeight: booleanType(),
arrows: booleanType(false),
autoplaySpeed: Number,
centerMode: booleanType(),
centerPadding: String,
cssEase: String,
dotsClass: String,
draggable: booleanType(false),
fade: booleanType(),
focusOnSelect: booleanType(),
infinite: booleanType(),
initialSlide: Number,
lazyLoad: stringType<LazyLoadTypes>(),
rtl: booleanType(),
slide: String,
slidesToShow: Number,
slidesToScroll: Number,
speed: Number,
swipe: booleanType(),
swipeToSlide: booleanType(),
swipeEvent: functionType<(swipeDirection: SwipeDirection) => void>(),
touchMove: booleanType(),
touchThreshold: Number,
variableWidth: booleanType(),
useCSS: booleanType(),
slickGoTo: Number,
responsive: Array,
dotPosition: stringType<DotPosition>(),
verticalSwiping: booleanType(false),
});
export type CarouselProps = Partial<ExtractPropTypes<ReturnType<typeof carouselProps>>>;
const Carousel = defineComponent({
name: 'ACarousel',
inheritAttrs: false,
props: carouselProps(),
setup(props, { slots, attrs, expose }) {
const slickRef = ref();
const goTo = (slide: number, dontAnimate = false) => {
slickRef.value?.slickGoTo(slide, dontAnimate);
};
expose({
goTo,
autoplay: palyType => {
slickRef.value?.innerSlider?.handleAutoPlay(palyType);
},
prev: () => {
slickRef.value?.slickPrev();
},
next: () => {
slickRef.value?.slickNext();
},
innerSlider: computed(() => {
return slickRef.value?.innerSlider;
}),
} as CarouselRef);
watchEffect(() => {
warning(
props.vertical === undefined,
'Carousel',
'`vertical` is deprecated, please use `dotPosition` instead.',
);
});
const { prefixCls, direction } = useConfigInject('carousel', props);
// style
const [wrapSSR, hashId] = useStyle(prefixCls);
const dotPosition = computed(() => {
if (props.dotPosition) return props.dotPosition;
if (props.vertical !== undefined) return props.vertical ? 'right' : 'bottom';
return 'bottom';
});
const vertical = computed(() => dotPosition.value === 'left' || dotPosition.value === 'right');
const dsClass = computed(() => {
const dotsClass = 'slick-dots';
return classNames({
[dotsClass]: true,
[`${dotsClass}-${dotPosition.value}`]: true,
[`${props.dotsClass}`]: !!props.dotsClass,
});
});
return () => {
const { dots, arrows, draggable, effect } = props;
const { class: cls, style, ...restAttrs } = attrs;
const fade = effect === 'fade' ? true : props.fade;
const className = classNames(
prefixCls.value,
{
[`${prefixCls.value}-rtl`]: direction.value === 'rtl',
[`${prefixCls.value}-vertical`]: vertical.value,
[`${cls}`]: !!cls,
},
hashId.value,
);
return wrapSSR(
<div class={className} style={style as CSSProperties}>
<SlickCarousel
ref={slickRef}
{...props}
{...restAttrs}
dots={!!dots}
dotsClass={dsClass.value}
arrows={arrows}
draggable={draggable}
fade={fade}
vertical={vertical.value}
v-slots={slots}
/>
</div>,
);
};
},
});
export default withInstall(Carousel);