@bouko/react 2.0.0 → 2.0.2

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.
@@ -0,0 +1,7 @@
1
+ import { ReactNode } from "react";
2
+ export type CarouselProps<T = ReactNode> = {
3
+ container?: string;
4
+ items: T[];
5
+ style?: string;
6
+ };
7
+ export declare function Carousel({ container, items, style }: CarouselProps): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,15 @@
1
+ "use client";
2
+ import { jsx as _jsx } from "react/jsx-runtime";
3
+ import { useState, useEffect } from "react";
4
+ import { AnimatePresence, motion } from "framer-motion";
5
+ import { cn } from "@bouko/style";
6
+ export function Carousel({ container, items, style }) {
7
+ const [index, setIndex] = useState(0);
8
+ useEffect(() => {
9
+ const interval = setInterval(() => {
10
+ setIndex((prev) => (prev + 1) % items.length);
11
+ }, 3000);
12
+ return () => clearInterval(interval);
13
+ }, []);
14
+ return (_jsx("div", { className: cn("flex items-center", container), children: _jsx(AnimatePresence, { mode: "wait", children: _jsx(motion.div, { transition: { duration: 0.5 }, initial: { opacity: 0, y: 5 }, animate: { opacity: 1, y: 0 }, exit: { opacity: 0, y: -5 }, layout: true, children: _jsx("div", { className: cn("w-full h-full", style), children: items[index] }) }, index) }) }));
15
+ }
@@ -6,3 +6,4 @@ export { default as Dropdown } from "./dropdown/normal";
6
6
  export { default as FileUploader } from "./upload/file";
7
7
  export * from "./list";
8
8
  export * from "./form";
9
+ export * from "./carousel";
@@ -6,3 +6,4 @@ export { default as Dropdown } from "./dropdown/normal";
6
6
  export { default as FileUploader } from "./upload/file";
7
7
  export * from "./list";
8
8
  export * from "./form";
9
+ export * from "./carousel";
@@ -1,3 +1,4 @@
1
1
  export declare const getFileData: (files: File[]) => Promise<unknown[]>;
2
+ export declare const getAudioDuration: (file: File) => Promise<number>;
2
3
  export declare const getEnv: (key: string) => string;
3
4
  export declare function getBase64(image: string): Promise<string>;
@@ -13,6 +13,21 @@ export const getFileData = (files) => Promise.all(files.map((file) => {
13
13
  reader.readAsDataURL(file);
14
14
  });
15
15
  }));
16
+ export const getAudioDuration = (file) => {
17
+ return new Promise((resolve, reject) => {
18
+ const url = URL.createObjectURL(file);
19
+ const audio = new Audio(url);
20
+ audio.addEventListener("loadedmetadata", () => {
21
+ const durationMs = audio.duration * 1000;
22
+ URL.revokeObjectURL(url);
23
+ resolve(durationMs);
24
+ });
25
+ audio.addEventListener("error", (e) => {
26
+ URL.revokeObjectURL(url);
27
+ reject(new Error("Failed to load audio metadata"));
28
+ });
29
+ });
30
+ };
16
31
  export const getEnv = (key) => {
17
32
  const value = process.env[key];
18
33
  if (!value)
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
 
3
3
  "name": "@bouko/react",
4
- "version": "2.0.0",
4
+ "version": "2.0.2",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
7
7
  "license": "MIT",