Spotlight Card

Carte avec un projecteur radial qui suit le pointeur. Installez Spotlight Card depuis le registre VLLNT UI avec la CLI shadcn.

Signaler un bug

Carte avec un projecteur radial qui suit le pointeur. Fait partie de la famille utility dans VLLNT UI, il est publie comme entree de registre lisible par machine — copiez la source directement dans votre application avec la CLI shadcn et possedez-la, sans dependance d'execution a une bibliotheque de composants.

Apercu

Basculez entre clair et sombre pour inspecter l'apercu Storybook integre.

Installation

Ajoutez Spotlight Card a votre projet avec la CLI shadcn. La source arrive dans votre code, prete a etre adaptee :

pnpm dlx shadcn@latest add https://ui.vllnt.ai/r/spotlight-card.json

Source

"use client"; import * as React from "react"; import { cn } from "../../lib/utils"; /** Props for {@link SpotlightCard}. */ export type SpotlightCardProps = React.ComponentPropsWithoutRef<"div">; type Point = { x: number; y: number }; /** * Card with a radial spotlight that tracks the pointer across its surface. * * @example * ```tsx * <SpotlightCard>Hover me</SpotlightCard> * ``` */ export const SpotlightCard = ({ children, className, ref, ...props }: SpotlightCardProps & { ref?: React.Ref<HTMLDivElement> }) => { const [point, setPoint] = React.useState<Point | undefined>(); const handlePointerMove = ( event: React.PointerEvent<HTMLDivElement>, ): void => { const bounds = event.currentTarget.getBoundingClientRect(); setPoint({ x: event.clientX - bounds.left, y: event.clientY - bounds.top, }); }; const handlePointerLeave = (): void => { setPoint(undefined); }; return ( <div className={cn( "relative overflow-hidden rounded-xl border bg-card p-6", className, )} onPointerLeave={handlePointerLeave} onPointerMove={handlePointerMove} ref={ref} {...props} > <span aria-hidden="true" className="pointer-events-none absolute inset-0 transition-opacity duration-300" style={{ background: point ? `radial-gradient(180px circle at ${point.x}px ${point.y}px, oklch(var(--foreground) / 0.10), transparent 65%)` : undefined, opacity: point ? 1 : 0, }} /> <div className="relative z-10">{children}</div> </div> ); }; SpotlightCard.displayName = "SpotlightCard";

Stories

Explorez chaque variante et etat dans le Storybook interactif :

Apercu

Basculez entre clair et sombre pour inspecter l'apercu Storybook integre.

Dependances

  • @vllnt/ui@^0.3.0