Skip to content

Commit

Permalink
Added draggable option to carousel component (#1121)
Browse files Browse the repository at this point in the history
* added draggable option to carousel component

* prettier formatting

* fixed mouse cursor when draggable flag is off

* add draggable to theme and remove redundant change
  • Loading branch information
Sigabiel authored Nov 18, 2023
1 parent d410b79 commit f5f6e32
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
9 changes: 6 additions & 3 deletions src/components/Carousel/Carousel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export interface FlowbiteCarouselIndicatorsTheme {

export interface FlowbiteCarouselItemTheme {
base: string;
wrapper: string;
wrapper: FlowbiteBoolean;
}

export interface FlowbiteCarouselControlTheme {
Expand All @@ -50,6 +50,7 @@ export interface CarouselProps extends ComponentProps<'div'> {
indicators?: boolean;
leftControl?: ReactNode;
rightControl?: ReactNode;
draggable?: boolean;
slide?: boolean;
slideInterval?: number;
theme?: DeepPartial<FlowbiteCarouselTheme>;
Expand All @@ -67,6 +68,7 @@ export const Carousel: FC<CarouselProps> = ({
leftControl,
rightControl,
slide = true,
draggable = true,
slideInterval,
className,
theme: customTheme = {},
Expand Down Expand Up @@ -148,13 +150,14 @@ export const Carousel: FC<CarouselProps> = ({
draggingClassName="cursor-grab"
innerRef={carouselContainer}
onEndScroll={handleDragging(false)}
onStartScroll={handleDragging(true)}
onStartScroll={handleDragging(draggable)}
vertical={false}
horizontal={draggable}
>
{items?.map((item, index) => (
<div
key={index}
className={theme.item.wrapper}
className={theme.item.wrapper[draggable ? 'on' : 'off']}
data-active={activeItem === index}
data-testid="carousel-item"
>
Expand Down
5 changes: 4 additions & 1 deletion src/components/Carousel/theme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ export const carouselTheme: FlowbiteCarouselTheme = {
},
item: {
base: 'absolute top-1/2 left-1/2 block w-full -translate-x-1/2 -translate-y-1/2',
wrapper: 'w-full flex-shrink-0 transform cursor-grab snap-center',
wrapper: {
off: 'w-full flex-shrink-0 transform cursor-default snap-center',
on: 'w-full flex-shrink-0 transform cursor-grab snap-center',
},
},
control: {
base: 'inline-flex h-8 w-8 items-center justify-center rounded-full bg-white/30 group-hover:bg-white/50 group-focus:outline-none group-focus:ring-4 group-focus:ring-white dark:bg-gray-800/30 dark:group-hover:bg-gray-800/60 dark:group-focus:ring-gray-800/70 sm:h-10 sm:w-10',
Expand Down

1 comment on commit f5f6e32

@vercel
Copy link

@vercel vercel bot commented on f5f6e32 Nov 18, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.