@@ -3,33 +3,44 @@ import type { ComponentProps, FC, PropsWithChildren, ReactElement, ReactNode } f
33import { Children , cloneElement , useCallback , useEffect , useMemo , useRef , useState } from 'react' ;
44import { HiOutlineChevronLeft , HiOutlineChevronRight } from 'react-icons/hi' ;
55import ScrollContainer from 'react-indiana-drag-scroll' ;
6+ import { mergeDeep } from '../../helpers/mergeDeep' ;
67import windowExists from '../../helpers/window-exists' ;
8+ import { FlowbiteBoolean } from '../Flowbite/FlowbiteTheme' ;
79import { useTheme } from '../Flowbite/ThemeContext' ;
810
911export interface FlowbiteCarouselTheme {
12+ root : FlowbiteCarouselRootTheme ;
13+ indicators : FlowbiteCarouselIndicatorsTheme ;
14+ item : FlowbiteCarouselItemTheme ;
15+ control : FlowbiteCarouselControlTheme ;
16+ scrollContainer : FlowbiteCarouselScrollContainer ;
17+ }
18+
19+ export interface FlowbiteCarouselRootTheme {
1020 base : string ;
11- indicators : {
12- active : {
13- off : string ;
14- on : string ;
15- } ;
16- base : string ;
17- wrapper : string ;
18- } ;
19- item : {
20- base : string ;
21- wrapper : string ;
22- } ;
23- control : {
24- base : string ;
25- icon : string ;
26- } ;
2721 leftControl : string ;
2822 rightControl : string ;
29- scrollContainer : {
30- base : string ;
31- snap : string ;
32- } ;
23+ }
24+
25+ export interface FlowbiteCarouselIndicatorsTheme {
26+ active : FlowbiteBoolean ;
27+ base : string ;
28+ wrapper : string ;
29+ }
30+
31+ export interface FlowbiteCarouselItemTheme {
32+ base : string ;
33+ wrapper : string ;
34+ }
35+
36+ export interface FlowbiteCarouselControlTheme {
37+ base : string ;
38+ icon : string ;
39+ }
40+
41+ export interface FlowbiteCarouselScrollContainer {
42+ base : string ;
43+ snap : string ;
3344}
3445
3546export interface CarouselProps extends PropsWithChildren < ComponentProps < 'div' > > {
@@ -38,6 +49,7 @@ export interface CarouselProps extends PropsWithChildren<ComponentProps<'div'>>
3849 rightControl ?: ReactNode ;
3950 slide ?: boolean ;
4051 slideInterval ?: number ;
52+ theme ?: FlowbiteCarouselTheme ;
4153}
4254
4355export const Carousel : FC < CarouselProps > = ( {
@@ -48,14 +60,15 @@ export const Carousel: FC<CarouselProps> = ({
4860 slide = true ,
4961 slideInterval,
5062 className,
63+ theme : customTheme = { } ,
5164 ...props
5265} ) : JSX . Element => {
53- const isDeviceMobile = windowExists ( ) && navigator . userAgent . indexOf ( 'IEMobile' ) !== - 1 ;
66+ const theme = mergeDeep ( useTheme ( ) . theme . carousel , customTheme ) ;
5467
68+ const isDeviceMobile = windowExists ( ) && navigator . userAgent . indexOf ( 'IEMobile' ) !== - 1 ;
5569 const carouselContainer = useRef < HTMLDivElement > ( null ) ;
5670 const [ activeItem , setActiveItem ] = useState ( 0 ) ;
5771 const [ isDragging , setIsDragging ] = useState ( false ) ;
58- const theme = useTheme ( ) . theme . carousel ;
5972
6073 const items = useMemo (
6174 ( ) =>
@@ -96,7 +109,7 @@ export const Carousel: FC<CarouselProps> = ({
96109 const handleDragging = ( dragging : boolean ) => ( ) => setIsDragging ( dragging ) ;
97110
98111 return (
99- < div className = { classNames ( theme . base , className ) } data-testid = "carousel" { ...props } >
112+ < div className = { classNames ( theme . root . base , className ) } data-testid = "carousel" { ...props } >
100113 < ScrollContainer
101114 className = { classNames (
102115 theme . scrollContainer . base ,
@@ -141,7 +154,7 @@ export const Carousel: FC<CarouselProps> = ({
141154
142155 { items && (
143156 < >
144- < div className = { theme . leftControl } >
157+ < div className = { theme . root . leftControl } >
145158 < button
146159 className = "group"
147160 data-testid = "carousel-left-control"
@@ -151,7 +164,7 @@ export const Carousel: FC<CarouselProps> = ({
151164 { leftControl ? leftControl : < DefaultLeftControl /> }
152165 </ button >
153166 </ div >
154- < div className = { theme . rightControl } >
167+ < div className = { theme . root . rightControl } >
155168 < button
156169 className = "group"
157170 data-testid = "carousel-right-control"
0 commit comments