Skip to content

docs(core): open the pan hook pages with a minimal draggable box - #9928

Merged
cixzhang merged 10 commits into
meta:mainfrom
vjeux:uikit/f2-pan-examples
Nov 5, 2026
Merged

cixzhang merged 10 commits into
meta:mainfrom
vjeux:uikit/f2-pan-examples

Conversation

@vjeux

@vjeux vjeux commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

Stack: #8655 → #9928

On #8655's head 14b0fe7: the examples, the one-page merge, a changeset fix, and merges of main and #8655's head. Review those.

Reader impact

A reader of the pan pages meets the playing card first, and the same examples twice, once per API. No short example shows the basic drag.

Source of truth

The hooks and their docs in #8655, under spec:AST-107 FR1 and FR6. architecture:public-component-api INV22 asks for both APIs, the hook and its create… twin, not two example pages.

Correction

  • The usePanGesture page opens with "A draggable box" in two forms side by side: one card made with usePanGesture, one with createPanGesture. Each card names its API, and both share one set of StyleX styles.
  • Each card's offset lives in React state and reaches it through a StyleX dynamic style, with no inline styles.
  • "A playing card (advanced)" follows once. Drag, settle and throw are StyleX styles driven by React state. A Button discards it from the keyboard, and useAnnounce names each discard.
  • Motion uses theme tokens: the spring-back and settle take --duration-medium with --ease-move, the neutral step nearest the old 300 ms. The fly-off takes --duration-exit with --ease-exit.
  • The next card is dealt when the throw's animations settle, or at once when none runs.
  • Each stage has a neutral wash (--color-neutral) in the example's own StyleX, so the card reads in light and dark themes. The cards take user-select: none, so a mouse drag moves them.
  • createPanGesture's page keeps its API entry and points to the shared example. Following the spec owner's ruling for state-driven examples, the usePanGesture guidance now warns only against holding the drag offset in a large component's state.
  • The route lock and the sandbox export list drop the two plain-JavaScript example pages.

Evidence

  • Template rubric 1.4, before → after: the draggable box 76 (B) → 90 (A); the playing card 64 (C) → 85 (B). Scorecards below.
  • jsdom cases: each box follows its own drag through its StyleX drag style, and the other box stays put. It springs back at the theme's duration, with no spring under reduced motion. The factory's pan comes down with the block.
  • The card deals once per Discard, keeps a throw through a drag begun during it, and announces each discard. It deals when the throw ends, when no transition runs, or on a cancel.

Scope

  • This PR changes documentation only, or names every necessary generated artifact.
  • Runtime, API, visual, and policy changes were removed or split.
  • Public text and artifacts contain no internal Meta context.

Testing

Local gates at 28476ba, on #8655's head 14b0fe7.

Earlier evidence, at aef79fd (the same examples):

  • The pan tests with the sandbox route manifest: 20 passed. At 40d7162 the CLI's node tests passed 551 of 551 files and 9,788 tests. That commit differs only in two doc strings and the changeset.
  • The pan templates type-check under the sandbox's compiler options. The CLI typechecks, strict ESLint, Prettier and pnpm check:knowledge: clean.
  • routes.lock.json matches node apps/docsite/scripts/generate-data.mjs. The docsite build passes at 40d7162.
  • node scripts/pre-review.mjs --base d007fc231a: no findings, 1,278 authored lines. A Changeset names @astryxdesign/core and @astryxdesign/cli.

Rubric scorecards (template rubric 1.4)

Example Commit Purity /30 Icons /15 CSS /15 Layout /15 Doc /10 Images /5 Code /10 Total
Draggable box, before e85acb1 20 15 2 15 9 5 10 76 (B)
Draggable box, after aef79fd 30 15 5 15 10 5 10 90 (A)
Playing card, before e85acb1 15 15 0 10 9 5 10 64 (C)
Playing card, after aef79fd 30 15 5 10 10 5 10 85 (B)

Remaining deductions are intentional. The wash, user-select and the drag, spring and throw styles have no Astryx prop. The advanced card keeps its keyboard path, announcement and throw guards at 147 lines.

…s (spec:AST-107 FR1, FR6)

