Components/BaseSurface

BaseSurface

A background layer with switchable materials and motion fallback.

VerifiedSince 0.3.4

Usage

Modes

mode picks the material: pure solid, mask translucent overlay, blur backdrop blur, glass, or refraction.

Loading demo...

Advanced Lab

filter* props tune the filter layer, refraction* props the refraction layer, and preset="card" applies the card tuning.

Loading demo...

Fake Mode

fake paints the background on a pseudo-element, matching the existing .fake-background layering; slot content sits above it naturally.

Loading demo...

Motion Fallback

transform motion breaks backdrop-filter; with moving set, the surface degrades to fallbackMode and recovers smoothly when it stops.

Loading demo...

Raw vs BaseSurface

When the motion state isn't available, turn on autoDetect and the surface watches transform transitions itself.

Loading demo...

Best Practices

  • Prefer TxCard for product containers, since it owns container semantics and interaction; use TxBaseSurface only to tune material, fallback, or refraction directly.
  • Pass moving when the parent owns the animation state; use autoDetect only for transform transitions whose state you can't reach.
  • Keep fallbackMode="mask" so blur / glass content stays readable in motion; use pure only when a flat color is acceptable.
  • Tune refraction through refractionStrength, refractionProfile, and refractionTone; keep RGB channel offsets for visual experiments.
  • Use refractionRenderer="css" only where its lower optical fidelity is acceptable.

API Reference

Props

PropTypeDefaultDescription
mode'pure' | 'mask' | 'blur' | 'glass' | 'refraction''pure'Surface mode: solid, mask, filter, glass, or refraction.
radiusstring | number-Corner radius; inherits from the parent when unset.
colorstring-Base color for the solid or mask layer.
opacitynumber0.75Opacity in mask mode (0–1).
fallbackMaskOpacitynumber-Opacity when degraded to mask (0–1).
blurnumber10Filter-layer blur radius in px.
filterSaturationnumber1.5Filter-layer saturation.
filterContrastnumber1Filter-layer contrast.
filterBrightnessnumber1Filter-layer brightness.
saturationnumber1.8Glass-layer saturation for glass and refraction.
brightnessnumber70Glass-layer brightness for glass and refraction; <= 3 is read as a multiplier.
backgroundOpacitynumber0Background opacity of the glass layer.
borderWidthnumber0.07Edge width factor of the glass layer.
displacenumber0.5Refraction displacement amount.
distortionScalenumber-180Refraction distortion scale.
redOffset / greenOffset / blueOffsetnumber0 / 10 / 20RGB channel offsets that control dispersion.
xChannel / yChannel'R' | 'G' | 'B''R' / 'G'Channels sampled by the displacement map.
mixBlendModestring'difference'Refraction blend mode.
refractionStrengthnumber62Refraction strength, 0–100.
refractionProfile'soft' | 'filmic' | 'cinematic''filmic'Refraction style preset.
refractionTone'mist' | 'balanced' | 'vivid''balanced'Refraction tone: vivid is clearer, mist softer.
refractionAnglenumber-24Main dispersion angle in degrees.
refractionLightX / refractionLightYnumber-Light anchor (0–1).
refractionHaloOpacitynumber-Halo opacity (0–1); the built-in filmic model applies when unset.
overlayOpacitynumber0Extra mask opacity for non-mask modes.
preset'default' | 'card''default'Visual preset; card applies the card tuning.
refractionRenderer'svg' | 'css''svg'Refraction renderer.
movingbooleanfalseMarks the surface as moving, which triggers the fallback.
fallbackMode'pure' | 'mask''mask'Mode used while moving.
settleDelaynumber150Delay in ms before recovery after motion ends; never shorter than transitionDuration.
autoDetectbooleanfalseDetects transform motion and falls back automatically.
transitionDurationnumber299Recovery transition duration in ms.
fakebooleanfalseRenders the background on a pseudo-element.
fakeIndexnumber0z-index of the pseudo-element layer.
tagstring'div'Root element tag.

Slots

SlotPropsDescription
default-Surface content, rendered in .tx-base-surface__content above every material layer.

CSS Variables

VariableSourceDescription
--tx-surface-colorcolor prop or theme fallbackSolid / mask color; defaults to var(--tx-fill-color-lighter, #fafafa).
--tx-surface-radiusradius propRadius of the root and every layer; numbers become px.
--tx-surface-transitiontransitionDuration propDuration of layer fades, background, and backdrop-filter transitions.
--tx-surface-filter-blurblur propBlur radius of the filter and refraction filter layers.
--tx-surface-filter-saturationfilterSaturation propFilter-layer saturation multiplier.
--tx-surface-filter-contrastfilterContrast propFilter-layer contrast multiplier.
--tx-surface-filter-brightnessfilterBrightness propFilter-layer brightness multiplier.
--tx-surface-mask-opacityopacity, fallbackMaskOpacity, or overlayOpacityCurrent mask opacity, clamped to 0..1.
--tx-surface-refraction-light-x / --tx-surface-refraction-light-yrefractionLightX / refractionLightY or angle modelRefraction light anchor in percent.
--tx-surface-refraction-strengthrefractionStrength modelOptical strength blended across rest, motion, and recovery.
--tx-surface-fake-indexfakeIndex propz-index of the pseudo-element layer.
--tx-surface-fake-bgcolor prop or theme fallbackBackground color of the pseudo-element.
--tx-surface-fake-opacitymask opacity modelOpacity of the pseudo-element.
--tx-surface-mask-opacity-percentmask opacity modelMask opacity as a percentage (internal; do not override).
--tx-surface-motion-cover-opacitymotion state modelOpacity of the refraction motion cover (internal).
--tx-surface-refraction-edge-opacityoptics modelOpacity of the refraction edge highlight (internal).
--tx-surface-refraction-streak-anglerefractionAngle modelRefraction streak angle, the angle plus 92deg (internal).
--tx-surface-refraction-{filter,mask}-{base,primary,secondary,veil}-weight / --tx-surface-refraction-streak-weightprofile/tone weight modelBlend weights of the optical layers (internal).
--tx-surface-refraction-*-gain / -boost / -base, --tx-surface-refraction-halo-opacity, --tx-surface-refraction-mask-effective-opacityprofile/tone derived valuesDerived outputs of the optical interpolation (internal).
--tx-surface-refraction-mask-colortheming hook (consumed)Base color of the refraction gradients; override it in themes (defaults to #fff shades).

Overview

  • pure renders only the root background; mask renders a mask layer with opacity clamped to 0..1.
  • blur and glass degrade while moving is set or transform motion is detected: fallbackMode="mask" prefers fallbackMaskOpacity, and pure renders no mask layer.
  • refraction keeps its mode in motion: the glass / blur layers that lose their sampling fade out, a translucent motion cover holds the weight, and both cross-fade back on settle.
  • Passing any of refractionStrength, refractionAngle, or refractionProfile switches to the derived refraction model; unset ones fall back to 62 / -24 / 'filmic'.
  • autoDetect watches style changes on the root and its ancestors plus transitionstart / transitionend / transitioncancel, and removes its listeners on unmount.

Technologies

  • Glass and refraction render through TxGlassSurface; fallback timing lives in base-surface-motion.ts.
  • Source: packages/tuffex/packages/components/src/base-surface/.
查看源码
packages/tuffex/packages/components/src/base-surface/index.ts