UI Library for Design Engineers. Animated components and effects you can copy and paste into your apps. Free. Open Source.
[FEAT] New Lens component (#508)
Isaac "H3rmel" Reginatof775706dccfe
diff --git a/__registry__/index.tsx b/__registry__/index.tsxindex 868fbd25..8526ac3c 100644--- a/__registry__/index.tsx+++ b/__registry__/index.tsx@@ -177,6 +177,30 @@ export const Index: Record<string, any> = {}),meta: undefined,},+ lens: {+ name: "lens",+ description:+ "A interactive component that enables zooming into images, videos and other elements.",+ type: "registry:ui",+ registryDependencies: undefined,+ files: [+ {+ path: "registry/magicui/lens.tsx",+ type: "registry:ui",+ target: "components/magicui/lens.tsx",+ },+ ],+ component: React.lazy(async () => {+ const mod = await import("@/registry/magicui/lens.tsx");+ const exportName =+ Object.keys(mod).find(+ (key) =>+ typeof mod[key] === "function" || typeof mod[key] === "object",+ ) || item.name;+ return { default: mod.default || mod[exportName] };+ }),+ meta: undefined,+ },"neon-gradient-card": {name: "neon-gradient-card",description: "A beautiful neon card effect",@@ -1712,6 +1736,85 @@ export const Index: Record<string, any> = {}),meta: undefined,},+ "lens-demo": {+ name: "lens-demo",+ description: "Example showing a lens effect component",+ type: "registry:example",+ registryDependencies: ["button", "card", "https://magicui.design/r/lens"],+ files: [+ {+ path: "registry/example/lens-demo.tsx",+ type: "registry:example",+ target: "components/lens-demo.tsx",+ },+ {+ path: "registry/magicui/lens.tsx",+ type: "registry:ui",+ target: "components/magicui/lens.tsx",+ },+ ],+ component: React.lazy(async () => {+ const mod = await import("@/registry/example/lens-demo.tsx");+ const exportName =+ Object.keys(mod).find(+ (key) =>+ typeof mod[key] === "function" || typeof mod[key] === "object",+ ) || item.name;+ return { default: mod.default || mod[exportName] };+ }),+ meta: undefined,+ },+ "lens-demo-2": {+ name: "lens-demo-2",+ description: "Second example showing a lens effect component",+ type: "registry:example",+ registryDependencies: ["button", "card", "https://magicui.design/r/lens"],+ files: [+ {+ path: "registry/example/lens-demo-2.tsx",+ type: "registry:example",+ target: "components/lens-demo-2.tsx",+ },+ {+ path: "registry/magicui/lens.tsx",+ type: "registry:ui",+ target: "components/magicui/lens.tsx",+ },+ ],+ component: React.lazy(async () => {+ const mod = await import("@/registry/example/lens-demo-2.tsx");+ const exportName =+ Object.keys(mod).find(+ (key) =>+ typeof mod[key] === "function" || typeof mod[key] === "object",+ ) || item.name;+ return { default: mod.default || mod[exportName] };+ }),+ meta: undefined,+ },+ "lens-demo-3": {+ name: "lens-demo-3",+ description: "Third example showing a lens effect component",+ type: "registry:example",+ registryDependencies: ["button", "card", "https://magicui.design/r/lens"],+ files: [+ {+ path: "registry/example/lens-demo-3.tsx",+ type: "registry:example",+ target: "components/lens-demo-3.tsx",+ },+ ],+ component: React.lazy(async () => {+ const mod = await import("@/registry/example/lens-demo-3.tsx");+ const exportName =+ Object.keys(mod).find(+ (key) =>+ typeof mod[key] === "function" || typeof mod[key] === "object",+ ) || item.name;+ return { default: mod.default || mod[exportName] };+ }),+ meta: undefined,+ },"neon-gradient-card-demo": {name: "neon-gradient-card-demo",description: "Example showing a beautiful neon card effect.",diff --git a/config/docs.ts b/config/docs.tsindex 0fc9dbb9..810299af 100644--- a/config/docs.ts+++ b/config/docs.ts@@ -303,6 +303,12 @@ export const docsConfig: DocsConfig = {items: [],label: "New",},+ {+ title: "Lens",+ href: `/docs/components/lens`,+ items: [],+ label: "New",+ },],},{diff --git a/content/docs/components/lens.mdx b/content/docs/components/lens.mdxnew file mode 100644index 00000000..8d88c94a--- /dev/null+++ b/content/docs/components/lens.mdx@@ -0,0 +1,65 @@+---+title: Lens+date: 2025-01-13+description: A interactive component that enables zooming into images, videos and other elements.+author: h3rmel+published: true+---++<ComponentPreview name="lens-demo" />++## Installation++<Tabs defaultValue="cli">++<TabsList>+ <TabsTrigger value="cli">CLI</TabsTrigger>+ <TabsTrigger value="manual">Manual</TabsTrigger>+</TabsList>+<TabsContent value="cli">++```bash+npx shadcn@latest add "https://magicui.design/r/lens"+```++</TabsContent>++<TabsContent value="manual">++<Steps>++<Step>Copy and paste the following code into your project.</Step>++<ComponentSource name="lens" />++<Step>Update the import paths to match your project setup.</Step>++</Steps>++</TabsContent>++</Tabs>++## Examples++### Static Lens++<ComponentPreview name="lens-demo-2" />++### Lens with a Default Position++<ComponentPreview name="lens-demo-3" />++## Props++| Property | Type | Default | Description |+| ----------------- | ----------------- | ------- | ---------------------------------------------------------- |+| `children` | `React.ReactNode` | - | The content that will be magnified by the lens |+| `zoomFactor` | `number` | 1.3 | The magnification factor of the lens |+| `lensSize` | `number` | 170 | The size of the lens in pixels (works as a diameter) |+| `position` | `Position` | - | The current position of the lens |+| `defaultPosition` | `Position` | - | The initial position of the lens |+| `isStatic` | `boolean` | false | Determines if the lens will remain in a fixed position |+| `duration` | `number` | 0.1 | Duration of the animation when the lens moves (in seconds) |+| `lensColor` | `string` | - | The color of the lens (CSS color value) |+| `ariaLabel` | `string` | - | Accessibility label for the lens component |diff --git a/public/r/lens-demo-2.json b/public/r/lens-demo-2.jsonnew file mode 100644index 00000000..ff6fd48a--- /dev/null+++ b/public/r/lens-demo-2.json@@ -0,0 +1,26 @@+{+ "$schema": "https://ui.shadcn.com/schema/registry-item.json",+ "name": "lens-demo-2",+ "type": "registry:example",+ "title": "Lens Demo 2",+ "description": "Second example showing a lens effect component",+ "registryDependencies": [+ "button",+ "card",+ "https://magicui.design/r/lens"+ ],+ "files": [+ {+ "path": "registry/example/lens-demo-2.tsx",+ "content": "/* eslint-disable @next/next/no-img-element */\n\nimport { Button } from \"@/components/ui/button\";\nimport {\n Card,\n CardContent,\n CardDescription,\n CardFooter,\n CardHeader,\n CardTitle,\n} from \"@/components/ui/card\";\nimport { Lens } from \"@/components/magicui/lens\";\n\nexport default function LensDemo() {\n return (\n <Card className=\"relative max-w-md shadow-none\">\n <CardHeader>\n <Lens isStatic position={{ x: 260, y: 150 }}>\n <img\n src=\"https://images.unsplash.com/photo-1736606355698-5efdb410fe93?q=80&w=2071&auto=format&fit=crop&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D\"\n alt=\"image placeholder\"\n width={500}\n height={500}\n />\n </Lens>\n </CardHeader>\n <CardContent>\n <CardTitle className=\"text-2xl\">Your next camp</CardTitle>\n <CardDescription>\n See our latest and best camp destinations all across the five\n continents of the globe.\n </CardDescription>\n </CardContent>\n <CardFooter className=\"space-x-4\">\n <Button>Let's go</Button>\n <Button variant=\"secondary\">Another time</Button>\n </CardFooter>\n </Card>\n );\n}\n",+ "type": "registry:example",+ "target": "components/lens-demo-2.tsx"+ },+ {+ "path": "registry/magicui/lens.tsx",+ "content": "\"use client\";\n\nimport { AnimatePresence, motion, useMotionTemplate } from \"motion/react\";\nimport React, { useCallback, useMemo, useRef, useState } from \"react\";\n\ninterface Position {\n /** The x coordinate of the lens */\n x: number;\n /** The y coordinate of the lens */\n y: number;\n}\n\ninterface LensProps {\n /** The children of the lens */\n children: React.ReactNode;\n /** The zoom factor of the lens */\n zoomFactor?: number;\n /** The size of the lens */\n lensSize?: number;\n /** The position of the lens */\n position?: Position;\n /** The default position of the lens */\n defaultPosition?: Position;\n /** Whether the lens is static */\n isStatic?: boolean;\n /** The duration of the animation */\n duration?: number;\n /** The color of the lens */\n lensColor?: string;\n /** The aria label of the lens */\n ariaLabel?: string;\n}\n\nexport function Lens({\n children,\n zoomFactor = 1.3,\n lensSize = 170,\n isStatic = false,\n position = { x: 0, y: 0 },\n defaultPosition,\n duration = 0.1,\n lensColor = \"black\",\n ariaLabel = \"Zoom Area\",\n}: LensProps) {\n if (zoomFactor < 1) {\n throw new Error(\"zoomFactor must be greater than 1\");\n }\n if (lensSize < 0) {\n throw new Error(\"lensSize must be greater than 0\");\n }\n\n const [isHovering, setIsHovering] = useState(false);\n const [mousePosition, setMousePosition] = useState<Position>(position);\n const containerRef = useRef<HTMLDivElement>(null);\n\n const currentPosition = useMemo(() => {\n if (isStatic) return position;\n if (defaultPosition && !isHovering) return defaultPosition;\n return mousePosition;\n }, [isStatic, position, defaultPosition, isHovering, mousePosition]);\n\n const handleMouseMove = useCallback((e: React.MouseEvent<HTMLDivElement>) => {\n const rect = e.currentTarget.getBoundingClientRect();\n setMousePosition({\n x: e.clientX - rect.left,\n y: e.clientY - rect.top,\n });\n }, []);\n\n const handleKeyDown = useCallback((e: React.KeyboardEvent) => {\n if (e.key === \"Escape\") setIsHovering(false);\n }, []);\n\n const maskImage = useMotionTemplate`radial-gradient(circle ${lensSize / 2}px at ${currentPosition.x}px ${currentPosition.y}px, ${lensColor} 100%, transparent 100%)`;\n\n const LensContent = useMemo(() => {\n const { x, y } = currentPosition;\n\n return (\n <motion.div\n initial={{ opacity: 0, scale: 0.58 }}\n animate={{ opacity: 1, scale: 1 }}\n exit={{ opacity: 0, scale: 0.8 }}\n transition={{ duration }}\n className=\"absolute inset-0 overflow-hidden\"\n style={{\n maskImage,\n WebkitMaskImage: maskImage,\n transformOrigin: `${x}px ${y}px`,\n zIndex: 50,\n }}\n >\n <div\n className=\"absolute inset-0\"\n style={{\n transform: `scale(${zoomFactor})`,\n transformOrigin: `${x}px ${y}px`,\n }}\n >\n {children}\n </div>\n </motion.div>\n );\n }, [currentPosition, lensSize, lensColor, zoomFactor, children, duration]);\n\n return (\n <div\n ref={containerRef}\n className=\"relative z-20 overflow-hidden rounded-xl\"\n onMouseEnter={() => setIsHovering(true)}\n onMouseLeave={() => setIsHovering(false)}\n onMouseMove={handleMouseMove}\n onKeyDown={handleKeyDown}\n role=\"region\"\n aria-label={ariaLabel}\n tabIndex={0}\n >\n {children}\n {isStatic || defaultPosition ? (\n LensContent\n ) : (\n <AnimatePresence mode=\"popLayout\">\n {isHovering && LensContent}\n </AnimatePresence>\n )}\n </div>\n );\n}\n",+ "type": "registry:ui",+ "target": "components/magicui/lens.tsx"+ }+ ]+}\ No newline at end of filediff --git a/public/r/lens-demo-3.json b/public/r/lens-demo-3.jsonnew file mode 100644index 00000000..bfda1051--- /dev/null+++ b/public/r/lens-demo-3.json@@ -0,0 +1,20 @@+{+ "$schema": "https://ui.shadcn.com/schema/registry-item.json",+ "name": "lens-demo-3",+ "type": "registry:example",+ "title": "Lens Demo 3",+ "description": "Third example showing a lens effect component",+ "registryDependencies": [+ "button",+ "card",+ "https://magicui.design/r/lens"+ ],+ "files": [+ {+ "path": "registry/example/lens-demo-3.tsx",+ "content": "/* eslint-disable @next/next/no-img-element */\n\nimport { Button } from \"@/components/ui/button\";\nimport {\n Card,\n CardContent,\n CardDescription,\n CardFooter,\n CardHeader,\n CardTitle,\n} from \"@/components/ui/card\";\nimport { Lens } from \"@/components/magicui/lens\";\n\nexport default function LensDemo() {\n return (\n <Card className=\"relative max-w-md shadow-none\">\n <CardHeader>\n <Lens defaultPosition={{ x: 260, y: 150 }}>\n <img\n src=\"https://images.unsplash.com/photo-1736606355698-5efdb410fe93?q=80&w=2071&auto=format&fit=crop&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D\"\n alt=\"image placeholder\"\n width={500}\n height={500}\n />\n </Lens>\n </CardHeader>\n <CardContent>\n <CardTitle className=\"text-2xl\">Your next camp</CardTitle>\n <CardDescription>\n See our latest and best camp destinations all across the five\n continents of the globe.\n </CardDescription>\n </CardContent>\n <CardFooter className=\"space-x-4\">\n <Button>Let's go</Button>\n <Button variant=\"secondary\">Another time</Button>\n </CardFooter>\n </Card>\n );\n}\n",+ "type": "registry:example",+ "target": "components/lens-demo-3.tsx"+ }+ ]+}\ No newline at end of filediff --git a/public/r/lens-demo.json b/public/r/lens-demo.jsonnew file mode 100644index 00000000..a0a62169--- /dev/null+++ b/public/r/lens-demo.json@@ -0,0 +1,26 @@+{+ "$schema": "https://ui.shadcn.com/schema/registry-item.json",+ "name": "lens-demo",+ "type": "registry:example",+ "title": "Lens Demo",+ "description": "Example showing a lens effect component",+ "registryDependencies": [+ "button",+ "card",+ "https://magicui.design/r/lens"+ ],+ "files": [+ {+ "path": "registry/example/lens-demo.tsx",+ "content": "/* eslint-disable @next/next/no-img-element */\n\n\"use client\";\nimport { Button } from \"@/components/ui/button\";\nimport {\n Card,\n CardContent,\n CardDescription,\n CardFooter,\n CardHeader,\n CardTitle,\n} from \"@/components/ui/card\";\nimport { Lens } from \"@/components/magicui/lens\";\n\nexport default function LensDemo() {\n return (\n <Card className=\"relative max-w-md shadow-none\">\n <CardHeader>\n <Lens\n zoomFactor={2}\n lensSize={150}\n isStatic={false}\n ariaLabel=\"Zoom Area\"\n >\n <img\n src=\"https://images.unsplash.com/photo-1736606355698-5efdb410fe93?q=80&w=2071&auto=format&fit=crop&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D\"\n alt=\"image placeholder\"\n width={500}\n height={500}\n />\n </Lens>\n </CardHeader>\n <CardContent>\n <CardTitle className=\"text-2xl\">Your next camp</CardTitle>\n <CardDescription>\n See our latest and best camp destinations all across the five\n continents of the globe.\n </CardDescription>\n </CardContent>\n <CardFooter className=\"space-x-4\">\n <Button>Let's go</Button>\n <Button variant=\"secondary\">Another time</Button>\n </CardFooter>\n </Card>\n );\n}\n",+ "type": "registry:example",+ "target": "components/lens-demo.tsx"+ },+ {+ "path": "registry/magicui/lens.tsx",+ "content": "\"use client\";\n\nimport { AnimatePresence, motion, useMotionTemplate } from \"motion/react\";\nimport React, { useCallback, useMemo, useRef, useState } from \"react\";\n\ninterface Position {\n /** The x coordinate of the lens */\n x: number;\n /** The y coordinate of the lens */\n y: number;\n}\n\ninterface LensProps {\n /** The children of the lens */\n children: React.ReactNode;\n /** The zoom factor of the lens */\n zoomFactor?: number;\n /** The size of the lens */\n lensSize?: number;\n /** The position of the lens */\n position?: Position;\n /** The default position of the lens */\n defaultPosition?: Position;\n /** Whether the lens is static */\n isStatic?: boolean;\n /** The duration of the animation */\n duration?: number;\n /** The color of the lens */\n lensColor?: string;\n /** The aria label of the lens */\n ariaLabel?: string;\n}\n\nexport function Lens({\n children,\n zoomFactor = 1.3,\n lensSize = 170,\n isStatic = false,\n position = { x: 0, y: 0 },\n defaultPosition,\n duration = 0.1,\n lensColor = \"black\",\n ariaLabel = \"Zoom Area\",\n}: LensProps) {\n if (zoomFactor < 1) {\n throw new Error(\"zoomFactor must be greater than 1\");\n }\n if (lensSize < 0) {\n throw new Error(\"lensSize must be greater than 0\");\n }\n\n const [isHovering, setIsHovering] = useState(false);\n const [mousePosition, setMousePosition] = useState<Position>(position);\n const containerRef = useRef<HTMLDivElement>(null);\n\n const currentPosition = useMemo(() => {\n if (isStatic) return position;\n if (defaultPosition && !isHovering) return defaultPosition;\n return mousePosition;\n }, [isStatic, position, defaultPosition, isHovering, mousePosition]);\n\n const handleMouseMove = useCallback((e: React.MouseEvent<HTMLDivElement>) => {\n const rect = e.currentTarget.getBoundingClientRect();\n setMousePosition({\n x: e.clientX - rect.left,\n y: e.clientY - rect.top,\n });\n }, []);\n\n const handleKeyDown = useCallback((e: React.KeyboardEvent) => {\n if (e.key === \"Escape\") setIsHovering(false);\n }, []);\n\n const maskImage = useMotionTemplate`radial-gradient(circle ${lensSize / 2}px at ${currentPosition.x}px ${currentPosition.y}px, ${lensColor} 100%, transparent 100%)`;\n\n const LensContent = useMemo(() => {\n const { x, y } = currentPosition;\n\n return (\n <motion.div\n initial={{ opacity: 0, scale: 0.58 }}\n animate={{ opacity: 1, scale: 1 }}\n exit={{ opacity: 0, scale: 0.8 }}\n transition={{ duration }}\n className=\"absolute inset-0 overflow-hidden\"\n style={{\n maskImage,\n WebkitMaskImage: maskImage,\n transformOrigin: `${x}px ${y}px`,\n zIndex: 50,\n }}\n >\n <div\n className=\"absolute inset-0\"\n style={{\n transform: `scale(${zoomFactor})`,\n transformOrigin: `${x}px ${y}px`,\n }}\n >\n {children}\n </div>\n </motion.div>\n );\n }, [currentPosition, lensSize, lensColor, zoomFactor, children, duration]);\n\n return (\n <div\n ref={containerRef}\n className=\"relative z-20 overflow-hidden rounded-xl\"\n onMouseEnter={() => setIsHovering(true)}\n onMouseLeave={() => setIsHovering(false)}\n onMouseMove={handleMouseMove}\n onKeyDown={handleKeyDown}\n role=\"region\"\n aria-label={ariaLabel}\n tabIndex={0}\n >\n {children}\n {isStatic || defaultPosition ? (\n LensContent\n ) : (\n <AnimatePresence mode=\"popLayout\">\n {isHovering && LensContent}\n </AnimatePresence>\n )}\n </div>\n );\n}\n",+ "type": "registry:ui",+ "target": "components/magicui/lens.tsx"+ }+ ]+}\ No newline at end of filediff --git a/public/r/lens.json b/public/r/lens.jsonnew file mode 100644index 00000000..2edb77d3--- /dev/null+++ b/public/r/lens.json@@ -0,0 +1,18 @@+{+ "$schema": "https://ui.shadcn.com/schema/registry-item.json",+ "name": "lens",+ "type": "registry:ui",+ "title": "Lens",+ "description": "A interactive component that enables zooming into images, videos and other elements.",+ "dependencies": [+ "motion"+ ],+ "files": [+ {+ "path": "registry/magicui/lens.tsx",+ "content": "\"use client\";\n\nimport { AnimatePresence, motion, useMotionTemplate } from \"motion/react\";\nimport React, { useCallback, useMemo, useRef, useState } from \"react\";\n\ninterface Position {\n /** The x coordinate of the lens */\n x: number;\n /** The y coordinate of the lens */\n y: number;\n}\n\ninterface LensProps {\n /** The children of the lens */\n children: React.ReactNode;\n /** The zoom factor of the lens */\n zoomFactor?: number;\n /** The size of the lens */\n lensSize?: number;\n /** The position of the lens */\n position?: Position;\n /** The default position of the lens */\n defaultPosition?: Position;\n /** Whether the lens is static */\n isStatic?: boolean;\n /** The duration of the animation */\n duration?: number;\n /** The color of the lens */\n lensColor?: string;\n /** The aria label of the lens */\n ariaLabel?: string;\n}\n\nexport function Lens({\n children,\n zoomFactor = 1.3,\n lensSize = 170,\n isStatic = false,\n position = { x: 0, y: 0 },\n defaultPosition,\n duration = 0.1,\n lensColor = \"black\",\n ariaLabel = \"Zoom Area\",\n}: LensProps) {\n if (zoomFactor < 1) {\n throw new Error(\"zoomFactor must be greater than 1\");\n }\n if (lensSize < 0) {\n throw new Error(\"lensSize must be greater than 0\");\n }\n\n const [isHovering, setIsHovering] = useState(false);\n const [mousePosition, setMousePosition] = useState<Position>(position);\n const containerRef = useRef<HTMLDivElement>(null);\n\n const currentPosition = useMemo(() => {\n if (isStatic) return position;\n if (defaultPosition && !isHovering) return defaultPosition;\n return mousePosition;\n }, [isStatic, position, defaultPosition, isHovering, mousePosition]);\n\n const handleMouseMove = useCallback((e: React.MouseEvent<HTMLDivElement>) => {\n const rect = e.currentTarget.getBoundingClientRect();\n setMousePosition({\n x: e.clientX - rect.left,\n y: e.clientY - rect.top,\n });\n }, []);\n\n const handleKeyDown = useCallback((e: React.KeyboardEvent) => {\n if (e.key === \"Escape\") setIsHovering(false);\n }, []);\n\n const maskImage = useMotionTemplate`radial-gradient(circle ${lensSize / 2}px at ${currentPosition.x}px ${currentPosition.y}px, ${lensColor} 100%, transparent 100%)`;\n\n const LensContent = useMemo(() => {\n const { x, y } = currentPosition;\n\n return (\n <motion.div\n initial={{ opacity: 0, scale: 0.58 }}\n animate={{ opacity: 1, scale: 1 }}\n exit={{ opacity: 0, scale: 0.8 }}\n transition={{ duration }}\n className=\"absolute inset-0 overflow-hidden\"\n style={{\n maskImage,\n WebkitMaskImage: maskImage,\n transformOrigin: `${x}px ${y}px`,\n zIndex: 50,\n }}\n >\n <div\n className=\"absolute inset-0\"\n style={{\n transform: `scale(${zoomFactor})`,\n transformOrigin: `${x}px ${y}px`,\n }}\n >\n {children}\n </div>\n </motion.div>\n );\n }, [currentPosition, lensSize, lensColor, zoomFactor, children, duration]);\n\n return (\n <div\n ref={containerRef}\n className=\"relative z-20 overflow-hidden rounded-xl\"\n onMouseEnter={() => setIsHovering(true)}\n onMouseLeave={() => setIsHovering(false)}\n onMouseMove={handleMouseMove}\n onKeyDown={handleKeyDown}\n role=\"region\"\n aria-label={ariaLabel}\n tabIndex={0}\n >\n {children}\n {isStatic || defaultPosition ? (\n LensContent\n ) : (\n <AnimatePresence mode=\"popLayout\">\n {isHovering && LensContent}\n </AnimatePresence>\n )}\n </div>\n );\n}\n",+ "type": "registry:ui",+ "target": "components/magicui/lens.tsx"+ }+ ]+}\ No newline at end of filediff --git a/registry.json b/registry.jsonindex 4e25a706..356c2864 100644--- a/registry.json+++ b/registry.json@@ -232,6 +232,22 @@}]},+ {+ "name": "lens",+ "type": "registry:ui",+ "title": "Lens",+ "description": "A interactive component that enables zooming into images, videos and other elements.",+ "dependencies": [+ "motion"+ ],+ "files": [+ {+ "path": "registry/magicui/lens.tsx",+ "type": "registry:ui",+ "target": "components/magicui/lens.tsx"+ }+ ]+ },{"name": "neon-gradient-card","type": "registry:ui",@@ -1554,6 +1570,70 @@}]},+ {+ "name": "lens-demo",+ "type": "registry:example",+ "title": "Lens Demo",+ "description": "Example showing a lens effect component",+ "registryDependencies": [+ "button",+ "card",+ "https://magicui.design/r/lens"+ ],+ "files": [+ {+ "path": "registry/example/lens-demo.tsx",+ "type": "registry:example",+ "target": "components/lens-demo.tsx"+ },+ {+ "path": "registry/magicui/lens.tsx",+ "type": "registry:ui",+ "target": "components/magicui/lens.tsx"+ }+ ]+ },+ {+ "name": "lens-demo-2",+ "type": "registry:example",+ "title": "Lens Demo 2",+ "description": "Second example showing a lens effect component",+ "registryDependencies": [+ "button",+ "card",+ "https://magicui.design/r/lens"+ ],+ "files": [+ {+ "path": "registry/example/lens-demo-2.tsx",+ "type": "registry:example",+ "target": "components/lens-demo-2.tsx"+ },+ {+ "path": "registry/magicui/lens.tsx",+ "type": "registry:ui",+ "target": "components/magicui/lens.tsx"+ }+ ]+ },+ {+ "name": "lens-demo-3",+ "type": "registry:example",+ "title": "Lens Demo 3",+ "description": "Third example showing a lens effect component",+ "registryDependencies": [+ "button",+ "card",+ "https://magicui.design/r/lens"+ ],+ "files": [+ {+ "path": "registry/example/lens-demo-3.tsx",+ "type": "registry:example",+ "target": "components/lens-demo-3.tsx"+ }+ ]+ },{"name": "neon-gradient-card-demo","type": "registry:example",diff --git a/registry/example/lens-demo-2.tsx b/registry/example/lens-demo-2.tsxnew file mode 100644index 00000000..cf7ef94c--- /dev/null+++ b/registry/example/lens-demo-2.tsx@@ -0,0 +1,40 @@+/* eslint-disable @next/next/no-img-element */++import { Button } from "@/components/ui/button";+import {+ Card,+ CardContent,+ CardDescription,+ CardFooter,+ CardHeader,+ CardTitle,+} from "@/components/ui/card";+import { Lens } from "@/registry/magicui/lens";++export default function LensDemo() {+ return (+ <Card className="relative max-w-md shadow-none">+ <CardHeader>+ <Lens isStatic position={{ x: 260, y: 150 }}>+ <img+ src="https://images.unsplash.com/photo-1736606355698-5efdb410fe93?q=80&w=2071&auto=format&fit=crop&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D"+ alt="image placeholder"+ width={500}+ height={500}+ />+ </Lens>+ </CardHeader>+ <CardContent>+ <CardTitle className="text-2xl">Your next camp</CardTitle>+ <CardDescription>+ See our latest and best camp destinations all across the five+ continents of the globe.+ </CardDescription>+ </CardContent>+ <CardFooter className="space-x-4">+ <Button>Let's go</Button>+ <Button variant="secondary">Another time</Button>+ </CardFooter>+ </Card>+ );+}diff --git a/registry/example/lens-demo-3.tsx b/registry/example/lens-demo-3.tsxnew file mode 100644index 00000000..207e5449--- /dev/null+++ b/registry/example/lens-demo-3.tsx@@ -0,0 +1,40 @@+/* eslint-disable @next/next/no-img-element */++import { Button } from "@/components/ui/button";+import {+ Card,+ CardContent,+ CardDescription,+ CardFooter,+ CardHeader,+ CardTitle,+} from "@/components/ui/card";+import { Lens } from "@/registry/magicui/lens";++export default function LensDemo() {+ return (+ <Card className="relative max-w-md shadow-none">+ <CardHeader>+ <Lens defaultPosition={{ x: 260, y: 150 }}>+ <img+ src="https://images.unsplash.com/photo-1736606355698-5efdb410fe93?q=80&w=2071&auto=format&fit=crop&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D"+ alt="image placeholder"+ width={500}+ height={500}+ />+ </Lens>+ </CardHeader>+ <CardContent>+ <CardTitle className="text-2xl">Your next camp</CardTitle>+ <CardDescription>+ See our latest and best camp destinations all across the five+ continents of the globe.+ </CardDescription>+ </CardContent>+ <CardFooter className="space-x-4">+ <Button>Let's go</Button>+ <Button variant="secondary">Another time</Button>+ </CardFooter>+ </Card>+ );+}diff --git a/registry/example/lens-demo.tsx b/registry/example/lens-demo.tsxnew file mode 100644index 00000000..2c1ec5a7--- /dev/null+++ b/registry/example/lens-demo.tsx@@ -0,0 +1,46 @@+/* eslint-disable @next/next/no-img-element */++"use client";+import { Button } from "@/components/ui/button";+import {+ Card,+ CardContent,+ CardDescription,+ CardFooter,+ CardHeader,+ CardTitle,+} from "@/components/ui/card";+import { Lens } from "@/registry/magicui/lens";++export default function LensDemo() {+ return (+ <Card className="relative max-w-md shadow-none">+ <CardHeader>+ <Lens+ zoomFactor={2}+ lensSize={150}+ isStatic={false}+ ariaLabel="Zoom Area"+ >+ <img+ src="https://images.unsplash.com/photo-1736606355698-5efdb410fe93?q=80&w=2071&auto=format&fit=crop&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D"+ alt="image placeholder"+ width={500}+ height={500}+ />+ </Lens>+ </CardHeader>+ <CardContent>+ <CardTitle className="text-2xl">Your next camp</CardTitle>+ <CardDescription>+ See our latest and best camp destinations all across the five+ continents of the globe.+ </CardDescription>+ </CardContent>+ <CardFooter className="space-x-4">+ <Button>Let's go</Button>+ <Button variant="secondary">Another time</Button>+ </CardFooter>+ </Card>+ );+}diff --git a/registry/magicui/lens.tsx b/registry/magicui/lens.tsxnew file mode 100644index 00000000..4cc2e3f7--- /dev/null+++ b/registry/magicui/lens.tsx@@ -0,0 +1,128 @@+"use client";++import { AnimatePresence, motion, useMotionTemplate } from "motion/react";+import React, { useCallback, useMemo, useRef, useState } from "react";++interface Position {+ /** The x coordinate of the lens */+ x: number;+ /** The y coordinate of the lens */+ y: number;+}++interface LensProps {+ /** The children of the lens */+ children: React.ReactNode;+ /** The zoom factor of the lens */+ zoomFactor?: number;+ /** The size of the lens */+ lensSize?: number;+ /** The position of the lens */+ position?: Position;+ /** The default position of the lens */+ defaultPosition?: Position;+ /** Whether the lens is static */+ isStatic?: boolean;+ /** The duration of the animation */+ duration?: number;+ /** The color of the lens */+ lensColor?: string;+ /** The aria label of the lens */+ ariaLabel?: string;+}++export function Lens({+ children,+ zoomFactor = 1.3,+ lensSize = 170,+ isStatic = false,+ position = { x: 0, y: 0 },+ defaultPosition,+ duration = 0.1,+ lensColor = "black",+ ariaLabel = "Zoom Area",+}: LensProps) {+ if (zoomFactor < 1) {+ throw new Error("zoomFactor must be greater than 1");+ }+ if (lensSize < 0) {+ throw new Error("lensSize must be greater than 0");+ }++ const [isHovering, setIsHovering] = useState(false);+ const [mousePosition, setMousePosition] = useState<Position>(position);+ const containerRef = useRef<HTMLDivElement>(null);++ const currentPosition = useMemo(() => {+ if (isStatic) return position;+ if (defaultPosition && !isHovering) return defaultPosition;+ return mousePosition;+ }, [isStatic, position, defaultPosition, isHovering, mousePosition]);++ const handleMouseMove = useCallback((e: React.MouseEvent<HTMLDivElement>) => {+ const rect = e.currentTarget.getBoundingClientRect();+ setMousePosition({+ x: e.clientX - rect.left,+ y: e.clientY - rect.top,+ });+ }, []);++ const handleKeyDown = useCallback((e: React.KeyboardEvent) => {+ if (e.key === "Escape") setIsHovering(false);+ }, []);++ const maskImage = useMotionTemplate`radial-gradient(circle ${lensSize / 2}px at ${currentPosition.x}px ${currentPosition.y}px, ${lensColor} 100%, transparent 100%)`;++ const LensContent = useMemo(() => {+ const { x, y } = currentPosition;++ return (+ <motion.div+ initial={{ opacity: 0, scale: 0.58 }}+ animate={{ opacity: 1, scale: 1 }}+ exit={{ opacity: 0, scale: 0.8 }}+ transition={{ duration }}+ className="absolute inset-0 overflow-hidden"+ style={{+ maskImage,+ WebkitMaskImage: maskImage,+ transformOrigin: `${x}px ${y}px`,+ zIndex: 50,+ }}+ >+ <div+ className="absolute inset-0"+ style={{+ transform: `scale(${zoomFactor})`,+ transformOrigin: `${x}px ${y}px`,+ }}+ >+ {children}+ </div>+ </motion.div>+ );+ }, [currentPosition, lensSize, lensColor, zoomFactor, children, duration]);++ return (+ <div+ ref={containerRef}+ className="relative z-20 overflow-hidden rounded-xl"+ onMouseEnter={() => setIsHovering(true)}+ onMouseLeave={() => setIsHovering(false)}+ onMouseMove={handleMouseMove}+ onKeyDown={handleKeyDown}+ role="region"+ aria-label={ariaLabel}+ tabIndex={0}+ >+ {children}+ {isStatic || defaultPosition ? (+ LensContent+ ) : (+ <AnimatePresence mode="popLayout">+ {isHovering && LensContent}+ </AnimatePresence>+ )}+ </div>+ );+}diff --git a/registry/registry-examples.ts b/registry/registry-examples.tsindex 2431d518..904fef72 100644--- a/registry/registry-examples.ts+++ b/registry/registry-examples.ts@@ -174,6 +174,58 @@ export const examples: Registry["items"] = [},],},+ {+ name: "lens-demo",+ type: "registry:example",+ title: "Lens Demo",+ description: "Example showing a lens effect component",+ registryDependencies: ["button", "card", "https://magicui.design/r/lens"],+ files: [+ {+ path: "registry/example/lens-demo.tsx",+ type: "registry:example",+ target: "components/lens-demo.tsx",+ },+ {+ path: "registry/magicui/lens.tsx",+ type: "registry:ui",+ target: "components/magicui/lens.tsx",+ },+ ],+ },+ {+ name: "lens-demo-2",+ type: "registry:example",+ title: "Lens Demo 2",+ description: "Second example showing a lens effect component",+ registryDependencies: ["button", "card", "https://magicui.design/r/lens"],+ files: [+ {+ path: "registry/example/lens-demo-2.tsx",+ type: "registry:example",+ target: "components/lens-demo-2.tsx",+ },+ {+ path: "registry/magicui/lens.tsx",+ type: "registry:ui",+ target: "components/magicui/lens.tsx",+ },+ ],+ },+ {+ name: "lens-demo-3",+ type: "registry:example",+ title: "Lens Demo 3",+ description: "Third example showing a lens effect component",+ registryDependencies: ["button", "card", "https://magicui.design/r/lens"],+ files: [+ {+ path: "registry/example/lens-demo-3.tsx",+ type: "registry:example",+ target: "components/lens-demo-3.tsx",+ },+ ],+ },{name: "neon-gradient-card-demo",type: "registry:example",diff --git a/registry/registry-ui.ts b/registry/registry-ui.tsindex f5822e07..9d2c6592 100644--- a/registry/registry-ui.ts+++ b/registry/registry-ui.ts@@ -159,6 +159,21 @@ export const ui: Registry["items"] = [},],},+ {+ name: "lens",+ type: "registry:ui",+ title: "Lens",+ description:+ "A interactive component that enables zooming into images, videos and other elements.",+ dependencies: ["motion"],+ files: [+ {+ path: "registry/magicui/lens.tsx",+ type: "registry:ui",+ target: "components/magicui/lens.tsx",+ },+ ],+ },{name: "neon-gradient-card",type: "registry:ui",