Direction Reveal
rivelle/direction-revealFreeComponent
A reveal overlay that enters and exits from the pointer direction.
Install it
npx shadcn@latest add https://rivelle.dev/r/direction-reveal.jsonSource
1"use client";23import * as React from "react";45import { cn } from "@/lib/utils";67type Direction = "top" | "right" | "bottom" | "left";89type DirectionRevealProps = React.ComponentProps<"div"> & {10 reveal: React.ReactNode;11 revealClassName?: string;12};1314const transforms: Record<Direction, string> = {15 top: "translate3d(0,-101%,0)",16 right: "translate3d(101%,0,0)",17 bottom: "translate3d(0,101%,0)",18 left: "translate3d(-101%,0,0)",19};2021function getDirection(event: React.MouseEvent<HTMLDivElement>): Direction {22 const bounds = event.currentTarget.getBoundingClientRect();23 const x = event.clientX - bounds.left - bounds.width / 2;24 const y = event.clientY - bounds.top - bounds.height / 2;25 const angle = Math.atan2(y, x) * (180 / Math.PI);26 if (angle >= -45 && angle < 45) return "right";27 if (angle >= 45 && angle < 135) return "bottom";28 if (angle >= -135 && angle < -45) return "top";29 return "left";30}3132function DirectionReveal({33 children,34 className,35 onMouseEnter,36 onMouseLeave,37 onPointerMove,38 reveal,39 revealClassName,40 ...props41}: DirectionRevealProps) {42 const [direction, setDirection] = React.useState<Direction>("bottom");43 const [visible, setVisible] = React.useState(false);4445 return (46 <div47 className={cn(48 "group relative isolate overflow-hidden rounded-[2rem] border border-foreground/10 bg-card [contain:paint]",49 className,50 )}51 data-direction={direction}52 data-slot="direction-reveal"53 onMouseEnter={(event) => {54 setDirection(getDirection(event));55 setVisible(true);56 onMouseEnter?.(event);57 }}58 onMouseLeave={(event) => {59 setDirection(getDirection(event));60 setVisible(false);61 onMouseLeave?.(event);62 }}63 onPointerMove={(event) => {64 if (!visible) {65 setDirection(getDirection(event));66 setVisible(true);67 }68 onPointerMove?.(event);69 }}70 {...props}71 >72 <div className="h-full transition-transform duration-500 ease-[cubic-bezier(.22,1,.36,1)] group-hover:scale-[1.025]">73 {children}74 </div>75 <div76 aria-hidden={!visible}77 className={cn(78 "absolute inset-0 z-10 transition-transform duration-500 ease-[cubic-bezier(.22,1,.36,1)] will-change-transform [backface-visibility:hidden] motion-reduce:transition-none",79 revealClassName,80 )}81 style={{82// … truncated
What it pulls in
Other registry items
Files it writes
More from rivelle
All 83 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Accordionaccordion | rivelle | Components | Free | 2 deps | |
| Alertalert | rivelle | Components | Free | 1 dep | |
| Alert Dialogalert-dialog | rivelle | Components | Free | 1 dep | |
| Aspect Ratioaspect-ratio | rivelle | Components | Free | 1 dep | |
| Avataravatar | rivelle | Components | Free | 1 dep | |
| Badgebadge | rivelle | Components | Free | 2 deps | |
| Breadcrumbbreadcrumb | rivelle | Components | Free | 2 deps | |
| Buttonbutton | rivelle | Components | Free | 2 deps |
