@bouko/react 2.4.6 → 2.4.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -2,6 +2,10 @@ import { ReactNode } from "react";
|
|
|
2
2
|
export declare type CarouselProps<T = ReactNode> = {
|
|
3
3
|
container?: string;
|
|
4
4
|
items: T[];
|
|
5
|
+
direction?: "horizontal" | "vertical";
|
|
6
|
+
interval?: number;
|
|
7
|
+
duration?: number;
|
|
8
|
+
autoplay?: boolean;
|
|
5
9
|
style?: string;
|
|
6
10
|
};
|
|
7
|
-
export declare function Carousel({ container, items,
|
|
11
|
+
export declare function Carousel({ container, style, items, direction, autoplay, interval, ...props }: CarouselProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -1,15 +1,19 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
import { AnimatePresence } from "framer-motion";
|
|
4
|
+
import { Animation } from "../animate";
|
|
3
5
|
import { useState, useEffect } from "react";
|
|
4
|
-
import {
|
|
6
|
+
import { opacity, slideX, slideY } from "../animate";
|
|
5
7
|
import { cn } from "@bouko/style";
|
|
6
|
-
export function Carousel({ container, items,
|
|
8
|
+
export function Carousel({ container, style, items, direction = "horizontal", autoplay = true, interval = 3000, ...props }) {
|
|
7
9
|
const [index, setIndex] = useState(0);
|
|
8
10
|
useEffect(() => {
|
|
9
|
-
|
|
11
|
+
if (items.length === 0 || !autoplay)
|
|
12
|
+
return;
|
|
13
|
+
const intervalTracker = setInterval(() => {
|
|
10
14
|
setIndex((prev) => (prev + 1) % items.length);
|
|
11
|
-
},
|
|
12
|
-
return () => clearInterval(
|
|
13
|
-
}, []);
|
|
14
|
-
return (_jsx("div", { className: cn("flex items-center", container), children: _jsx(AnimatePresence, { mode: "wait", children: _jsx(
|
|
15
|
+
}, interval);
|
|
16
|
+
return () => clearInterval(intervalTracker);
|
|
17
|
+
}, [items.length, interval, autoplay]);
|
|
18
|
+
return (_jsx("div", { className: cn("flex items-center", container), children: _jsx(AnimatePresence, { mode: "wait", children: _jsx(Animation, { style: cn("w-full", style), variants: [opacity(), direction === "horizontal" ? slideX() : slideY()], children: items[index], ...props }, index) }, void 0) }, void 0));
|
|
15
19
|
}
|