Css Box
fancy/css-boxFreeComponent
A ui component.
Install it
npx shadcn@latest add https://www.fancycomponents.dev/r/css-box.jsonSource
1"use client"23import {4 forwardRef,5 ReactNode,6 useCallback,7 useEffect,8 useImperativeHandle,9 useRef,10} from "react"11import { motion, useMotionValue, useSpring, useTransform } from "motion/react"1213import { cn } from "@/lib/utils"1415interface FaceProps {16 transform: string17 className?: string18 showBackface?: boolean19 children?: ReactNode20 style?: React.CSSProperties21}2223const CubeFace = ({24 transform,25 className,26 showBackface,27 children,28 style,29}: FaceProps) => (30 <div31 className={cn(32 "absolute",33 showBackface ? "backface-visible" : "backface-hidden",34 className35 )}36 style={{ transform, ...style }}37 >38 {children}39 </div>40)4142interface CubeFaces {43 front?: ReactNode44 back?: ReactNode45 right?: ReactNode46 left?: ReactNode47 top?: ReactNode48 bottom?: ReactNode49}5051export interface CSSBoxRef {52 showFront: () => void53 showBack: () => void54 showLeft: () => void55 showRight: () => void56 showTop: () => void57 showBottom: () => void58 rotateTo: (x: number, y: number) => void59 getCurrentRotation: () => { x: number; y: number }60}6162interface CSSBoxProps extends React.HTMLProps<HTMLDivElement> {63 width: number64 height: number65 depth: number66 className?: string67 perspective?: number68 stiffness?: number69 damping?: number70 showBackface?: boolean71 faces?: CubeFaces72 draggable?: boolean73}7475const CSSBox = forwardRef<CSSBoxRef, CSSBoxProps>(76 (77 {78 width,79 height,80 depth,81 className,82 perspective = 600,83 stiffness = 100,84 damping = 30,85 showBackface = false,86 faces = {},87 draggable = true,88 ...props89 },90 ref91 ) => {92 const isDragging = useRef(false)93 const startPosition = useRef({ x: 0, y: 0 })94 const startRotation = useRef({ x: 0, y: 0 })9596 const baseRotateX = useMotionValue(0)97 const baseRotateY = useMotionValue(0)9899 const springRotateX = useSpring(baseRotateX, {100 stiffness,101 damping,102 ...(isDragging.current ? { stiffness: stiffness / 2 } : {}),103 })104 const springRotateY = useSpring(baseRotateY, {105 stiffness,106 damping,107 ...(isDragging.current ? { stiffness: stiffness / 2 } : {}),108 })109110 const currentRotation = useRef({ x: 0, y: 0 })111112 useImperativeHandle(113 ref,114 () => ({115 showFront: () => {116 baseRotateX.set(0)117 baseRotateY.set(0)118 },119 showBack: () => {120 baseRotateX.set(0)121 baseRotateY.set(180)122 },123// … truncated
What it pulls in
npm packages
Files it writes
More from fancy
All 158 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Animated Gradient With Svganimated-gradient-with-svg | fancy | Components | Free | no deps | |
| Basic Number Tickerbasic-number-ticker | fancy | Components | Free | 1 dep | |
| Box Carouselbox-carousel | fancy | Components | Free | 1 dep | |
| Breathing Textbreathing-text | fancy | Components | Free | 1 dep | |
| Circling Elementscircling-elements | fancy | Components | Free | 1 dep | |
| Cursor Attractor And Gravitycursor-attractor-and-gravity | fancy | Components | Free | 5 deps | |
| Drag Elementsdrag-elements | fancy | Components | Free | 1 dep | |
| Elastic Lineelastic-line | fancy | Components | Free | 1 dep |
