Components
Glass
Add an optional glass material to a custom control surface.
Example
Requires React 18.2+ or 19 and shared styles. See setup.
Default
Loading preview…
Code
'use client';
import { Button, HStack, Text, UIProvider, VStack } from '@swiftuijs/ui';
import { Glass } from '@swiftuijs/ui';
export default function Example() {
return (<UIProvider glass theme="system">
<VStack spacing={20} style={{ padding: 32, borderRadius: 24, background: 'linear-gradient(135deg, color-mix(in srgb, var(--sw-color-background-primary) 35%, #2563eb), color-mix(in srgb, var(--sw-color-background-primary) 35%, #7c3aed), color-mix(in srgb, var(--sw-color-background-primary) 35%, #db2777))' }}>
<Glass><HStack><Text>Regular material</Text><Button>Done</Button></HStack></Glass>
<Glass glass={{ variant: 'clear', intensity: 0.8 }}><Text>Clear material over a rich background</Text></Glass>
<Glass glass={false}><Text>Effects disabled</Text></Glass>
<Glass glass={{ intensity: 0 }}><Text>Zero intensity</Text></Glass>
</VStack>
</UIProvider>);
}Usage and limitations
- Inherits
UIProviderpreferences;glassoverrides them for this surface. Glass is off by default. glass={{ enabled: true, intensity: 0.6, variant: 'regular' }}enables it. Intensity is clamped to 0–1;regularsoftens the background for legibility, whilecleartransmits more color and uses less blur.falseor zero intensity uses an opaque fallback.- Use on controls over content. Keep forms and content cards opaque and check contrast over your actual background.
- Chromium adds shape-aware SVG edge refraction after hydration. Foreground content remains unfiltered and interactive. Safari and Firefox use CSS blur, tint and highlights; set
renderer: 'css'to use that path everywhere. - SVG refraction needs
img-src data:in a Content Security Policy; blocked images or an unavailable renderer keep the CSS fallback. Reduced transparency, increased contrast and forced colors use opaque surfaces; browsers without backdrop-filter also stay opaque. - This web approximation does not reproduce Apple's system vibrancy or full native optical model. Maps are cached and rebuilt after size/radius changes settle; no cursor animation or graphics-engine dependency is added.
- See theming and materials for configuration and browser requirements.
More examples
Optics
Navigation Surfaces
Presentations
API reference
| Prop | Type | Required | Description |
|---|---|---|---|
glass | boolean | { enabled?: boolean; intensity?: number; variant?: 'regular' | 'clear'; renderer?: 'auto' | 'css' } | No | Local material override. Intensity is clamped to 0–1; zero uses an opaque surface. Default: Inherited from UIProvider; off without a provider |
Inherits additional props from IBaseElementComponent<'div'>, GlassSurfaceProps.