The public pan: `createPanGesture(element, {axis?, onPan}) → {destroy}` and
`usePanGesture(ref, {axis?, onPan})` over it, reporting
`{state, translation, velocity}` as a drag begins, changes, ends or is
cancelled, under a finger, a mouse and a pen. The translation leaves out
the travel the drag needed to begin, so an element that follows it does
not jump. usePanGesture attaches through useAttachment, Core's one owner
of a node's attachment.

Docs pages for both, with a playing-card example in plain JavaScript and
in React. The card is an image named by its rank and suit, painted in the
theme's surface and text colors. A drag that meets a throw is ignored to
its end, and the next card's face is in place before the thrown card
returns to rest. The core API report, the route lock and the sandbox's routes
list the new exports and pages.

Drawer imports its three hooks from their own modules, as BottomSheet
and Lightbox do, so the hooks entry's new export keeps Drawer off the
gesture host.
@vercel

vercel Bot commented Nov 4, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
astryx Ready Ready Preview Nov 5, 2026 3:57pm UTC

Request Review

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Nov 4, 2026
@astracat-bot

astracat-bot Bot commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

AI review status for this pull request.

Review status Updated
🟢 Reviewed (for maintainers only) Nov 5, 2026, 4:10 PM UTC

@github-actions github-actions Bot added the needs:design-review Affects visuals — Design should review label Nov 4, 2026
@github-actions

github-actions Bot commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

PR Analysis Report

🔎 Preview · 411dd2a

Storybook · Sandbox · built from this PR's head

Package size: measured; main has no measurement of the merge base to compare yet.

API changes: none in this pull request

Committed API report behind this build: cli 9 rows, core 8 rows; run pnpm api:report.

Not run on this PR: add ci:run-visual, ci:run-a11y or ci:run-rtl to run them.


Generated by PR Enrichment workflow | View full report

@cixzhang

cixzhang commented Nov 4, 2026

Copy link
Copy Markdown
Contributor

/approve-spec b049e4c

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved pending CI: CI has not run on this head yet, and it runs once the pull request leaves draft and a maintainer adds the ci:run label.

#8655: approve; no blocking findings.

#9928: approve; no blocking findings.

Whole stack: passes; a pull request lands only when it and every pull request below it are approved, and because #9928 renames the example routes that #8655 adds, land the two together.

  • Miss: non-blocking, the playing card's Discard button renders as plain text under the Astryx reset (no border, background or padding until it takes keyboard focus), so an inline border and padding would make the drag's keyboard alternative recognizable as a button.

[Automated review]

</div>
</div>
{/* The drag's keyboard and assistive-technology path (WCAG 2.5.7). */}
<button type="button" onClick={() => discard(1)}>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Miss, non-blocking: Astryx's reset gives this native button no border, background or padding, so on the docs page it reads as a label until it takes keyboard focus. An inline border, padding and radius, as the card has, would make the drag's keyboard alternative look like a button. PanPlayingCardVanilla.tsx line 158 has the same markup.

@vjeux
vjeux force-pushed the uikit/f2-pan-examples branch 2 times, most recently from b049e4c to e85acb1 Compare November 4, 2026 11:46

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved pending CI: CI has not run on this head yet, and it runs once the pull request leaves draft and a maintainer adds the ci:run label.

#8655: approve; no blocking findings.

#9928: approve; no blocking findings.

Whole stack: passes; a pull request lands only when it and every pull request below it are approved, and because #9928 renames the playing-card example routes that #8655 adds, land the two together.

  • Non-blocking: the playing card's Discard button renders as plain text under the Astryx reset (no border, background or padding), so an inline border, padding and radius would make the drag's keyboard alternative recognizable as a button.

[Automated review]

Each page's first example is now a box that follows a drag and springs
back, in about twenty lines, for usePanGesture and for createPanGesture.
The playing card stays as the advanced example. Its throw, discard and
reset live in small named helpers, the card is two thirds its size, and
its stage is 280 px tall, so a drag, the spring back and the fly-off stay
in view at 390 px.
@cixzhang

cixzhang commented Nov 4, 2026

Copy link
Copy Markdown
Contributor

/approve-spec 2781e8e

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes requested: the examples in #9928 need three fixes before this stack can land.

#8655 — approve

The public pan (createPanGesture, usePanGesture) matches its spec, with no blocking findings.

