Components/BaseAnchor

BaseAnchor

A primitive that anchors a floating panel to a trigger element.

VerifiedSince 0.3.4

Usage

Basic

Loading demo...

Expand Motion

The default expand springs open from the corner nearest the reference and folds back on close.

Loading demo...

Placement

placement is the preferred side; the panel flips when space runs out, and the expand origin follows the final side.

Loading demo...

Animation Modes

animation.type takes expand (default), transfer, boom, opacity, or none.

Loading demo...

Drip

drip pours the panel out of its trigger like a drop; items marked data-liquid-item appear one by one as the panel grows.

Loading demo...

Bead

bead shares the drip engine and pinches its sides by speed; beadPinch sets the peak pinch per side in px.

Loading demo...

Custom Ease

Duration and easing live in animation; the component has no top-level duration or ease props.

Loading demo...

Panel Surfaces

panelBackground picks the material; surfaceMotionAdaptation decides whether it degrades while the panel moves.

Loading demo...

Best Practices

  • Reach for TxPopover, TxDropdownMenu, or TxContextMenu first; use TxBaseAnchor directly only to build a new anchored primitive or to position against a virtual reference.
  • When you use it directly, supply the roles, focus handling, and keyboard navigation your content needs.
  • Keep panels light; move multi-step forms, destructive confirmations, and full-screen flows to a Drawer or Dialog.
  • For coordinate menus, pass virtualReference and call updatePosition() after the pointer or canvas transform changes.
  • eager and keepAliveContent keep content measurable, not positioned: measure size while closed, and take coordinates from the reference or an open panel.

API Reference

Props

PropTypeDefaultDescription
modelValuebooleanundefinedWhether the panel is open (v-model); omit it for uncontrolled use.
disabledbooleanfalseBlocks opening and closes an open panel.
eagerbooleanfalseMounts the panel before the first open so its content can be measured.
placementBaseAnchorPlacement'bottom-start'Preferred side; flips when space runs out.
offsetnumber8Gap to the reference in px.
widthnumber0Panel width; 0 sizes to content.
minWidthnumber0Minimum width.
maxWidthnumber360Maximum width.
maxHeightnumber420Maximum height, shrunk to the space left in the viewport.
unlimitedHeightbooleanfalseRemoves the height limit; maxHeight <= 0 does the same.
matchReferenceWidthbooleanfalseMatches the reference width when width is 0.
referenceClassBaseAnchorClassValueundefinedClass for the reference wrapper; all other attrs go to the panel.
virtualReferenceBaseAnchorVirtualReferenceundefinedPositions against a virtual reference, such as a cursor point; the reference slot still renders.
disableFlipbooleanfalseKeeps the requested side but still shifts into view; for a host-measured virtualReference.
animationBaseAnchorAnimationOptions{}Animation config; omitted fields take the type's defaults.
useCardbooleantrueWraps content in the built-in TxCard.
panelVariant'solid' | 'dashed' | 'plain''plain'Border style of the TxCard.
panelBackground'pure' | 'mask' | 'blur' | 'glass' | 'refraction''refraction'Panel background.
panelShadow'none' | 'soft' | 'medium''soft'Panel shadow.
panelRadiusnumber18Panel corner radius in px.
panelPaddingnumber10Panel padding in px.
panelCardBaseAnchorPanelCardPropsundefinedAdvanced TxCard props, such as maskOpacity or refraction*.
surfaceMotionAdaptation'auto' | 'manual' | 'off''auto'Surface downgrade while moving: auto follows the animation, manual reads panelCard.surfaceMoving, off never downgrades.
showArrowbooleanfalseShows an arrow that follows the placement.
arrowSizenumber10Arrow size in px.
keepAliveContentbooleanfalseKeeps content mounted after close, with its state.
closeOnClickOutsidebooleantrueCloses on an outside click.
closeOnEscbooleantrueCloses on Escape.
toggleOnReferenceClickbooleantrueToggles on reference click; turn it off for references that handle their own clicks.
hoverBridgebooleanfalseWhile open, fills the gap to the reference with an invisible hit area; TxTooltip enables it when needed.

Events

