Card

A surface container with header, body, and footer slots.

VerifiedSince 0.3.4

Usage

Basic

Loading demo...
Loading demo...

Inertial

inertial makes the card follow the pointer and spring back on leave; inertialMaxOffset caps the travel and inertialRebound sets the bounce.

Loading demo...

Title

Loading demo...

Actions

Loading demo...

Variants

plain drops the border and the hover feedback.

Loading demo...

Backgrounds

background picks the surface material from the same values as BaseSurface's mode; refraction is the default and the recommendation.

Loading demo...

Specular light

specular gives the card a faint light that follows the pointer in dark themes: a 600px white radial light over the surface (6%, gone by 40%), and where it crosses the border, a tighter 240px glint in the ring the border occupies. The light trails the pointer by exponential smoothing, lights up right under the pointer on the way in, and fades out over 240ms on leave; with reduced motion it jumps straight to the pointer. Light themes and high contrast don't draw it, and a dashed border gets no glint. It follows clickable when absent and is off while disabled. Where each value comes from is in Alpha Noise Masks & Specular Tracking.

Loading demo...

Empty State

Loading demo...

Overlay Panels

Popover, SearchSelect, and other overlays render their panel with TxCard, configured through panel-* props.

Loading demo...

Sizes

size only sets the padding.

Loading demo...

Padding and Radius

Loading demo...

States

Loading demo...

Flow light

flowLight is passed to the card's surface whatever its background; floating panels turn it on through panelCard.

Loading demo...

Best Practices

  • Use clickable only for whole-card navigation or selection; put separate actions on real buttons or links inside the slots.
  • Tune the look with variant, shadow, size, radius, and padding; override CSS variables only to align slot content or the mask color.
  • For low-level refraction or filter parameters (displace, distortionScale, redOffset, …), use TxBaseSurface.

API Reference

Props

PropTypeDefaultDescription
variant'solid' | 'dashed' | 'plain''solid'Border style; plain has no border and no hover feedback.
background'pure' | 'mask' | 'blur' | 'glass' | 'refraction' | 'acrylic' | 'mica' | 'flat' | 'plain''refraction'Surface material, the same values as TxBaseSurface's mode.
shadow'none' | 'soft' | 'medium''none'Shadow strength.
size'small' | 'medium' | 'large''medium'Padding preset: 10 / 12 / 16 px.
radiusnumber18Corner radius in px.
paddingnumber-Padding in px; overrides size.
glassBlurbooleantrueEnables blur under glass / refraction.
glassBlurAmountnumber22Blur radius in px under glass / refraction.
glassOverlaybooleantrueEnables the highlight layer under glass / refraction.
glassOverlayOpacitynumber0.18Highlight layer opacity.
maskOpacitynumber0.75Surface opacity under mask, clamped to 0..1; acrylic's tint takes 0.8 of it.
fallbackMaskOpacitynumber0.26Mask opacity (0–1) when the surface falls back during motion.
surfaceMovingbooleanfalseExternal motion flag, merged with inertial motion and forwarded to the surface.
refractionStrengthnumber62Refraction strength (0–100); drives dispersion and distortion.
refractionProfile'soft' | 'filmic' | 'cinematic''filmic'Refraction style preset.
refractionTone'mist' | 'balanced' | 'vivid''vivid'Refraction tone preset; vivid avoids a gray cast.
refractionAnglenumber-24Main dispersion direction in degrees.
refractionLightFollowMousebooleanfalseMakes the highlight anchor follow the pointer.
refractionLightFollowIntensitynumber0.45Follow weight (0–1) on dispersion angle and strength.
refractionLightSpringbooleantrueSprings the light as it follows the pointer.
refractionLightSpringStiffnessnumber0.15Light spring stiffness, clamped to 0.01–0.55.
refractionLightSpringDampingnumber0.6Light spring damping, clamped to 0.55–0.99.
flowLight'corners' | 'rim' | 'aurora' | false-The flow light on the surface; absent or false is off.
flowLightIntensitynumber1Flow light strength, multiplying the theme opacity.
clickablebooleanfalseEnables hover and press feedback (scales to 0.985) and emits click.
specularboolean-A faint light that follows the pointer, with a glint along the border, in dark themes; follows clickable when absent and is off while disabled.
loadingbooleanfalseCovers the card with a TxSpinner overlay.
loadingSpinnerSizenumber-Spinner size in px; 12 when omitted.
disabledbooleanfalseDisabled styling; blocks click and pointer motion.
inertialbooleanfalseFollows the pointer and springs back on leave.
inertialMaxOffsetnumber22Maximum follow offset in px.
inertialReboundnumber0.12Rebound factor, clamped to 0..1; higher is bouncier.

Events

EventParamsDescription
click(event: MouseEvent)Fires on click, Enter, or Space when the card is clickable and not disabled.

Slots

SlotPropsDescription
default-Body content.
header-Header above the body.
footer-Footer below the body.
cover-Cover before the header and body.

Overview

  • When clickable, the root gets role="button" and tabindex="0", and Enter / Space fire click; otherwise it is a plain div.
  • A disabled clickable card sets aria-disabled and leaves the tab order.
  • Only key presses on the card itself activate it; Enter / Space in slotted controls don't.
  • The loading overlay is aria-hidden; screen-reader and form-busy announcements are up to the caller.
  • background is forwarded to TxBaseSurface as the surface mode: mask and acrylic use maskOpacity, and mask, acrylic and mica take --tx-card-fake-background as their base colour; blur and acrylic both blur 30px; glass and refraction use the blur and overlay props; refraction props apply only under refraction.

Technologies

  • The surface is an aria-hidden TxBaseSurface; inertia is a requestAnimationFrame spring that writes --tx-card-dx / --tx-card-dy and stops once settled.
  • Source: packages/tuffex/packages/components/src/card/.
查看源码
packages/tuffex/packages/components/src/card/index.ts

Customization

EXAMPLE.CSS
.custom-card {
  /* Base color sampled by mask and refraction fallback surfaces */
  --tx-card-fake-background: color-mix(in srgb, var(--tx-bg-color-overlay, #fff) 92%, transparent);
}
VariableWritten byPurpose
--tx-card-radiusradiusRadius of the root. The surface, cover, and loading overlay sit inside the border and take this radius less --tx-card-border-width, so their corners stay concentric with the root's.
--tx-card-border-widthvariantBorder width: 1px for solid and dashed, 0 for plain. Do not set it by hand.
--tx-card-paddingpadding or sizePadding and the cover's negative margin.
--tx-card-dx / --tx-card-dyinertial motionRoot offset; don't set manually.
--tx-card-fake-backgroundcaller / themeBase color of mask, acrylic and mica surfaces and of refraction fallback surfaces.
--tx-card-light-x / --tx-card-light-yspecularPosition of the light, in percent of the card's width and height, written on .tx-card__specular; don't set manually.
--tx-surface-refraction-mask-colorroot inline styleForwards --tx-card-fake-background to TxBaseSurface; override that one instead.

To follow an app theme, override global tokens such as --tx-bg-color-overlay, --tx-border-color-light, and --tx-color-primary.