Ballmac UI home

Lens

A magnifying lens that follows the pointer over an image or any content, moves with the arrow keys when focused, hides on Escape and keeps the copy inside it out of the accessibility tree.

Installation

$ pnpm dlx shadcn@latest add @ballmac/lens

Usage

import { Lens } from "@/components/ballmac/lens"

The full example is in the Code tab above.

Examples

Magnifying text

Terms of the offer

The free trial lasts 14 days and ends automatically. No payment details are needed to start. You may cancel at any time from your account settings, and your data is kept for 30 days after cancellation so you can export it.

API reference

PropTypeDefault
children*

What to magnify: usually an image, but any visual content works.

React.ReactNode—
zoom

How much the lens enlarges what is under it.

number2.2
lensSize

Diameter of the lens in pixels.

number160
label

Accessible name; the keyboard instructions are added for you.

string—

Also accepts the standard attributes of its root element.

Accessibility

KeyAction
TabThe area is focusable; the lens appears centered
ArrowKeysMove the lens in steps; Escape hides it
Screen readersThe group is named and explains the keys; the copy is hidden

Use with AI

<Lens zoom lensSize label>{image or content}</Lens>. Works with any child. The magnified copy is inert and aria-hidden. Touch pointers are ignored so scrolling is never blocked. With the shadcn MCP server set up (guide), ask your agent:

Add the Ballmac UI Lens (@ballmac/lens) to this project with the shadcn MCP, then use it where it fits.

Use it for

  • Product photos and maps
  • Inspecting fine detail in diagrams or charts

Not for

  • Full-screen image viewing (use a dialog)

Registry JSON: https://ui.ballmac.com/r/lens.json

Credits

Free to use in personal and commercial projects.