# Lens

- Page: https://jiguang132.com/resources/magic-ui/docs/lens
- Resource: Magic UI (https://jiguang132.com/resources/magic-ui.md)
- All guides: https://jiguang132.com/resources/magic-ui/docs.md

Install: `npx shadcn@latest add https://jiguang132.com/r/magic-ui/lens.json`

## Use case

Magnify an area of child content on hover or at a fixed position.

## Native props used by the examples

Extracted from all local examples for this entry, grouped by imported module and native owner, including other Magic components used by compound demos. This is not an exhaustive API or a universal host variant. Inspect spread object declarations and the source types/defaults below.

| Owning component prop | Explanation | Example source |
| --- | --- | --- |
| `Lens.zoomFactor` (lens) | Lens scale multiplier. | `examples/lens-demo.tsx` |
| `Lens.lensSize` (lens) | Lens diameter in pixels. | `examples/lens-demo.tsx` |
| `Lens.isStatic` (lens) | Use a fixed lens rather than tracking hover. | `examples/lens-demo.tsx`、`examples/lens-demo-2.tsx` |
| `Lens.ariaLabel` (lens) | Accessible name for the lens area. | `examples/lens-demo.tsx` |
| `Lens.children` (lens) | Native child content; keep the owning component's text/element constraints. | `examples/lens-demo.tsx`、`examples/lens-demo-2.tsx`、`examples/lens-demo-3.tsx` |
| `Lens.position` (lens) | Controlled local x/y lens coordinates. | `examples/lens-demo-2.tsx` |
| `Lens.defaultPosition` (lens) | Initial local x/y lens coordinates. | `examples/lens-demo-3.tsx` |

## Interaction and state checks

- Lens Demo — `lens-demo`
- Lens Demo 2 — `lens-demo-2`
- Lens Demo 3 — `lens-demo-3`

These names identify real example entries, not new component props or extra components. Check pointer/keyboard behavior, themes, small screens and failures for the selected example. Decorative effects must not invent disabled/error/submission states. Complete example installation includes the actual dependency closure.

## Business integration boundary

Coordinates are local to the lens area. Test keyboard access and ariaLabel; a visual lens is not a replacement for accessible source content.

## Host and motion setup

Initialize Tailwind CSS v4, semantic CSS variables and the dark variant; import the independent local Registry namespace. Reuse an existing next-themes Provider without substituting JGuang UI/Base UI/HeroUI APIs. Mount effects in view and unmount offscreen; provide static alternatives for unavailable Canvas/WebGL or failed remote media. Respect prefers-reduced-motion and verify timer/RAF/observer/listener cleanup: stopping CSS alone does not prove the engine stopped. Examples provide no backend, login, payment or real AI stream. This practical guide is bilingual; detailed upstream references and demo text retain their original language.


## Available examples

lens-demo, lens-demo-2, lens-demo-3

Demo state and mock data do not provide a backend service. Inspect the component props before wiring real data.




## Installation

<Tabs defaultValue="cli">

<TabsList>
  <TabsTrigger value="cli">CLI</TabsTrigger>
  <TabsTrigger value="manual">Manual</TabsTrigger>
</TabsList>
<TabsContent value="cli">

```bash
npx shadcn@latest add @magicui/lens
```

</TabsContent>

<TabsContent value="manual">

<Steps>

<Step>Copy and paste the following code into your project.</Step>



<Step>Update the import paths to match your project setup.</Step>

</Steps>

</TabsContent>

</Tabs>

## Examples

### Static Lens



### Lens with a Default Position



## Usage

```tsx showLineNumbers
import { Lens } from "@/components/ui/lens"
```

```tsx showLineNumbers
<Lens>
  <img src="/images/lens-demo.jpg" alt="Lens Demo" />
</Lens>
```

## 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                 |




## Complete example installation

The component command installs the component. Each example command also includes its actual imported components, native support UI, utilities and pinned dependencies. Helpers are not additional catalog components.

### Lens Demo

```bash
npx shadcn@latest add https://jiguang132.com/r/magic-ui/examples/lens/lens-demo.json
```

Default import: `@/components/magicui/examples/lens-demo`

Dependencies: `@radix-ui/react-slot@1.3.0`, `class-variance-authority@0.7.1`, `clsx@2.1.1`, `motion@12.42.2`, `tailwind-merge@3.6.0`

### Lens Demo 2

```bash
npx shadcn@latest add https://jiguang132.com/r/magic-ui/examples/lens/lens-demo-2.json
```

Default import: `@/components/magicui/examples/lens-demo-2`

Dependencies: `@radix-ui/react-slot@1.3.0`, `class-variance-authority@0.7.1`, `clsx@2.1.1`, `motion@12.42.2`, `tailwind-merge@3.6.0`

### Lens Demo 3

```bash
npx shadcn@latest add https://jiguang132.com/r/magic-ui/examples/lens/lens-demo-3.json
```

Default import: `@/components/magicui/examples/lens-demo-3`

Dependencies: `@radix-ui/react-slot@1.3.0`, `class-variance-authority@0.7.1`, `clsx@2.1.1`, `motion@12.42.2`, `tailwind-merge@3.6.0`

### Minimal usage and theme

```tsx
import Demo from '@/components/magicui/examples/lens-demo';
import { ThemeProvider } from 'next-themes';
export default function Example() {
  return <ThemeProvider attribute="class" defaultTheme="system" enableSystem><Demo /></ThemeProvider>;
}

```

Initialize Tailwind CSS v4, semantic color variables and the dark variant first. Reuse an existing next-themes provider rather than nesting another. Next Link examples require a Next.js environment; in static Vite projects adapt the demo links to your router without changing the native component API. Some media and tweets require network access. Examples do not supply authentication or backend services.


## Source-backed parameter reference

Implementation signatures and types are generated from the pinned local source. Optional props, native inherited types, union branches and never exclusions are preserved. A forwardRef implementation's ref is a React reference, not an additional business prop.


```ts
Lens({
  children,
  zoomFactor = 1.3,
  lensSize = 170,
  isStatic = false,
  position = { x: 0, y: 0 },
  defaultPosition,
  duration = 0.1,
  lensColor = "black",
  ariaLabel = "Zoom Area",
}: LensProps)
```



```ts
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
}
```


### Destructuring defaults in source

Only defaults written directly in parameter/props destructuring are listed. Conditional expressions, runtime theme and computed values require source inspection; this is not an exhaustive behavior-default list.


```ts
// Lens
zoomFactor = 1.3

// Lens
lensSize = 170

// Lens
isStatic = false

// Lens
position = { x: 0, y: 0 }

// Lens
duration = 0.1

// Lens
lensColor = "black"

// Lens
ariaLabel = "Zoom Area"
```


### Native and external types

External types remain defined by React or native dependencies, not manually expanded into guessed props. The installed version's TypeScript definitions are authoritative.


```ts
React.ReactNode
```

---

Index of all JGuang resources: https://jiguang132.com/llms.txt
