# 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.

- Kind: Component (Motion)
- Docs: https://ui.minidev.pro/docs/light-provider
- Source (registry JSON with the full file): https://ui.minidev.pro/r/light-provider.json
- License: MIT. One file, yours to edit after install.

## 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.

## Installation

### shadcn CLI (copies the source into your project)

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

Writes `components/ui/light-provider.tsx` and installs its npm dependencies. Older CLI versions: `npx shadcn@latest add https://ui.minidev.pro/r/light-provider.json`.

### npm package

```bash
npm i minidev-ui-kit
```

Add the tokens to your global stylesheet once:

```css
@import "tailwindcss";
@import "minidev-ui-kit/styles.css";
@source "../node_modules/minidev-ui-kit";
```

Next.js also needs `transpilePackages: ["minidev-ui-kit"]` in next.config.

## Import

After the shadcn install:

```tsx
import { LightProvider, MaterialSwitcher, useMaterial, MATERIALS } from "@/components/ui/light-provider"
```

From the npm package:

```tsx
import { LightProvider } from "minidev-ui-kit/ui/light-provider"
```

## Usage

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

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

## Props

| Prop | Type | Default | Required | Description |
| --- | --- | --- | --- | --- |
| `idle` | `boolean` | `true` | no | Drift when the pointer is idle or absent. |
| `children` | `React.ReactNode` | - | no | Rendered as-is. Without children the root provider renders nothing visible. |

## Examples

### Appearance setting

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

```tsx
<div className="flex w-full max-w-md items-center justify-between gap-4 rounded-xl border border-border bg-surface p-4">
  <div>
    <p className="text-sm font-medium text-fg">Material</p>
    <p className="text-xs text-fg-muted">How cards, menus and buttons are drawn.</p>
  </div>
  <MaterialSwitcher size="sm" />
</div>
```

### Swatches only

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

```tsx
<MaterialSwitcher labels={false} size="sm" />
```

### Your own control

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

```tsx
function PaperModeButton() {
  const { material, setMaterial } = useMaterial()
  const on = material === "paper"
  return (
    <Button variant="outline" onClick={() => setMaterial(on ? "hairline" : "paper")}>
      {on ? "Back to hairline" : "Reading mode: paper"}
    </Button>
  )
}
```

## Keyboard interactions

| Key | Action |
| --- | --- |
| `Tab` | On the MaterialSwitcher, moves focus to the selected material only (roving focus). |
| `ArrowRight` or `ArrowDown` | Selects and focuses the next material, wrapping at the end. |
| `ArrowLeft` or `ArrowUp` | Selects and focuses the previous material, wrapping at the start. |
| `Home` or `End` | Selects 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.

## FAQ

### 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.

## Rules for generating code

- Use semantic tokens only (bg, surface, sunken, border, fg, fg-muted, fg-subtle, ink, accent, success, warning, danger). Never raw hex or palette steps like blue-500.
- Shadows only from the set: shadow-xs, shadow-sm, shadow-raised, shadow-md, shadow-lg, shadow-overlay.
- Numbers use tabular-nums. Dark mode is the `dark` class on <html>; components never branch on theme.

## Related

- [Marquee](https://ui.minidev.pro/docs/marquee/md): An infinitely scrolling Tailwind strip that loops its children horizontally, duplicated for a gapless cycle, and stops when users prefer reduced motion.
- [Morph Panel](https://ui.minidev.pro/docs/morph-panel/md): A React button that morphs into the panel it opens on a spring, blurring the label out and the form in. Ships with a feedback form and closes on Escape.
- [Number Roll](https://ui.minidev.pro/docs/number-roll/md): An odometer style animated number where each digit rolls on a spring and only changed digits move. Supports Intl formatting, trend tint and reduced motion.
- [Split Flap](https://ui.minidev.pro/docs/split-flap/md): Split-flap display that flips each character through the alphabet like a departure board, with a column ripple, tones, sizes and reduced motion support.
- [Animated Feature Row](https://ui.minidev.pro/docs/animated-feature-row/md): A row of feature cards that slide up with a staggered delay when scrolled into view. Pass title and description pairs; reduced motion keeps them still.
- [Card Tilt](https://ui.minidev.pro/docs/card-tilt/md): A card that tilts in 3D toward the pointer on springs, with an accent glare that follows the cursor. It stays flat when reduced motion is preferred.

---

All 557 components: https://ui.minidev.pro/llms.txt (full text: https://ui.minidev.pro/llms-full.txt).
