@ai-matrx/tap-target

中文文档
0.2.91发布于 2026/10/12MITTypeScriptESM + CJS近 30 天下载 2.9万

The AI Matrx tap-target button system: one locked 38px footprint per button (32px pill, 16px glyph, 6px between pills, 28px wide shapes, a coarse-pointer hit slop), the macOS-style TapTargetSearchGroup, glass/transparent/solid/group variants with correct

原始使用文档
文档目录5 节
  1. Setup — two one-time steps
  2. Link component registration
  3. Usage
  4. Subpaths
  5. Styling notes

@ai-matrx/tap-target

The AI Matrx tap-target button system: every button occupies one fixed 38px footprint holding a 32px round pill and 16px glyph, so neighbouring buttons sit exactly 6px apart with no wrapper (wide shapes — capsules, labelled pills — are 28px tall; a 24px pill in the slim group geometry; a touch area toward 44px on coarse pointers through an invisible hit slop), plus TapTargetSearchGroup — the macOS toolbar search, with press feedback, mobile tap hygiene (no 300ms delay, no iOS gray flash), and correct ref forwarding for Radix asChild triggers.

  • Primitives — TapTargetButton (glass), TapTargetButtonTransparent, TapTargetButtonSolid, TapTargetButtonDestructive, TapTargetButtonForGroup + TapTargetButtonGroup, and the TapTargetLabeled caption wrapper.
  • ~60 pre-composed buttons — BugTapButton, PlusTapButton, TrashTapButton, … one import, one tag, zero configuration, all glyphs inlined. Opt-in via the ./buttons subpath.
  • Every button can be a button, label, or link (as="label", href), carries automatic tooltip wiring from ariaLabel, and supports an inline caption (label) that widens the pill.
npm install @ai-matrx/tap-target

Peer: react >= 18. The canonical primitive, geometry and tooltip behavior come from the regular @ai-matrx/design-system dependency.

Setup — two one-time steps

1. Import the stylesheet once at your app root. The CSS is part of the product — the geometry and press feedback live in it, and nothing renders correctly without it. Declare its lock layer FIRST in your root CSS (@layer matrx-tap-lock; before any other rule) so no class can bend it, and turn on the misuse guard in development builds (enableTapTargetGuard()):

// app/layout.tsx (or your root entry)
import "@ai-matrx/tap-target/styles.css";

That one line is enough: since 0.2.1 this sheet @imports @ai-matrx/design-system/styles.css, which it REQUIRES — the loading button's spinner wears design-system's matrx-spin, whose keyframe is defined there (never animate-spin, a host utility this package cannot ship). If your app already imports the design-system sheet, nothing is duplicated.

2. Mount a tooltip provider near the root (skip if your app already mounts @radix-ui/react-tooltip's provider):

import { TooltipProvider } from "@ai-matrx/tap-target";

<TooltipProvider delayDuration={300}>{children}</TooltipProvider>

href on any tap button renders a link. External hrefs (http(s):, mailto:, tel:) always render <a target="_blank" rel="noopener noreferrer">. Internal hrefs render through your router's link component — register it once at startup:

import Link from "next/link";
import { setTapTargetLinkComponent } from "@ai-matrx/tap-target";

setTapTargetLinkComponent(Link); // e.g. in a client boot component

Without a registration, internal hrefs fall back to a plain <a> (still a working link — no prefetch, no client-side routing). A per-instance override is also available: <TapTargetButton href="/tasks" linkComponent={Link} />.

Usage

import { TapTargetButton, TapTargetButtonGroup, TapTargetButtonForGroup } from "@ai-matrx/tap-target";
import { PlusTapButton, TrashTapButton } from "@ai-matrx/tap-target/buttons";

// Pre-composed (preferred): one tag, tooltip auto-derives from ariaLabel
<PlusTapButton onClick={add} ariaLabel="Add a task" />

// Variants: glass (default) | transparent | solid | group
<TrashTapButton variant="solid" bgColor="bg-destructive" iconColor="text-destructive-foreground" />

// Links
<PlusTapButton href="/tasks/new" ariaLabel="New task" />

// Inline caption (widens the pill, tooltip off — the label self-describes)
<PlusTapButton label="Add" />

// Grouped slim buttons in one shared glass shell
<TapTargetButtonGroup>
  <TapTargetButtonForGroup ariaLabel="Undo" icon={<UndoIcon />} />
  <TapTargetButtonForGroup ariaLabel="Redo" icon={<RedoIcon />} />
</TapTargetButtonGroup>

// Custom glyph via the primitive
<TapTargetButton ariaLabel="Custom" icon={<MyIcon className="h-4 w-4" />} />

Refs forward to the underlying <button>, so every button works as a Radix asChild trigger (DropdownMenu, Popover, Tooltip, …):

<DropdownMenuTrigger asChild>
  <MoreHorizontalTapButton />
</DropdownMenuTrigger>

Subpaths

SubpathWhat it is
.Primitives, TapTargetLabeled, link registration, tooltip re-exports.
./buttonsThe ~60 pre-composed buttons (heavy — every glyph inlined; opt-in).
./styles.cssThe REQUIRED geometry/feedback stylesheet — import once at app root.
./package.jsonThe manifest.

Styling notes

  • Geometry and press feedback come from styles.css (.matrx-tap-*). To retune every tap button, that file is the single source of truth — never per-button size overrides.
  • Variant decoration uses Tailwind-style utility classes on the pill (bg-primary, hover:bg-muted, text-foreground, and the Matrx matrx-glass-thin-border / matrx-glass-interactive glass classes). In a Tailwind app these resolve against your theme tokens; make sure your Tailwind build scans this package (Tailwind v4: @source "../node_modules/@ai-matrx/tap-target";) and provide the two matrx-glass-* classes (or accept an undecorated glass pill).
  • Never wrap a tap button in extra p-*/m-*/gap-* — the box already reserves the spacing. With the guard on, such a button renders as a red box.
  • Release timing probe (2026-10-09): this line exists to measure push-to-npm for a one-line change.

版本与发布记录

@ai-matrx/tap-target 共发布 95 个版本,首次发布于 2026/08/29;过去 12 个月发布了 95 个版本。

版本发布日期距今
0.2.91latest2026/10/1225 天前
0.2.902026/10/1225 天前
0.2.892026/10/1125 天前
0.2.882026/10/1125 天前
0.2.872026/10/1125 天前
0.2.862026/10/1126 天前

关于 @ai-matrx/tap-target 的常见问题

@ai-matrx/tap-target 是什么?

The AI Matrx tap-target button system: one locked 38px footprint per button (32px pill, 16px glyph, 6px between pills, 28px wide shapes, a coarse-pointer hit slop), the macOS-style TapTargetSearchGroup, glass/transparent/solid/group variants with correct

如何安装 @ai-matrx/tap-target?

在项目目录运行 npm install @ai-matrx/tap-target,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:react(>=18.0.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@ai-matrx/tap-target 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@ai-matrx/tap-target 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@ai-matrx/tap-target 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=20。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@ai-matrx/tap-target 可以商用吗?

@ai-matrx/tap-target 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@ai-matrx/tap-target 的下载量有多少?

根据 npm 官方下载统计,@ai-matrx/tap-target 在 2026/10/05 – 2026/11/03 这 30 天内被下载 29,179 次,日均约 973 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@ai-matrx/tap-target 还在维护吗?

最新版本 0.2.91 发布于 2026/10/12(25 天前);至今共发布 95 个版本,其中过去 12 个月发布了 95 个;首次发布于 2026/08/29。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。