GlassSurface
Refractive glass container with SVG displacement, backdrop-filter, and solid fallback rendering paths.
Usage
GlassSurface
Loading demo...
Best Practices
- Use this component only when the surrounding artwork benefits from visible refraction. For regular cards, prefer
TxBaseSurfaceorTxCardso the UI keeps predictable contrast. - Keep
width,height, andborderRadiusexplicit when the glass layer sits above scrollable or image-heavy content; the displacement map is regenerated from the measured container bounds. - Tune
blur,backgroundOpacity, andsaturationagainst the actual background. Heavy blur on low-contrast content can make text behind the panel unreadable. - Treat
distortionScaleand RGB offsets as art-direction controls. Large negative values or wide channel offsets should be reserved for hero / preview surfaces, not dense forms. - Account for the fallback paths in Safari, Firefox, SSR, tests, and other environments without
CSS.supports; those paths preserve layout and readability but remove RGB refraction. - Keep important controls inside the default slot; the generated SVG is decorative, non-interactive, and sits behind
.tx-glass-surface__content.
API Reference
Props
| Property | Type | Default | Description |
|---|---|---|---|
| width | Surface width. Numeric values are normalized to px; strings are passed through. | ||
| height | Surface height. Numeric values are normalized to px; strings are passed through. | ||
| borderRadius | Outer radius in px, also applied to the generated displacement map rectangles. | ||
| borderWidth | Edge-size multiplier used when generating the displacement map mask. | ||
| brightness | Lightness percentage for the generated inner displacement mask. | ||
| opacity | Alpha value for the generated inner displacement mask. | ||
| blur | Blur radius for the generated displacement mask; also drives the backdrop-filter fallback blur. | ||
| displace | Final SVG feGaussianBlur.stdDeviation applied after the RGB displacement maps are blended. | ||
| backgroundOpacity | Background alpha used on the SVG-filter rendering path. | ||
| saturation | Saturation value appended to the SVG-filter backdrop-filter chain. | ||
| distortionScale | Base SVG displacement scale applied to the red, green, and blue maps. | ||
| redOffset | Offset added to distortionScale for the red displacement map. | ||
| greenOffset | Offset added to distortionScale for the green displacement map. | ||
| blueOffset | Offset added to distortionScale for the blue displacement map. | ||
| xChannel | SVG displacement X channel selector forwarded to all RGB maps. | ||
| yChannel | SVG displacement Y channel selector forwarded to all RGB maps. | ||
| mixBlendMode | CSS mix-blend-mode used by the generated blue gradient rectangle in the displacement map. |
Events
TxGlassSurface does not emit custom events. Put interactive controls inside the default slot and handle their native events there.
Slots
| Slot | Props | Description |
|---|---|---|
default | - | Panel content rendered above the generated SVG filter layer and centered by .tx-glass-surface__content. |
Parameter Tuning (Slider)
GlassSurface Parameter Tuning
Loading demo...
Fallback degradation
TxGlassSurface selects the rendering path in this order:
- SVG filter refraction path: when the browser supports
backdrop-filter: url(#filter), the component uses the generated SVG displacement map and keeps RGB channel displacement,distortionScale,redOffset/greenOffset/blueOffset,xChannel/yChannel,displace, andsaturation. - backdrop-filter blur path: when SVG filters are unavailable but native
backdrop-filteris supported, it falls back toblur(${blur}px) saturate(1.8) brightness(1.06)with a translucent background and border. RGB displacement and chromatic refraction are no longer rendered. - solid translucent path: when
backdrop-filteris also unavailable, it falls back to a translucent background plus border. Real blur and refraction are disabled, but width, height, radius, and baseline readability are preserved.
Safari and Firefox currently skip the SVG filter refraction path and enter the latter fallback paths first.
Technologies
- Rendering contract: numeric
width/heightbecome px strings, string dimensions pass through, and measured bounds feed the generated displacement map. - Fallback contract: SVG displacement is the high-fidelity path; unsupported browsers fall back to native
backdrop-filter, then to a solid translucent surface that preserves layout and readability but drops RGB refraction. - Interaction contract: the generated SVG/filter layers are decorative. Interactive controls belong in the default slot above
.tx-glass-surface__content. - Verified coverage:
glass-surface.test.tscovers dimension normalization, slot rendering, solid fallback styling, and RGB displacement channel forwarding. - Component source:
packages/tuffex/packages/components/src/glass-surface/src/TxGlassSurface.vue. - Types:
packages/tuffex/packages/components/src/glass-surface/index.tsexportsGlassSurfacePropsandTxGlassSurfaceInstance. - Coverage:
packages/tuffex/packages/components/src/glass-surface/__tests__/glass-surface.test.tsverifies numeric dimension normalization, slot rendering, solid fallback styling, and SVG displacement channel forwarding.
查看源码
packages/tuffex/packages/components/src/glass-surface/index.ts