User intent hooks and provider
@interlace/ui — typed, vendor-neutral user intent: activate, view, dwell, commit, disclosure and form hooks, `data-intent` for server components, rage clicks and page view/leave, all reported through one `IntentProvider` adapter. Sends nothing that identifies a person.
Install
Two equivalent paths — the URL works in any shadcn-CLI setup; the alias works once you've registered @interlace in your components.json.
npx shadcn@latest add https://ds.interlace.tools/r/intent.jsonnpx shadcn@latest add @interlace/intentHistory
This component is at v1.0.0, first shipped in @interlace/ui 2.0.0. The version is stamped as a banner into the file the install writes, so the copy in your tree says which one you have — compare it with the number above before deciding whether to re-run the install.
@interlace/ui 2.0.01 entry
- Addedminor
User intent: typed events for what a person meant to do, sent to whichever analytics tool the app uses.
IntentProvidertakes oneonIntentadapter. Below it,useActivateIntent(every activation, with keyboard, mouse, touch or pen),useViewIntent(half the element visible for a second),useDwellIntent(a pointer or keyboard focus resting for half a second),useCommitIntent(a typed value settled, reported as its length),useDisclosureIntent(an overlay opened or closed, and why) anduseFormIntent(started, submitted, or abandoned by cancel or page leave) all report to it. Any element withdata-intent="name"reports its clicks with no hook, so server components can declare intent too. Given apage, the provider reportspage_viewandpage_leavewith visible time and read depth, and it reports rage clicks: three quick clicks on one spot. Events carry names, numbers and enums only: never typed text, element text, or anything about who the person is. A failing adapter is caught, so analytics never breaks a page.
Import
20 named exports — pull the parts you need.
import { COMMIT_INTENT_DELAY_MS, DWELL_INTENT_DELAY_MS, IntentEvent, IntentInput, IntentKind, IntentProvider, IntentSink, RAGE_CLICK_COUNT, RAGE_CLICK_RADIUS_PX, RAGE_CLICK_WINDOW_MS, VIEW_INTENT_DELAY_MS, VIEW_INTENT_THRESHOLD, inputOf, useActivateIntent, useCommitIntent, useDisclosureIntent, useDwellIntent, useFormIntent, useIntent, useViewIntent } from '@/hooks/use-intent';API reference
Parsed from the type declarations in the source — the same file the install writes into your tree, so this table can't drift from the component you get.
IntentProviderProps
| Prop | Type | Description |
|---|---|---|
| onIntent* | IntentSink | Where every intent below this provider goes: the app's adapter. |
| page | string | The current page's name, usually its route. When set, the provider reports `page_view` for it, and `page_leave` when it changes or the document is hidden for good (`pagehide`), with the visible time and the deepest point read (0–100). |
| rageClicks | boolean | Report rage clicks anywhere below the document. Default `true`. |
| declarative | boolean | Report clicks on `[data-intent]` elements as `activate`. Default `true`. |
| children | ReactNode | — |
Accessibility
Every story for this component is rendered headlessly and checked with axe-core (wcag2aa, wcag22aa, best-practice, ACT) on every PR. That gate has no continue-on-error, so what ships has zero known violations.
What follows is what static analysis can see. Axe cannot press a key and never sees an overlay open, so the operable-without-a-mouse claim lives in Behavior instead, where the keyboard path is replayed step by step.
- Focus + keyboard behaviour
- Native element semantics — no interaction layer to get wrong.
- Focus ring (WCAG 2.2 SC 2.4.13)
- Not focusable — no focus indicator required.
- Reduced motion
- No animation to gate.
- ARIA in the source
- None — semantics come from the element or the Base UI primitive rather than hand-written ARIA.
Dependencies
- Base UI primitive
- Native / no Base UI dependency
- Lucide icons
- none
- NPM dependencies
- none
- Registry dependencies
- none
Source
The full implementation — hooks/use-intent.ts once installed.
'use client';
import {
createContext,
createElement,
useCallback,
useContext,
useEffect,
useRef,
useState,
type ReactNode,
} from 'react';
// @interlace/intent v1.0.0 — Interlace design system.
// Docs, props and live preview: https://ds.interlace.tools/c/intent
// What changed since: https://ds.interlace.tools/c/intent#history
// Generated banner — keep it, the upgrade diff reads this version.
/**
* User intent: what a person meant to do, as typed events, sent wherever the
…549 more lines…Registry JSON
The raw registry record — what the shadcn CLI fetches.