Skip to main content
Clever Ops

Lens Lab

A playable thin-lens ray lab for React, drag the object along the axis and principal rays, image, and magnification re-solve live. ARIA slider semantics, Tailwind token ink.

Preview & code

Loading Lens Lab preview

Installation

pnpm dlx shadcn@latest add @cleverui/lens-lab

Requires the @cleverui registry in your components.json, a one-off, two-line setup.

Usage

tsx
import { LensLab } from '@/components/ui/lens-lab'
Exampletsx
import { LensLab } from '@/components/ui/lens-lab'

export default function LensLabDemo() {
  return (
    <div className="mx-auto w-full max-w-3xl px-4 py-10 sm:px-6 sm:py-14">
      <p className="mb-4 font-mono text-[11px] uppercase tracking-[0.2em] text-muted-foreground sm:text-xs">
        Spectacle · thin-lens equation
      </p>
      <h2 className="mb-6 text-2xl font-semibold tracking-tight text-balance sm:text-3xl">
        Drag the object. Watch the image re-solve.
      </h2>
      <LensLab
        focalLength={90}
        defaultDistance={240}
        caption="THIN LENS · F 90"
        ariaLabel="Thin lens ray lab"
      />
      <p className="mt-4 text-sm leading-relaxed text-muted-foreground">
        Three principal rays, live magnification, real and virtual regimes.
        Arrow keys step the object; Shift for coarse moves.
      </p>
    </div>
  )
}

API reference

LensLab accepts the following props.

PropTypeDefaultDescription
focalLengthnumber90lens focal length in px (clamped 60-140)
defaultDistancenumber240initial object distance from the lens in px
captionstring'THIN LENS · F 90'mono micro-label on the stage frame
ariaLabelstring'Thin lens lab'accessible name for the object slider

…plus everything from React.HTMLAttributes<HTMLDivElement>: className, event handlers, aria attributes and the rest pass straight through.

Frequently asked questions

How do I install the Lens Lab component?

Register the @cleverui registry in your components.json ("@cleverui": "https://cleverops.com.au/r/{name}.json"), then run `npx shadcn@latest add @cleverui/lens-lab`. The shadcn CLI copies the source into your project, you own the code from that point. You can also copy the source directly from this page.

What dependencies does Lens Lab require?

Lens Lab uses motion on top of React and Tailwind CSS. You don't need to install it manually, the shadcn CLI resolves and installs npm dependencies automatically when you add the component.

Can I theme Lens Lab to match my brand?

Yes. The component is styled entirely with Tailwind utilities over standard design tokens (primary, background, muted, border), so it inherits your existing shadcn/ui theme automatically. Change your CSS variables and the component follows, no source edits needed for palette, radius, or fonts.

Want this built for you?

CleverUI is built by the Clever Ops web team. If you'd rather ship a hand-coded, fast, custom website than assemble one, we build them for Australian businesses every week.

Explore web development services