usePressFeedback@astryxdesign/core v0.7.5 · usePressFeedback

Usage

The touch press model every Astryx pressable uses, for a local component that paints its own press. Under a finger, CSS :active paints on the touch itself and can outlive the start of a scroll; the press model instead tracks the touch the way UIKit tracks a control or a list cell (see profile): a control highlights as the finger lands (after the content-touch delay inside a scroller, where a flick paints nothing), a cell waits for that delay and yields to 10 px of travel, a quick tap answers at the lift, and a scroll that takes the touch cancels it with no fade. The release fades on the profile's clock. One document-level tracker does this for every marked element (installed by the first pressable to mount, removed by the last to unmount), so calling the hook adds no listener or state to your element. On a desktop a mouse press is still your :active rule: keep it, and drop it under @media (pointer: coarse) the way the built-in components do. That query reads the primary pointer, so on a phone or tablet it also drops :active for a connected mouse, trackpad or keyboard; those presses are painted there (at once, faded at the release), so nothing goes unanswered.

ts
import {usePressFeedback} from '@astryxdesign/core/hooks'

Best practices

GuidancePractices
Do

Spread the result on the element whose background paints the press and compose one of interactionOverlayStyles on it; the composed style is the instant onset, the hold and the fade, and it is themed through --color-overlay-pressed.

Do

Let the composed style own the press on every pointer: it keeps :active for a desktop mouse and drops it under @media (pointer: coarse), where every press is painted for you (a finger through the press model, a mouse or Space key at once). A rule of your own that paints :active would paint under a finger too, on the touch and through a scroll.

Do

Pass profile: 'cell' for a row in a list, and keep the default for a control.

Don't

Add a pointer listener or React state to the element to track the press; the tracker already writes the attribute, and per-element listeners are what a long list cannot afford.

Don't

Call it for a control rendered by an Astryx component; those are marked already, and the innermost marked element takes the press.

Parameters

ParamTypeDescription
options

Optional configuration.

options.profile
'control' | 'cell' (default: 'control')

How a finger's press is tracked and released, after UIKit. control (a button, a card, a switch): highlights in the frame the finger lands, or after UIScrollView's 150 ms content-touch delay inside a scroller, and releases over UIButton's 250 ms. cell (a list row): waits for that delay wherever it is, is cancelled by 10 px of travel, and releases on the deselect clock. A scroll that takes the touch cancels either with no fade and no click.

Returns

FieldTypeDescription
pressableProps{'data-astryx-pressable': '' | 'cell'}

The marker attribute to spread on the element that paints the press; its value is the profile. Compose one of interactionOverlayStyles (from @astryxdesign/core/utils) on the same element — backgroundColor or backgroundImage for a surface whose hover and press are the system's overlays, pressedBackgroundColor for one whose hover is its own — and it paints the pressed token on the first frame of a press and fades it over the profile's release, keeping :active for a mouse on a desktop. On a phone or tablet, where the stylesheet drops :active, a mouse, trackpad or Space-key press is painted too: at once, held while the button or key is down, faded at the release. A press is themed through --color-overlay-pressed.

Use with shadcn

Already using the shadcn registry workflow? Install the real Astryx package and a local public re-export. Component implementation source stays in Astryx.

This install URL expires with the draft preview.
bash
npx shadcn@4.19.0 add https://astryx-nswy75yqo-fbopensource.vercel.app/shadcn/hooks/use-press-feedback.json