@@ -24,9 +24,9 @@ const isVisible = (element: HTMLDivElement) => {
24
24
25
25
export interface CCarouselProps extends HTMLAttributes < HTMLDivElement > {
26
26
/**
27
- * Set 'animate' variable for created context .
27
+ * index of the active item .
28
28
*/
29
- animate ?: boolean
29
+ activeIndex ?: number
30
30
/**
31
31
* A string of all className you want applied to the base component.
32
32
*/
@@ -43,18 +43,18 @@ export interface CCarouselProps extends HTMLAttributes<HTMLDivElement> {
43
43
* The amount of time to delay between automatically cycling an item. If false, carousel will not automatically cycle.
44
44
*/
45
45
interval ?: boolean | number
46
- /**
47
- * index of the active item.
48
- */
49
- index ?: number
50
46
/**
51
47
* Adding indicators at the bottom of the carousel for each item.
52
48
*/
53
49
indicators ?: boolean
54
50
/**
55
- * On slide change callback .
51
+ * Callback fired when a slide transition end .
56
52
*/
57
- onSlideChange ?: ( a : number | string | null ) => void
53
+ onSlid ?: ( active : number , direction : string ) => void
54
+ /**
55
+ * Callback fired when a slide transition starts.
56
+ */
57
+ onSlide ?: ( active : number , direction : string ) => void
58
58
/**
59
59
* If set to 'hover', pauses the cycling of the carousel on mouseenter and resumes the cycling of the carousel on mouseleave. If set to false, hovering over the carousel won't pause it.
60
60
*/
@@ -84,14 +84,14 @@ export const CCarousel = forwardRef<HTMLDivElement, CCarouselProps>(
84
84
(
85
85
{
86
86
children,
87
- animate = true ,
87
+ activeIndex = 0 ,
88
88
className,
89
89
controls,
90
90
dark,
91
- index = 0 ,
92
91
indicators,
93
92
interval = 5000 ,
94
- onSlideChange,
93
+ onSlid,
94
+ onSlide,
95
95
pause = 'hover' ,
96
96
transition,
97
97
wrap = true ,
@@ -103,7 +103,7 @@ export const CCarousel = forwardRef<HTMLDivElement, CCarouselProps>(
103
103
const forkedRef = useForkedRef ( ref , carouselRef )
104
104
const data = useRef < DataType > ( { } ) . current
105
105
106
- const [ active , setActive ] = useState < number > ( 0 )
106
+ const [ active , setActive ] = useState < number > ( activeIndex )
107
107
const [ animating , setAnimating ] = useState < boolean > ( false )
108
108
const [ customInterval , setCustomInterval ] = useState < boolean | number > ( )
109
109
const [ direction , setDirection ] = useState < string > ( 'next' )
@@ -120,12 +120,10 @@ export const CCarousel = forwardRef<HTMLDivElement, CCarouselProps>(
120
120
121
121
useEffect ( ( ) => {
122
122
! animating && cycle ( )
123
+ ! animating && onSlid && onSlid ( active , direction )
124
+ animating && onSlide && onSlide ( active , direction )
123
125
} , [ animating ] )
124
126
125
- useEffect ( ( ) => {
126
- onSlideChange && onSlideChange ( active )
127
- } , [ active ] )
128
-
129
127
useEffect ( ( ) => {
130
128
window . addEventListener ( 'scroll' , handleScroll )
131
129
@@ -263,15 +261,15 @@ export const CCarousel = forwardRef<HTMLDivElement, CCarouselProps>(
263
261
)
264
262
265
263
CCarousel . propTypes = {
266
- animate : PropTypes . bool ,
264
+ activeIndex : PropTypes . number ,
267
265
children : PropTypes . node ,
268
266
className : PropTypes . string ,
269
267
controls : PropTypes . bool ,
270
268
dark : PropTypes . bool ,
271
- index : PropTypes . number ,
272
269
indicators : PropTypes . bool ,
273
270
interval : PropTypes . oneOfType ( [ PropTypes . bool , PropTypes . number ] ) ,
274
- onSlideChange : PropTypes . func ,
271
+ onSlid : PropTypes . func ,
272
+ onSlide : PropTypes . func ,
275
273
pause : PropTypes . oneOf ( [ false , 'hover' ] ) ,
276
274
transition : PropTypes . oneOf ( [ 'slide' , 'crossfade' ] ) ,
277
275
wrap : PropTypes . bool ,
0 commit comments