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.
Installation
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
import { LightProvider } from "@/components/ui/light-provider"
export function Example() {
return (
<LightProvider />
)
}
Exports LightProvider MaterialSwitcher useMaterial MATERIALS
API reference
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
| Key | Action |
|---|---|
| Tab | On the MaterialSwitcher, moves focus to the selected material only (roving focus). |
| ArrowRightorArrowDown | Selects and focuses the next material, wrapping at the end. |
| ArrowLeftorArrowUp | Selects and focuses the previous material, wrapping at the start. |
| HomeorEnd | Selects the first or last material. |
Accessibility
MaterialSwitcheris arole="radiogroup"named "Material", with onerole="radio"button per material andaria-checkedon the selected one.- With
labels={false}the swatch-only buttons keep anaria-labelsuch 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.