@@ -24,9 +24,9 @@ const isVisible = (element: HTMLDivElement) => {
2424
2525export interface CCarouselProps extends HTMLAttributes < HTMLDivElement > {
2626 /**
27- * Set 'animate' variable for created context .
27+ * index of the active item .
2828 */
29- animate ?: boolean
29+ activeIndex ?: number
3030 /**
3131 * A string of all className you want applied to the base component.
3232 */
@@ -43,18 +43,18 @@ export interface CCarouselProps extends HTMLAttributes<HTMLDivElement> {
4343 * The amount of time to delay between automatically cycling an item. If false, carousel will not automatically cycle.
4444 */
4545 interval ?: boolean | number
46- /**
47- * index of the active item.
48- */
49- index ?: number
5046 /**
5147 * Adding indicators at the bottom of the carousel for each item.
5248 */
5349 indicators ?: boolean
5450 /**
55- * On slide change callback .
51+ * Callback fired when a slide transition end .
5652 */
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
5858 /**
5959 * 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.
6060 */
@@ -84,14 +84,14 @@ export const CCarousel = forwardRef<HTMLDivElement, CCarouselProps>(
8484 (
8585 {
8686 children,
87- animate = true ,
87+ activeIndex = 0 ,
8888 className,
8989 controls,
9090 dark,
91- index = 0 ,
9291 indicators,
9392 interval = 5000 ,
94- onSlideChange,
93+ onSlid,
94+ onSlide,
9595 pause = 'hover' ,
9696 transition,
9797 wrap = true ,
@@ -103,7 +103,7 @@ export const CCarousel = forwardRef<HTMLDivElement, CCarouselProps>(
103103 const forkedRef = useForkedRef ( ref , carouselRef )
104104 const data = useRef < DataType > ( { } ) . current
105105
106- const [ active , setActive ] = useState < number > ( 0 )
106+ const [ active , setActive ] = useState < number > ( activeIndex )
107107 const [ animating , setAnimating ] = useState < boolean > ( false )
108108 const [ customInterval , setCustomInterval ] = useState < boolean | number > ( )
109109 const [ direction , setDirection ] = useState < string > ( 'next' )
@@ -120,12 +120,10 @@ export const CCarousel = forwardRef<HTMLDivElement, CCarouselProps>(
120120
121121 useEffect ( ( ) => {
122122 ! animating && cycle ( )
123+ ! animating && onSlid && onSlid ( active , direction )
124+ animating && onSlide && onSlide ( active , direction )
123125 } , [ animating ] )
124126
125- useEffect ( ( ) => {
126- onSlideChange && onSlideChange ( active )
127- } , [ active ] )
128-
129127 useEffect ( ( ) => {
130128 window . addEventListener ( 'scroll' , handleScroll )
131129
@@ -263,15 +261,15 @@ export const CCarousel = forwardRef<HTMLDivElement, CCarouselProps>(
263261)
264262
265263CCarousel . propTypes = {
266- animate : PropTypes . bool ,
264+ activeIndex : PropTypes . number ,
267265 children : PropTypes . node ,
268266 className : PropTypes . string ,
269267 controls : PropTypes . bool ,
270268 dark : PropTypes . bool ,
271- index : PropTypes . number ,
272269 indicators : PropTypes . bool ,
273270 interval : PropTypes . oneOfType ( [ PropTypes . bool , PropTypes . number ] ) ,
274- onSlideChange : PropTypes . func ,
271+ onSlid : PropTypes . func ,
272+ onSlide : PropTypes . func ,
275273 pause : PropTypes . oneOf ( [ false , 'hover' ] ) ,
276274 transition : PropTypes . oneOf ( [ 'slide' , 'crossfade' ] ) ,
277275 wrap : PropTypes . bool ,
0 commit comments