File tree 4 files changed +67
-14
lines changed
ui/src/components/carousel
4 files changed +67
-14
lines changed Original file line number Diff line number Diff line change
1
+ ---
2
+ ' @casual-ui/svelte ' : patch
3
+ ---
4
+
5
+ fix(carousel): first auto play should be triggered in mount instead of in intro end event
Original file line number Diff line number Diff line change
1
+ <script lang =" ts" >
2
+ import { CCarousel , CCarouselSlider } from ' @casual-ui/svelte'
3
+
4
+ let activeIndex = 0
5
+ </script >
6
+
7
+ <CCarousel bind:activeIndex interval ={5000 } infinity arrowTiming =" hover" >
8
+ <CCarouselSlider >
9
+ <div class =" item" >
10
+ <div class =" icon i-openmoji-red-apple" />
11
+ Do you want some apples?
12
+ </div >
13
+ </CCarouselSlider >
14
+ <CCarouselSlider >
15
+ <div class =" item" >
16
+ <div class =" icon i-openmoji-banana" />
17
+ Would you like some bananas?
18
+ </div >
19
+ </CCarouselSlider >
20
+ <CCarouselSlider >
21
+ <div class =" item" >
22
+ <div class =" icon i-openmoji-grapes" />
23
+ How about some grapes?
24
+ </div >
25
+ </CCarouselSlider >
26
+ </CCarousel >
27
+
28
+ <style >
29
+ .item {
30
+ font-size : 32px ;
31
+ height : 100% ;
32
+ display : flex ;
33
+ align-items : center ;
34
+ justify-content : center ;
35
+ flex-direction : column ;
36
+ }
37
+ .item .icon {
38
+ font-size : 100px ;
39
+ }
40
+ </style >
Original file line number Diff line number Diff line change 48
48
export const hoveringKey = Symbol (' c-carousel-hovering' )
49
49
50
50
/**
51
- * The slidering flag key.
51
+ * The sliding flag key.
52
52
* @type {symbol}
53
53
*/
54
- export const slideringKey = Symbol (' c-carousel-slidering' )
54
+ export const slidingKey = Symbol (' c-carousel-slidering' )
55
55
56
56
/**
57
57
* The pause functions key.
67
67
</script >
68
68
69
69
<script >
70
- import { setContext } from ' svelte'
70
+ import { onMount , setContext } from ' svelte'
71
71
import { cubicInOut } from ' svelte/easing'
72
72
import { writable } from ' svelte/store'
73
73
import { fade } from ' svelte/transition'
220
220
const sliding = writable (false )
221
221
222
222
setContext (hoveringKey, hovering)
223
- setContext (slideringKey , sliding)
223
+ setContext (slidingKey , sliding)
224
224
225
225
$: paused = ($hovering && pauseOnHover) || $sliding
226
226
253
253
$verticalContext = vertical
254
254
}
255
255
256
+ let initialized = false
257
+
258
+ onMount (() => {
259
+ if (! initialized && interval) {
260
+ initialized = true
261
+ timeoutFlag .set (setTimeout (toNext, interval))
262
+ }
263
+ })
264
+
256
265
export { toPrev , toNext , toIndex }
257
266
</script >
258
267
Original file line number Diff line number Diff line change 8
8
intervalKey ,
9
9
pausesKey ,
10
10
resumesKey ,
11
- slideringKey ,
12
11
slidesKey ,
12
+ slidingKey ,
13
13
timeoutKey ,
14
14
toNextKey ,
15
15
verticalKey ,
23
23
const toNext = getContext (toNextKey)
24
24
const timeoutFlag = getContext (timeoutKey)
25
25
const hovering = getContext (hoveringKey)
26
- const slidering = getContext (slideringKey )
26
+ const sliding = getContext (slidingKey )
27
27
28
28
const currentIndex = $slides .length
29
29
34
34
* @param {*} node
35
35
* @param {*} params
36
36
*/
37
- const carousel = (node , params ) => {
37
+ const carousel = (_node , params ) => {
38
38
const { leave } = params
39
39
return {
40
40
duration: 300 ,
62
62
let remain = $interval
63
63
64
64
const onIntroStart = () => {
65
- $slidering = true
66
- remain = $interval
65
+ $sliding = true
67
66
}
68
67
69
- const onIntroEnd = () => {
70
- $slidering = false
68
+ const onIntroEnd = async () => {
69
+ $sliding = false
71
70
remain = $interval
72
71
if ($interval && toNext && ! $hovering) {
73
72
start = Date .now ()
74
73
if ($timeoutFlag) clearTimeout ($timeoutFlag)
75
74
76
- $timeoutFlag = setTimeout (toNext, remain )
75
+ $timeoutFlag = setTimeout (toNext, $interval )
77
76
}
78
77
}
79
78
95
94
}
96
95
}
97
96
98
- if (pauses && Array .isArray (pauses)) pauses .push (pause)
97
+ if (Array .isArray (pauses)) pauses .push (pause)
99
98
100
99
const resume = () => {
101
100
if ($activeIndex !== currentIndex) return
105
104
$timeoutFlag = setTimeout (toNext, remain)
106
105
}
107
106
108
- if (resumes && Array .isArray (resumes)) resumes .push (resume)
107
+ if (Array .isArray (resumes)) resumes .push (resume)
109
108
110
109
onDestroy (() => {
111
110
if ($timeoutFlag) clearTimeout ($timeoutFlag)
You can’t perform that action at this time.
0 commit comments