#9928 — request changes

  • A mouse drag selects the text of both draggable boxes and the React playing card instead of moving them, because their StyleX styles dropped userSelect: 'none' (PanDraggableBox.tsx:23, PanDraggableBoxVanilla.tsx:23, PanPlayingCard.tsx:39); add it to styles.box and styles.card.
  • The usePanGesture page says not to set React state on every changed event (usePanGesture.doc.mjs:83, :154), while both of its examples do (PanDraggableBox.tsx:40, PanPlayingCard.tsx:110); make the guidance and the examples agree.
  • "A draggable box without React" is a React component with useState, useCallback, Card and Center (PanDraggableBoxVanilla.doc.mjs:7-8, PanDraggableBoxVanilla.tsx:35-64); render it in plain DOM like the card beside it, or drop "without React" from its name and route.

Whole stack — fails

A pull request lands only when it and every pull request below it are approved, and #8655 should land together with #9928, which renames its card routes.

[Automated review]

backgroundColor: colorVars['--color-neutral'],
borderRadius: radiusVars['--radius-container'],
},
box: {cursor: 'grab'},

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With a mouse, a drag here starts a native text selection (" me") and the box never moves: a mouse keeps native selection, and the inline userSelect: 'none' the earlier version carried was dropped in the StyleX rewrite. A finger still drags it. The same applies to PanDraggableBoxVanilla.tsx:23 and PanPlayingCard.tsx:39.

box: {cursor: 'grab', userSelect: 'none'},

