Skip to content

NewMCP server for your coding agent. Set it up ›

Nexus UI
Get Pro

Glass Lens, animated React component

  • Pro
  • Motion Effects
  • Spring

Glass Lens

A glass puck you drag over content. It magnifies the centre and splits colour toward the rim, built from three offset copies of the content instead of a shader. Also includes Zoom Lens: A magnifier that springs after your pointer and shows full detail, so tiny map labels become readable. Scroll or use the slider to zoom.

Zoom Lens

Props

PropTypeDefaultWhat it does
size150Lens diameter in px.
zoom1.45Magnification at the centre of the lens.
width520Width of the content surface in px.
height300Height of the content surface in px.
childrenField notes textContent under the glass. It is rendered four times (page plus three lens layers), so keep it static.
autoplayfalseDrifts across the content by itself until the user drags it.
ZoomLens.image—Zoom Lens: picture to magnify, as a URL or data URI. Defaults to a drawn map of an invented harbour district with tiny street names.
ZoomLens.darkImage—Zoom Lens: picture to use in dark mode. Defaults to a dark version of the demo map, or to image when you pass your own.
ZoomLens.aspectRatio1800 / 1100Zoom Lens: width divided by height of the picture.
ZoomLens.label"Map of the harbour district. Use the lens to read street names."Zoom Lens: accessible description of the picture.
ZoomLens.defaultZoom2.6Zoom Lens: starting magnification.
ZoomLens.minZoom1.5Zoom Lens: smallest magnification.
ZoomLens.maxZoom4Zoom Lens: largest magnification.
ZoomLens.lensSize164Zoom Lens: lens diameter in px.
ZoomLens.showControltrueZoom Lens: shows the zoom slider under the picture. The wheel and the plus and minus keys still work without it.
ZoomLens.autoplayfalseZoom Lens: the lens wanders over the picture until someone points at it or presses a key. Never runs under reduced motion.
ZoomLens.className—Zoom Lens: extra classes for the wrapper.

Add it to your project

  1. 1

    Set up your project once

    You need a Next.js project with Tailwind CSS and the @/ import alias. In its root folder, run this once. It creates components.json and the cn() helper in src/lib/utils.ts:

    npx shadcn@latest init -d

    Starting from nothing? The Quick Start walks through the whole thing.

  2. 2

    Connect the registry with your API key

    Glass Lens is a Pro item, so the CLI has to send your API key. Do this once per project:

    1. Create a key at nexus-ui.com/dashboard/api-key. Copy it straight away: it starts with nxs_ and is shown only once.
    2. In your project root, next to package.json, create a file named .env.local with this line, using your own key:
      NEXUS_API_KEY=nxs_your_key_here
    3. Open components.json and add this entry inside the outermost braces, next to "aliases". Leave {name} and ${NEXUS_API_KEY} exactly as written; the CLI fills them in:
      "registries": {
        "@nexus-labs": {
          "url": "https://www.nexus-ui.com/api/registry/{name}",
          "headers": {
            "Authorization": "Bearer ${NEXUS_API_KEY}"
          }
        }
      }

How Glass Lens works

A draggable glass puck. Three copies of the content sit inside it at slightly different magnifications, tinted red, green and blue, so colour fringes grow toward the rim the way chromatic aberration does in a real lens.

The source, the install command and the build prompt come with Pro.

Glass Lens questions

How do I install Glass Lens?

Run `npx shadcn@latest add @nexus-labs/glass-lens`. It adds both GlassLens and the ZoomLens variant and installs framer-motion. It is a Pro component, so it needs a Pro plan and an API key; key setup is on the CLI docs page (/docs/cli).

How do I put my own content under the GlassLens?

Pass it as `children`; it fills a surface of `width` by `height` (defaults 520 by 300). `size` sets the lens diameter (default 150) and `zoom` the centre magnification (default 1.45). Children render four times, so keep them static.

How is the color fringe made without a shader?

The lens holds three copies of your content: one at `zoom`, one slightly larger tinted red, one slightly smaller tinted blue, blended together. Their gap grows toward the rim, which looks like chromatic aberration. There is no canvas or WebGL.

How do I magnify my own image with ZoomLens?

Pass `image` (a URL or data URI), `darkImage` for dark mode, and `aspectRatio` as width divided by height. Zoom starts at `defaultZoom` (2.6) within `minZoom` 1.5 and `maxZoom` 4; the wheel, slider and +/- keys change it.

Can I use it from the keyboard or with reduced motion?

Both lenses are focusable and move with the arrow keys; ZoomLens also zooms with plus and minus. Under reduced motion, ZoomLens follows the pointer directly, fades instead of scaling in, and its `autoplay` never runs.