Components/GlassSurface

GlassSurface

A glass container that refracts the content behind it.

VerifiedSince 0.3.4

Usage

Basic

Loading demo...

Parameter Tuning

Loading demo...

Best Practices

  • Use it only where artwork, images, or gradients benefit from refraction; use TxBaseSurface or TxCard for regular cards.
  • Set width, height, and borderRadius explicitly when the glass sits over scrolling content or images.
  • Tune blur, backgroundOpacity, and saturation against the real background so text behind stays readable.
  • Reserve large distortionScale values and wide channel offsets for hero or preview surfaces, not dense forms.
  • Put important controls in the default slot.

API Reference

Props

PropertyTypeDefaultDescription
widthSurface width; numbers are px, strings are used as-is.
heightSurface height; numbers are px, strings are used as-is.
borderRadiusOuter radius in px, also used by the displacement map.
borderWidthEdge-size multiplier of the displacement map mask.
brightnessLightness percentage of the map's inner mask.
opacityAlpha of the map's inner mask.
blurBlur radius of the map mask; also the blur of the backdrop-filter fallback.
displaceFinal blur (feGaussianBlur.stdDeviation) after the RGB maps are blended.
backgroundOpacityBackground alpha on the SVG-filter path.
saturationSaturation on the SVG-filter path.
distortionScaleBase displacement scale of the red, green, and blue maps.
redOffsetRed offset added to distortionScale.
greenOffsetGreen offset added to distortionScale.
blueOffsetBlue offset added to distortionScale.
xChannelX-axis channel read by all three maps.
yChannelY-axis channel read by all three maps.
mixBlendModeBlend mode of the blue gradient when the map is generated.

Slots

SlotPropsDescription
default-Panel content, centered in .tx-glass-surface__content above the filter layer.

Overview

  • The rendering path follows support: SVG displacement refraction with backdrop-filter: url(), else a blur() frosted backdrop, else a translucent background with a border.
  • Safari, Firefox, SSR, and environments without CSS.supports skip refraction; the fallbacks keep size, radius, and readability but drop RGB refraction.
  • The displacement map is built from the measured size and regenerated when the size or an optical prop changes.
  • The generated SVG is decorative, non-interactive, and sits below the content layer.

Technologies

  • Three feDisplacementMap passes shift the red, green, and blue channels separately and recombine them into a chromatic refraction.
  • Source: packages/tuffex/packages/components/src/glass-surface/.
查看源码
packages/tuffex/packages/components/src/glass-surface/index.ts