Video Carousel
shadcn-collections/video-carouselFreeComponent
An interactive 3D real time audio visualizer.
Install it
npx shadcn@latest add https://chatcn.me/r/video-carousel.jsonSource
1"use client"23import React, { useEffect, useRef, useState, useCallback } from "react"4import { useInView, animate } from "framer-motion"5import { HugeiconsIcon } from "@hugeicons/react"6import { PauseIcon, PlayIcon } from "@hugeicons/core-free-icons"78export interface VideoItem {9 url: string10 duration: number11}1213export interface VideoCarouselProps {14 videos: VideoItem[]15 className?: string16}1718interface VideoState {19 currentVideoId: number20 isPlaying: boolean21 hasStarted: boolean22}2324export function VideoCarousel({ videos, className = "" }: VideoCarouselProps) {25 const containerRef = useRef<HTMLDivElement>(null)26 const carouselRef = useRef<HTMLDivElement>(null)27 const sliderRef = useRef<HTMLDivElement>(null)28 const videoRef = useRef<(HTMLVideoElement | null)[]>([])29 const videoSpanRef = useRef<(HTMLSpanElement | null)[]>([])30 const videoDivRef = useRef<(HTMLSpanElement | null)[]>([])3132 const [containerWidth, setContainerWidth] = useState(0)33 const [videoState, setVideoState] = useState<VideoState>({34 currentVideoId: 0,35 isPlaying: false,36 hasStarted: false,37 })3839 const { currentVideoId, isPlaying, hasStarted } = videoState40 const isInView = useInView(carouselRef, { once: true, amount: 0.5 })4142 const getVideoWidth = useCallback((): number => {43 if (!containerWidth) return 044 return containerWidth < 640 ? containerWidth * 0.88 : containerWidth * 0.745 }, [containerWidth])4647 const getGap = useCallback((): number => {48 if (!containerWidth) return 8049 return containerWidth < 640 ? 40 : 8050 }, [containerWidth])5152 const getTranslateValue = useCallback((): number => {53 if (!containerWidth) return 054 const videoWidth = getVideoWidth()55 const gap = getGap()56 const offset = (containerWidth - videoWidth) / 257 const slideOffset = currentVideoId * (videoWidth + gap)58 return offset - slideOffset59 }, [containerWidth, currentVideoId, getVideoWidth, getGap])6061 const getResponsiveWidth = useCallback((): string => {62 if (!containerWidth) return "60px"63 if (containerWidth < 480) return `${containerWidth * 0.15}px`64 if (containerWidth < 760) return `${containerWidth * 0.12}px`65 if (containerWidth < 1200) return `${containerWidth * 0.1}px`66 return `${containerWidth * 0.08}px`67 }, [containerWidth])6869 useEffect(() => {70 const updateWidth = () => {71// … truncated
What it pulls in
npm packages
Files it writes
More from shadcn-collections
All 24 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Audio Visualizeraudio-visualizer | shadcn-collections | Components | Free | 4 deps | |
| Calendarcalendar | shadcn-collections | Components | Free | no deps | |
| Chat Containerchat-container | shadcn-collections | Components | Free | no deps | |
| Code Editorcode-editor | shadcn-collections | Components | Free | no deps | |
| Code Blockcodeblock | shadcn-collections | Components | Free | 1 dep | |
| Command Blockcommand-block | shadcn-collections | Components | Free | no deps | |
| Command Tabscommand-tabs | shadcn-collections | Components | Free | no deps | |
| Emailemail | shadcn-collections | Components | Free | no deps |
