Cutout

@fabiocv/ui/cutout
Cutout.tsx
'use client'; import { motion, useSpring } from 'framer-motion'; import { Cutout, useCutout } from '@fabiocv/ui/cutout'; import { physics, SLIDE } from '@fabiocv/ui/spring'; import * as styles from './demos.css'; const SIZE = 40; /** Cuts the surface wherever it is, by reading the values that move it. */ function Cursor() { const x = useSpring(120, physics(SLIDE)); const y = useSpring(0, physics(SLIDE)); useCutout( () => ({ left: x.get(), top: y.get(), right: x.get() + SIZE, bottom: y.get() + SIZE, radius: 8, }), { values: [x, y] }, ); return ( <div className={styles.cursorArea} onPointerMove={(event) => { const box = event.currentTarget.getBoundingClientRect(); x.set(event.clientX - box.left - SIZE / 2); y.set(event.clientY - box.top - SIZE / 2); }} > <motion.div className={styles.cursor} style={{ x, y }} /> </div> ); } export function CutoutDemo() { return ( <Cutout.Root className={styles.cutout}> <Cutout.Surface className={styles.surface} /> <Cursor /> </Cutout.Root> ); }
Default