# useGlass / GlassSurface

> Give any custom component — cards, navbars, floating docks, or modals — Vitrum's real-time WebGL2 refraction with `useGlass()` and `<GlassSurface>`.

```tsx
import { Compass, Layers, Search, Sparkles } from "lucide-react";
import { useState } from "react";

import { GlassSurface, useGlass } from "@vitrumui/react/surface";

function CustomHookCard() {
  const [active, setActive] = useState(false);
  const { ref, style, glassProps, isReady } = useGlass<HTMLButtonElement>({
    radius: 20,
    blur: 6,
    refraction: 1.15,
    interactive: true,
    elevation: "md",
  });

  return (
    <button
      ref={ref}
      type="button"
      onClick={() => setActive((v) => !v)}
      {...glassProps}
      style={style}
      className="flex w-full cursor-pointer items-center justify-between border border-white/50 bg-white/55 px-4 py-3 text-left text-neutral-900 backdrop-blur-md dark:border-white/20 dark:bg-black/45 dark:text-white data-[vt-tone=dark]:text-white data-[vt-tone=light]:text-neutral-900"
    >
      <span className="flex items-center gap-2.5">
        <Sparkles className="size-4 opacity-80" />
        <span className="text-sm font-semibold">
          {active ? "useGlass() active" : "Custom useGlass() button"}
        </span>
      </span>
      <span className="font-mono text-[11px] opacity-60">
        {isReady ? "WebGL2" : "CSS"}
      </span>
    </button>
  );
}

export default function Demo() {
  return (
    <div className="relative isolate flex w-full max-w-md flex-col items-center gap-5 overflow-hidden rounded-[28px] p-8">
      <div
        aria-hidden
        className="absolute inset-0 -z-10 border border-border bg-zinc-900"
      />
      <GlassSurface
        as="nav"
        aria-label="Floating dock"
        radius="9999px"
        blur={6}
        refraction={1.1}
        elevation="lg"
        className="flex items-center gap-1 px-3 py-2"
      >
        {[
          { icon: Compass, label: "Explore" },
          { icon: Layers, label: "Layers" },
          { icon: Search, label: "Search" },
        ].map(({ icon: Icon, label }) => (
          <span
            key={label}
            className="inline-flex items-center gap-1.5 rounded-full px-3 py-1.5 text-xs font-medium"
          >
            <Icon className="size-3.5" />
            {label}
          </span>
        ))}
      </GlassSurface>
      <CustomHookCard />
    </div>
  );
}
```

## Using <GlassSurface>

`<GlassSurface>` is a polymorphic refractive glass container (`as="div" | "nav" | "header" | "section" | "aside"…`) powered by `useGlass()`. It ships with sensible defaults for corner radius, frost blur, specular rim light, and elevation shadow, and triggers Vitrum's offline license check automatically.

```tsx
import { GlassSurface } from '@vitrumui/react/surface'

<GlassSurface
  as="nav"
  aria-label="Floating dock"
  radius="9999px"
  blur={6}
  refraction={1.1}
  elevation="lg"
  className="flex items-center gap-2 px-4 py-2"
>
  <button>Explore</button>
  <button>Layers</button>
</GlassSurface>
```

## Using the useGlass() hook

Attach `useGlass()` directly to any HTML element when you need full control over markup, event handlers, or refs. It returns `{ ref, style, glassProps, isReady, reduceMotion }`, renders deterministically during SSR (zero hydration mismatches), and respects `prefers-reduced-motion`.

```tsx
import { useGlass } from '@vitrumui/react/surface'

export function CustomGlassCard({ children }: { children: React.ReactNode }) {
  const { ref, style, glassProps, isReady } = useGlass<HTMLDivElement>({
    radius: 24,
    blur: 6,
    refraction: 1.15,
    interactive: true,
    elevation: 'md',
  })

  return (
    <div ref={ref} {...glassProps} style={style} className="p-6">
      {children}
      <span className="sr-only">{isReady ? 'WebGL2 active' : 'CSS fallback'}</span>
    </div>
  )
}
```

## API reference

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `as` | `React.ElementType` | `'div'` | On `<GlassSurface>`: element tag or component to render. |
| `radius` | `number \| string` | `24` | Corner radius in px (number) or any CSS length string (`'9999px'`, `'1.5rem'`). |
| `tint / tintColor` | `number / string` | `0.65 / —` | Tint opacity (0–1) and optional CSS tint colour; inherits active `<VitrumProvider>` theme when omitted. |
| `blur / refraction / specular` | `number` | `5 / 1 / 1` | Frost blur in px, rim refraction multiplier, and specular rim highlight multiplier. |
| `interactive` | `boolean` | `false` | Enables spring hover and press deformation under the pointer. |
| `elevation` | `'none' \| 'sm' \| 'md' \| 'lg'` | `'md'` | Drop shadow depth layered beneath the refractive glass. |
| `live / backdrop / disabled` | `boolean / string / boolean` | `false / — / false` | Repaint every frame for moving backdrops, scope refraction to a CSS selector, or force the CSS fallback. |

Source: /docs/custom-glass