usePanGesture(box, {
onPan: ({state, translation}) => {
const held = state === 'began' || state === 'changed';
setDrag(held ? {...translation, held} : {x: 0, y: 0, held});

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This sets React state on every changed event, which the usePanGesture page lists as a Don't (usePanGesture.doc.mjs:83: "write the element’s style in onPan instead, so a drag costs no render"). The playing card does the same at PanPlayingCard.tsx:110. Either amend that guidance (and its dense twin at :154) or move the examples back to writing the style in onPan.

export const doc = {
type: 'block',
exampleFor: 'createPanGesture',
name: 'createPanGesture — A draggable box without React',

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The block is named "without React", but it holds the offset in useState, builds its ref with useCallback and renders Card and Center; the page it opens says "Use the usePanGesture hook in React". Render the box in plain DOM with React only mounting it, as PanPlayingCardVanilla does, or drop "without React" from the name, display name and route before the route ships.

The usePanGesture page shows the draggable box once, in two forms side
by side: the hook and the createPanGesture factory, with the same StyleX
styles. createPanGesture's page keeps its reference and points there.
The playing card appears once, on the usePanGesture page.

The boxes and the card take user-select: none again, so a mouse drag
moves them instead of selecting their text. The usePanGesture page's
guidance now agrees with its examples: it warns against holding the
drag offset in a large component's state.
@vjeux

vjeux commented Nov 4, 2026

Copy link
Copy Markdown
Contributor Author

Fixed in aef79fd:

  • Text selection: userSelect: 'none' is back on styles.box and styles.card, so a mouse drag moves them; both tests assert it.
  • Guidance vs examples: the spec owner asked for state-driven examples, so the guidance moved. The usePanGesture Don't now warns only against holding the drag offset in a large component's state, in both forms (usePanGesture.doc.mjs:83, :154).
  • "Without React": that block is gone. The spec owner merged the pages: the usePanGesture page shows one box in two forms side by side, the hook and createPanGesture, and createPanGesture's page keeps its entry with a pointer there.

@cixzhang

cixzhang commented Nov 4, 2026

Copy link
Copy Markdown
Contributor

/approve-spec aef79fd

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved pending CI: CI has not run on this head yet; it runs once the pull request is marked ready for review and a maintainer adds the ci:run label.

#8655 — approve

The public pan (createPanGesture, usePanGesture) matches its spec, with no blocking findings.

#9928 — approve

The three earlier fixes are in (a mouse drag moves both boxes and the card, the usePanGesture guidance agrees with its examples, and the "without React" box is gone), and nothing blocks.

Whole stack — passes

A pull request lands only when it and every pull request below it are approved, and #8655 should land together with #9928, which renames and removes example routes it adds.

[Automated review]

@cixzhang

cixzhang commented Nov 5, 2026

Copy link
Copy Markdown
Contributor

/approve-spec aef79fd

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes requested: one fix to the branch, with no code change needed.

  • Regression: the stack line Stack: #8655 → #8658, #9928 no longer holds, because this branch contains neither #8658's head nor #8655's current head (each branch merged main on its own), so this pull request is reviewed on its own at 2,007 authored lines, over the 2,000-line limit; make this branch contain #8655's head (merge #8655's branch instead of main, or rebase onto it) and declare a chain that holds, such as Stack: #8655 → #9928 in both bodies, or land #8655 first.

Otherwise the public pan and both examples match the spec, and their unit, browser and docs-build checks pass at this head. Non-blocking: neither example passes axis, neither hands the release velocity to its settle as the pages' own guidance suggests, and the docs changeset's "warns only against" reads as a change to guidance that never shipped. CI has not run on this head yet.

[Automated review]

vjeux added 3 commits November 5, 2026 04:44
…s it

The pan's pages and its changeset said a finger, a mouse and a pen all
drive it. A mouse or pen drag that starts on selectable text in the
element is the browser's text selection instead, and the pan reports
nothing; with user-select: none on that text, the same drag pans. Both
pages and the changeset now say so and name user-select: none.
The branch now contains meta#8655's head, 14b0fe7, so its stack holds.
createPanGesture's usage text keeps both changes: meta#8655's sentence on
selectable text and this branch's pointer to the shared example.
The usePanGesture page and its guidance ship in the same release, so
the changeset says what the guidance warns against, not that it
narrowed.
@vjeux

vjeux commented Nov 5, 2026

Copy link
Copy Markdown
Contributor Author

Fixed in 28476ba: this branch now merges #8655's head, 14b0fe7, and both descriptions carry Stack: #8655 → #9928. The changeset now says what the guidance warns against. On the non-blocking notes: neither example passes axis, because both are free two-way drags. Both settle with a StyleX transition, which takes no starting velocity; the card reads velocity to decide whether a release throws it.

@astracat-bot astracat-bot Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved pending CI: CI has not run on this head yet. Its required checks wait for a maintainer to add the ci:run label, which lets CI run on the fork branch.

#8655 — approve

createPanGesture and usePanGesture match the public gesture-hooks spec, with no blocking findings.

#9928 — approve

The usePanGesture page now opens with the draggable box in both forms, and this branch now contains #8655's head, so the stack holds and its size is exempt. No blocking findings.

Whole stack — pass

The API, behaviour and docs are consistent across both pull requests. A pull request lands only when it and every pull request below it are approved.

Non-blocking: #8655 adds a plain-JavaScript card and two example routes that #9928 removes or renames, so landing the two together keeps those routes from shipping and then disappearing.

[Automated review]

@vjeux
vjeux marked this pull request as ready for review November 5, 2026 13:37
@cixzhang cixzhang added the ci:run A maintainer lets this outside contributor's pull request run CI (AST-030 FR17) label Nov 5, 2026
@cixzhang
cixzhang marked this pull request as draft November 5, 2026 13:58
@cixzhang
cixzhang marked this pull request as ready for review November 5, 2026 13:58

@astracat-bot astracat-bot Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved: CI passes on this head.

#8655 has merged, so this pull request now stands on its own. The usePanGesture page's two-form draggable box, the reworked playing card and the docs and route updates match the spec, with no blocking findings.

  • Non-blocking: the two playing-card example routes #8655 added are on main but not yet released, and this change removes or renames them without an alias, so landing it before the next release keeps them from shipping once and then disappearing.

[Automated review]

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved pending CI: CI is still running on this head.

#8655 has merged, so this pull request now stands on its own. The usePanGesture page's two-form draggable box, the reworked playing card and the docs and route updates match the spec, with no blocking findings.

  • Non-blocking: the two playing-card example routes #8655 added are on main but in no stable release yet, and this change removes or renames them without an alias, so landing it before the next release keeps them from shipping once and then disappearing.

[Automated review]

@cixzhang
cixzhang merged commit df15de7 into meta:main Nov 5, 2026
66 checks passed
@vjeux
vjeux deleted the uikit/f2-pan-examples branch November 5, 2026 18:08

This branch was successfully deployed

1 active deployment
Preview — 411dd2a6 Deployed Nov 5, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci:run A maintainer lets this outside contributor's pull request run CI (AST-030 FR17) CLA Signed This label is managed by the Meta Open Source bot. needs:design-review Affects visuals — Design should review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants