BlockDex

Components

Registries

Free blocks

Method

BlockDex

Components

Registries

Free blocks

Method

Open API

BlockDex

Components

Registries

Free blocks

Method

Open API

Components/magicui/lens

Lens

magicui/lens
FreeComponent

A interactive component that enables zooming into images, videos and other elements.

Live preview

live · rendered by the registry
Rendered by magicui on their own page — this is the component running, not a screenshot of it.

Install it

npx shadcn@latest add https://magicui.design/r/lens.json

Source

registry/magicui/lens.tsxmagicui.design/r/lens.json
1"use client"
2
3import React, { useCallback, useMemo, useRef, useState } from "react"
4import { AnimatePresence, motion, useMotionTemplate } from "motion/react"
5
6interface Position {
7 /** The x coordinate of the lens */
8 x: number
9 /** The y coordinate of the lens */
10 y: number
11}
12
13interface LensProps {
14 /** The children of the lens */
15 children: React.ReactNode
16 /** The zoom factor of the lens */
17 zoomFactor?: number
18 /** The size of the lens */
19 lensSize?: number
20 /** The position of the lens */
21 position?: Position
22 /** The default position of the lens */
23 defaultPosition?: Position
24 /** Whether the lens is static */
25 isStatic?: boolean
26 /** The duration of the animation */
27 duration?: number
28 /** The color of the lens */
29 lensColor?: string
30 /** The aria label of the lens */
31 ariaLabel?: string
32}
33
34export function Lens({
35 children,
36 zoomFactor = 1.3,
37 lensSize = 170,
38 isStatic = false,
39 position = { x: 0, y: 0 },
40 defaultPosition,
41 duration = 0.1,
42 lensColor = "black",
43 ariaLabel = "Zoom Area",
44}: LensProps) {
45 if (zoomFactor < 1) {
46 throw new Error("zoomFactor must be greater than 1")
47 }
48 if (lensSize < 0) {
49 throw new Error("lensSize must be greater than 0")
50 }
51
52 const [isHovering, setIsHovering] = useState(false)
53 const [mousePosition, setMousePosition] = useState<Position>(position)
54 const containerRef = useRef<HTMLDivElement>(null)
55
56 const currentPosition = useMemo(() => {
57 if (isStatic) return position
58 if (defaultPosition && !isHovering) return defaultPosition
59 return mousePosition
60 }, [isStatic, position, defaultPosition, isHovering, mousePosition])
61
62 const handleMouseMove = useCallback((e: React.MouseEvent<HTMLDivElement>) => {
63 const rect = e.currentTarget.getBoundingClientRect()
64 setMousePosition({
65 x: e.clientX - rect.left,
66 y: e.clientY - rect.top,
67 })
68 }, [])
69
70 const handleKeyDown = useCallback((e: React.KeyboardEvent) => {
71 if (e.key === "Escape") setIsHovering(false)
72 }, [])
73
74 const maskImage = useMotionTemplate`radial-gradient(circle ${
75 lensSize / 2
76 }px at ${currentPosition.x}px ${
77 currentPosition.y
78 }px, ${lensColor} 100%, transparent 100%)`
79
80 const LensContent = useMemo(() => {
81 const { x, y } = currentPosition
82
83 return (
84 <motion.div
85 initial={{ opacity: 0, scale: 0.58 }}
86 animate={{ opacity: 1, scale: 1 }}
87 exit={{ opacity: 0, scale: 0.8 }}
88 transition={{ duration }}
89// … truncated

What it pulls in

npm packages

  • motion

Files it writes

  • registry/magicui/lens.tsx

Facts

Registry
magicui
Type
registry:ui
Access
Free
Files written
1
Licence
the repository states none
First indexed
2026-08-02
Last confirmed
today

Go to the source

Docs on magicui magicui.design magicuidesign/magicui on GitHub Raw registry item This item as JSON

More from magicui

All 247 items
Same registry, same kind — the ones you would have found next
ComponentRegistryKindAccessInstallsCommand
AndroidandroidmagicuiComponentsFreeno deps
Animated Beamanimated-beammagicuiComponentsFree1 dep
Animated Circular Progress Baranimated-circular-progress-barmagicuiComponentsFreeno deps
Animated Gradient Textanimated-gradient-textmagicuiComponentsFreeno deps
Animated Grid Patternanimated-grid-patternmagicuiComponentsFree1 dep
Animated Listanimated-listmagicuiComponentsFree1 dep
Animated Shiny Textanimated-shiny-textmagicuiComponentsFreeno deps
Theme Toggleranimated-theme-togglermagicuiComponentsFree1 dep
BlockDex

Built by

Kynth Studio

Index

Components
Registries
Method
Open API

Guides

shadcn component libraries
Best shadcn registries
Free shadcn blocks

Reference

Corpus counts
Crawl health
hello@kynth.studio
Privacy
Terms

BlockDex

BlockDex

Built by

Kynth Studio

Index

Components
Registries
Method
Open API

Guides

shadcn component libraries
Best shadcn registries
Free shadcn blocks

Reference

Corpus counts
Crawl health
hello@kynth.studio
Privacy
Terms

BlockDex

BlockDex

Built by

Kynth Studio

Index

Components
Registries
Method
Open API

Guides

shadcn component libraries
Best shadcn registries
Free shadcn blocks

Reference

Corpus counts
Crawl health
hello@kynth.studio
Privacy
Terms

BlockDex