Lens

An interactive magnifier for images, videos, and other elements — follow the pointer, stay static, or start from a default spot.

Default

Hover the image to magnify under the cursor. zoomFactor={2} and lensSize={150}.

Loading…

Installation

CLI
npx @sonojs/ui@latest add lens
Also needs
npm i motion

Usage

lens.tsx
import { Lens } from "@/components/lens"

export function Example() {
  return (
    <Lens zoomFactor={2} lensSize={150}>
      <img src="/images/lens-demo.jpg" alt="Lens demo" />
    </Lens>
  )
}

Props

PropTypeDefaultDescription
childrenReact.ReactNode-Content magnified by the lens.
zoomFactornumber1.3Magnification scale (must be greater than 1).
lensSizenumber170Lens diameter in pixels.
position{ x: number; y: number }-Controlled lens position (required when static).
defaultPosition{ x: number; y: number }-Initial lens position before hover.
isStaticbooleanfalseKeep the lens fixed instead of following the pointer.
durationnumber0.1Enter/exit animation duration in seconds.
lensColorstring"black"Mask fill color used for the circular lens.
ariaLabelstring"Zoom Area"Accessible label for the lens region.
classNamestring-Classes on the root wrapper.