Css Box Hover Demo
fancy/css-box-hover-demoFreeBlock
A block component.
Install it
npx shadcn@latest add https://www.fancycomponents.dev/r/css-box-hover-demo.jsonSource
1import { useEffect, useRef } from "react"23import { cn } from "@/lib/utils"4import CSSBox, { CSSBoxRef } from "@/components/fancy/blocks/css-box"56const BoxText = ({7 children,8 className,9 i,10}: {11 children: React.ReactNode12 className?: string13 i: number14}) => (15 <div16 className={cn(17 "w-full h-full uppercase text-white flex items-center justify-center p-0 text-2xl md:text-3xl font-bold",18 className19 )}20 >21 {children}22 </div>23)2425export default function CSSBoxHoverDemo() {26 const boxRefs = useRef<(CSSBoxRef | null)[]>([])27 const isRotating = useRef<boolean[]>([])28 const currentRotations = useRef<number[]>([])2930 const boxes = [31 { text: "January 15, 2025", size: 300 },32 { text: "Live Q&A", size: 200 },33 { text: "10:00", size: 120 },34 { text: "to", size: 70 },35 { text: "11:30", size: 120 },36 { text: "CET", size: 120 },37 { text: "Online", size: 180 },38 { text: "Recording Available", size: 380 },39 { text: "In English", size: 220 },40 { text: "Register Now", size: 280 },41 { text: "Free Access", size: 240 },42 ]4344 useEffect(() => {45 currentRotations.current = new Array(boxes.length).fill(0)46 }, [])4748 const handleHover = async (index: number) => {49 if (isRotating.current[index]) return5051 isRotating.current[index] = true52 const box = boxRefs.current[index]53 if (!box) return5455 const nextRotation = currentRotations.current[index] + 9056 currentRotations.current[index] = nextRotation5758 box.rotateTo(0, nextRotation)5960 isRotating.current[index] = false61 }6263 return (64 <div className="flex flex-col items-center justify-center w-dvw h-dvh bg-[#111]">65 {boxes.map(({ text, size }, index) => (66 <CSSBox67 key={index}68 ref={(el) => {69 if (el) {70 boxRefs.current[index] = el71 isRotating.current[index] = false72 currentRotations.current[index] = 073 }74 }}75 width={size}76 height={35}77 depth={size}78 draggable={false}79 className="hover:z-10"80 onMouseEnter={() => handleHover(index)}81 faces={{82 front: <BoxText i={index}>{text}</BoxText>,83 back: (84 <BoxText i={index} className="">85 {text}86 </BoxText>87 ),88 left: <BoxText i={index}>{text}</BoxText>,89 right: (90 <BoxText i={index} className="">91 {text}92// … truncated
What it pulls in
Other registry items
Files it writes
More from fancy
All 158 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Animated Gradient Demoanimated-gradient-demo | fancy | Blocks | Free | no deps | |
| Basic Number Ticker Demobasic-number-ticker-demo | fancy | Blocks | Free | no deps | |
| Box Carousel Autoplay Demobox-carousel-autoplay-demo | fancy | Blocks | Free | 1 dep | |
| Box Carousel Demobox-carousel-demo | fancy | Blocks | Free | 1 dep | |
| Box Carousel Video Demobox-carousel-video-demo | fancy | Blocks | Free | 1 dep | |
| Breathing Text Demobreathing-text-demo | fancy | Blocks | Free | no deps | |
| Circling Elements Democircling-elements-demo | fancy | Blocks | Free | no deps | |
| Circling Elements Easing Democircling-elements-easing-demo | fancy | Blocks | Free | no deps |