EventParamsDescription
open-Fires when the panel opens.
close-Fires when the panel closes.
update:modelValuebooleanFires when the open state changes.
floating-enterMouseEventThe pointer entered the floating layer: the panel or the hover bridge.
floating-leaveMouseEventThe pointer left the floating layer.

Slots

SlotDescription
referenceThe trigger element.
defaultPanel content; receives the final side as { side }.

Exposed Methods

MethodParamsDescription
close-Closes the panel.
toggle-Toggles the panel.
updatePosition-Recomputes the position.
getPanelRect-The panel's rect as drawn (DOMRect), or null before it mounts.
containsFloating(target: Node)Whether target is inside the floating layer, hover bridge included.
getSide-The final side: top, right, bottom, or left.

Types

BaseAnchorAnimationOptions

FieldTypeDefaultDescription
type'expand' | 'transfer' | 'boom' | 'opacity' | 'none' | 'drip' | 'bead''expand'expand springs open, transfer slides along the side, boom scales out of a blur, opacity fades, none is instant; drip / bead are liquid.
closeTypeSame values as typeSame as typeType used while closing. Liquid types must match at both ends; a mixed pair falls back to symmetric and warns in dev.
durationnumberper type (expand 400 / classic 432 / liquid 260)Open duration in ms.
closeDurationnumberper close type (expand 240 / classic: open duration × 0.45 / liquid 150)Close duration in ms.
easestringper type (expand: a spring solved for the panel's height, spring(10, 0.6) up to about 63px / classic back.out(2) / liquid linear)Open ease: a GSAP ease, cubic-bezier(...), or spring(omega, zeta), run as written; liquid types take only linear or cubic-bezier(...).
closeEasestringper close type (expand power2.in / classic power3.in / liquid cubic-bezier(0.25, 0.46, 0.45, 0.94))Close ease; same forms as ease.
distancenumberper type (expand 12 / transfer 30)expand drift and transfer travel in px.
scalenumberper type (expand 0.88 / boom 0.94 / transfer 0.92)Starting scale of the open.
blurnumber12Starting blur radius of boom in px.
opacitynumber0Starting opacity of expand, boom, and opacity.
exit{ scale?, distance?, blur?, opacity? }See descriptionClose-only geometry; each field falls back to the shared field of the same name, then to closeType's default.
gooBlurnumber4.5drip / bead only. Goo blur radius; decides how wide a gap the neck survives.
gooThresholdnumber20drip / bead only. Slope of the alpha threshold.
gooThresholdOffsetnumber-9drip / bead only. Offset of the alpha threshold.
outlineColorstring--tx-border-colordrip / bead only. Outline ring color; follows the theme by default.
triggerRadiusnumbermeasureddrip / bead only. Trigger corner radius; measured from the reference when omitted.
seedHeightnumber12drip / bead only. Panel height at the start, in px.
itemSelectorstring'[data-liquid-item]'drip / bead only. Items revealed one by one; with no match, the content reveals as a whole.
beadPinchnumber60bead only. Peak pinch per side in px; decays to 0 as the motion settles.
beadVelocityRefnumber4bead only. Speed at which the pinch peaks.

Overview

  • With modelValue it is controlled; otherwise it keeps its own open state. Each change emits open or close.
  • maxHeight shrinks to the space left in the viewport; overflow scrolls inside the card body, so read the scroll position from the body.
  • The anchor family draws no arrow by default: BaseAnchor, Tooltip, Popover, and the DropdownMenu, ContextMenu, and Select built on them. A showArrow arrow moves with the panel's content layer.
  • drip / bead work on vertical placements only; side placements fall back to opacity. They need a measurable height, so unlimitedHeight shows and hides instantly.
  • drip / bead paint their own surface: no TxCard and no arrow, so panel background, shadow, and variant do not apply. The trigger needs an opaque background.
  • Under reduced motion, every animation jumps to its end state.

Technologies

  • The panel is teleported to <body> and positioned by Floating UI in document coordinates; GSAP drives the classic types and a rAF loop drives drip / bead.
  • Source: packages/tuffex/packages/components/src/base-anchor/.
查看源码
packages/tuffex/packages/components/src/base-anchor/index.ts