Skip to content

Get started

Custom Glass

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

Markdown
glass-surface-basic.tsx

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.

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

custom-card.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

PropTypeDefault
as

On <GlassSurface>: element tag or component to render.

React.ElementType'div'
radius

Corner radius in px (number) or any CSS length string ('9999px', '1.5rem').

number | string24
tint / tintColor

Tint opacity (0–1) and optional CSS tint colour; inherits active <VitrumProvider> theme when omitted.

number / string0.65 / —
blur / refraction / specular

Frost blur in px, rim refraction multiplier, and specular rim highlight multiplier.

number5 / 1 / 1
interactive

Enables spring hover and press deformation under the pointer.

booleanfalse
elevation

Drop shadow depth layered beneath the refractive glass.

'none' | 'sm' | 'md' | 'lg''md'
live / backdrop / disabled

Repaint every frame for moving backdrops, scope refraction to a CSS selector, or force the CSS fallback.

boolean / string / booleanfalse / — / false