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; refraction is recommended.

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...

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' | 'blur' | 'glass' | 'refraction' | 'mask''pure'Surface material.
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.
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.18Light spring stiffness, clamped to 0.01–0.55.
refractionLightSpringDampingnumber0.84Light spring damping, clamped to 0.55–0.99.
clickablebooleanfalseEnables hover and press feedback (scales to 0.985) and emits click.
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 uses maskOpacity, 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/.

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, surface, cover, and loading overlay.
--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 and refraction fallback surfaces.
--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.

查看源码
packages/tuffex/packages/components/src/card/index.ts