Skip to content

Light Provider

A page wide light source that follows the pointer and drifts when idle, driving shadows via CSS variables, plus a hairline, glass, metal and paper switcher.

src/registry/ui/light-provider.tsx/r/light-provider.json

Installation

bash
npx shadcn@latest add @minidev/light-provider

MiniDev UI is in the shadcn registry directory, so the short form works with no setup. Older CLI versions can use the full URL: npx shadcn@latest add https://ui.minidev.pro/r/light-provider.json

Usage

tsx
import { LightProvider } from "@/components/ui/light-provider"

export function Example() {
  return (
    <LightProvider />
  )
}

Exports LightProvider MaterialSwitcher useMaterial MATERIALS

API reference

LightProvider props
PropTypeDefault
idleDrift when the pointer is idle or absent.booleantrue
childrenRendered as-is. Without children the root provider renders nothing visible.React.ReactNode-

When to use

Optional: without it shadows fall from a fixed light. Render it once near the root (it renders nothing and only touches document in an effect, so it is SSR safe). Pick a material with MaterialSwitcher or by setting data-material on <html> or any subtree.

Keyboard interactions

Keyboard interactions
KeyAction
TabOn the MaterialSwitcher, moves focus to the selected material only (roving focus).
ArrowRightorArrowDownSelects and focuses the next material, wrapping at the end.
ArrowLeftorArrowUpSelects and focuses the previous material, wrapping at the start.
HomeorEndSelects the first or last material.

Accessibility

  • MaterialSwitcher is a role="radiogroup" named "Material", with one role="radio" button per material and aria-checked on the selected one.
  • With labels={false} the swatch-only buttons keep an aria-label such as "Glass".
  • Under reduced motion (watched live) the light does not move, and switching material skips the circular view transition and the sliding pill.

Frequently asked questions

Where do I put LightProvider in a Next.js app?

Render <LightProvider /> once inside <body> in app/layout.tsx. It renders a hidden <span> and only touches document in an effect, so it is safe in server-rendered layouts. Without it, shadows fall from a fixed light.

How do I switch materials?

Render <MaterialSwitcher /> from the same file, or set data-material (hairline, glass, metal or paper) on <html> or any subtree. useMaterial() returns { material, setMaterial } for your own control.

Does the chosen material survive a reload?

setMaterial writes it to localStorage under the key material, but nothing in this file reads it back. Restore it by setting data-material on <html> from that key, for example in an inline script before first paint.

What if I render two providers?

Only the first one runs the light. A second one renders its children, or a small demo panel when it has none, and takes over if the first unmounts.

Examples

Appearance setting

MaterialSwitcher sets data-material on <html>, so every surface on the page changes at once.

Swatches only

labels={false} keeps the switcher small enough for a header; each swatch keeps an aria-label.

Your own control

useMaterial returns the current material and a setter, for a toggle that fits your product.

All Animated React components

Learn more