Skip to content

Commit bbfb3ce

Browse files
refactor:carousel (#6262)
* refactor:carousel * docs:update & refactor: carousel type --------- Co-authored-by: tangjinzhou <[email protected]>
1 parent e9ce4eb commit bbfb3ce

14 files changed

+422
-410
lines changed

components/carousel/demo/autoplay.vue

+2-3
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,14 @@ Timing of scrolling to the next card/picture.
2626
</template>
2727
<style scoped>
2828
/* For demo */
29-
.ant-carousel :deep(.slick-slide) {
29+
:deep(.slick-slide) {
3030
text-align: center;
3131
height: 160px;
3232
line-height: 160px;
3333
background: #364d79;
3434
overflow: hidden;
3535
}
36-
37-
.ant-carousel :deep(.slick-slide h3) {
36+
:deep(.slick-slide h3) {
3837
color: #fff;
3938
}
4039
</style>

components/carousel/demo/basic.vue

+2-2
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,15 @@ export default defineComponent({
4141
</script>
4242
<style scoped>
4343
/* For demo */
44-
.ant-carousel :deep(.slick-slide) {
44+
:deep(.slick-slide) {
4545
text-align: center;
4646
height: 160px;
4747
line-height: 160px;
4848
background: #364d79;
4949
overflow: hidden;
5050
}
5151
52-
.ant-carousel :deep(.slick-slide h3) {
52+
:deep(.slick-slide h3) {
5353
color: #fff;
5454
}
5555
</style>

components/carousel/demo/customArrows.vue

+7-5
Original file line numberDiff line numberDiff line change
@@ -46,31 +46,33 @@ export default defineComponent({
4646
</script>
4747
<style scoped>
4848
/* For demo */
49-
.ant-carousel :deep(.slick-slide) {
49+
:deep(.slick-slide) {
5050
text-align: center;
5151
height: 160px;
5252
line-height: 160px;
5353
background: #364d79;
5454
overflow: hidden;
5555
}
5656
57-
.ant-carousel :deep(.slick-arrow.custom-slick-arrow) {
57+
:deep(.slick-arrow.custom-slick-arrow) {
5858
width: 25px;
5959
height: 25px;
6060
font-size: 25px;
6161
color: #fff;
6262
background-color: rgba(31, 45, 61, 0.11);
63+
transition: ease all 0.3s;
6364
opacity: 0.3;
6465
z-index: 1;
6566
}
66-
.ant-carousel :deep(.custom-slick-arrow:before) {
67+
:deep(.slick-arrow.custom-slick-arrow:before) {
6768
display: none;
6869
}
69-
.ant-carousel :deep(.custom-slick-arrow:hover) {
70+
:deep(.slick-arrow.custom-slick-arrow:hover) {
71+
color: #fff;
7072
opacity: 0.5;
7173
}
7274
73-
.ant-carousel :deep(.slick-slide h3) {
75+
:deep(.slick-slide h3) {
7476
color: #fff;
7577
}
7678
</style>

components/carousel/demo/customPaging.vue

+7-7
Original file line numberDiff line numberDiff line change
@@ -46,33 +46,33 @@ export default defineComponent({
4646
</script>
4747
<style scoped>
4848
/* For demo */
49-
.ant-carousel :deep(.slick-dots) {
49+
:deep(.slick-dots) {
5050
position: relative;
5151
height: auto;
5252
}
53-
.ant-carousel :deep(.slick-slide img) {
53+
:deep(.slick-slide img) {
5454
border: 5px solid #fff;
5555
display: block;
5656
margin: auto;
5757
max-width: 80%;
5858
}
59-
.ant-carousel :deep(.slick-arrow) {
59+
:deep(.slick-arrow) {
6060
display: none !important;
6161
}
62-
.ant-carousel :deep(.slick-thumb) {
62+
:deep(.slick-thumb) {
6363
bottom: 0px;
6464
}
65-
.ant-carousel :deep(.slick-thumb li) {
65+
:deep(.slick-thumb li) {
6666
width: 60px;
6767
height: 45px;
6868
}
69-
.ant-carousel :deep(.slick-thumb li img) {
69+
:deep(.slick-thumb li img) {
7070
width: 100%;
7171
height: 100%;
7272
filter: grayscale(100%);
7373
display: block;
7474
}
75-
.ant-carousel :deep .slick-thumb li.slick-active img {
75+
:deep .slick-thumb li.slick-active img {
7676
filter: grayscale(0%);
7777
}
7878
</style>

components/carousel/demo/fade.vue

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,15 @@ Slides use fade for transition.
2626
</template>
2727
<style scoped>
2828
/* For demo */
29-
.ant-carousel :deep(.slick-slide) {
29+
:deep(.slick-slide) {
3030
text-align: center;
3131
height: 160px;
3232
line-height: 160px;
3333
background: #364d79;
3434
overflow: hidden;
3535
}
3636
37-
.ant-carousel :deep(.slick-slide h3) {
37+
:deep(.slick-slide h3) {
3838
color: #fff;
3939
}
4040
</style>

components/carousel/demo/position.vue

+2-2
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,15 @@ export default defineComponent({
4343
</script>
4444
<style scoped>
4545
/* For demo */
46-
.ant-carousel :deep(.slick-slide) {
46+
:deep(.slick-slide) {
4747
text-align: center;
4848
height: 160px;
4949
line-height: 160px;
5050
background: #364d79;
5151
overflow: hidden;
5252
}
5353
54-
.ant-carousel :deep(.slick-slide h3) {
54+
:deep(.slick-slide h3) {
5555
color: #fff;
5656
}
5757
</style>

components/carousel/index.en-US.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
category: Components
33
type: Data Display
44
title: Carousel
5-
cover: https://gw.alipayobjects.com/zos/antfincdn/%24C9tmj978R/Carousel.svg
5+
cover: https://mdn.alipayobjects.com/huamei_7uahnr/afts/img/A*bPMSSqbaTMkAAAAAAAAAAAAADrJ8AQ/original
66
---
77

88
A carousel component. Scales with its container.

components/carousel/index.tsx

+45-34
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
1-
import type { CSSProperties, ExtractPropTypes, PropType } from 'vue';
1+
import type { CSSProperties, ExtractPropTypes } from 'vue';
22
import { ref, computed, watchEffect, defineComponent } from 'vue';
33
import PropTypes from '../_util/vue-types';
44
import warning from '../_util/warning';
55
import classNames from '../_util/classNames';
66
import SlickCarousel from '../vc-slick';
7-
import { withInstall } from '../_util/type';
7+
import { withInstall, booleanType, functionType, stringType } from '../_util/type';
88
import useConfigInject from '../config-provider/hooks/useConfigInject';
99

10+
// CSSINJS
11+
import useStyle from './style';
12+
1013
export type SwipeDirection = 'left' | 'down' | 'right' | 'up' | string;
1114

1215
export type LazyLoadTypes = 'ondemand' | 'progressive';
@@ -24,49 +27,49 @@ export interface CarouselRef {
2427

2528
// Carousel
2629
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(),
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
});
7174
export type CarouselProps = Partial<ExtractPropTypes<ReturnType<typeof carouselProps>>>;
7275
const 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
},

components/carousel/index.zh-CN.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ category: Components
33
type: 数据展示
44
title: Carousel
55
subtitle: 走马灯
6-
cover: https://gw.alipayobjects.com/zos/antfincdn/%24C9tmj978R/Carousel.svg
6+
cover: https://mdn.alipayobjects.com/huamei_7uahnr/afts/img/A*bPMSSqbaTMkAAAAAAAAAAAAADrJ8AQ/original
77
---
88

99
旋转木马,一组轮播的区域。

0 commit comments

Comments
 (0)