Custom Glass
Give any custom component — cards, navbars, floating docks, or modals — Vitrum's real-time WebGL2 refraction with `useGlass()` and `<GlassSurface>`.
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.
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.
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 |
|---|---|---|
asOn | React.ElementType | 'div' |
radiusCorner radius in px (number) or any CSS length string ( | number | string | 24 |
tint / tintColorTint opacity (0–1) and optional CSS tint colour; inherits active | number / string | 0.65 / — |
blur / refraction / specularFrost blur in px, rim refraction multiplier, and specular rim highlight multiplier. | number | 5 / 1 / 1 |
interactiveEnables spring hover and press deformation under the pointer. | boolean | false |
elevationDrop shadow depth layered beneath the refractive glass. | 'none' | 'sm' | 'md' | 'lg' | 'md' |
live / backdrop / disabledRepaint every frame for moving backdrops, scope refraction to a CSS selector, or force the CSS fallback. | boolean / string / boolean | false / — / false |