Workspace / effect / overlay

Glass Lens

A cursor-following glass lens that refracts your live HTML and zooms in on targets like a crystal ball.

Workspaceeffectoverlay

npx shadcn@latest add @pax-sh/glass-lens-reactlocal only

Tier: high. Reduced motion: flat magnification

GlassLens.tsx
"use client";

import { useEffect, useRef } from "react";
import { glassLensEffect } from "@pax-sh/effects";

export interface GlassLensProps {
  className?: string;
  reducedMotion?: boolean;
  tier?: "low" | "medium" | "high";
  children?: React.ReactNode;
}

export function GlassLens(props: GlassLensProps) {
  const rootRef = useRef<HTMLDivElement>(null);

  useEffect(() => {
    const target = rootRef.current;
    if (!target) return;
    const instance = glassLensEffect.mount(target, {
      className: props.className,
      reducedMotion: props.reducedMotion,
      tier: props.tier,
    });
    return () => instance.dispose();
  }, [props.className, props.reducedMotion, props.tier]);

  return (
    <div ref={rootRef} className={props.className} data-pax-effect="glass-lens">
      {props.children}
    </div>
  );
}