Repository navigation
docs(core): open the pan hook pages with a minimal draggable box - #9928
Conversation
…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.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
AI review status for this pull request.
|
PR Analysis Report🔎 Preview ·
|
|
/approve-spec b049e4c |
There was a problem hiding this comment.
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)}> |
There was a problem hiding this comment.
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.
b049e4c to
e85acb1
Compare
There was a problem hiding this comment.
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]
e85acb1 to
8c8586c
Compare
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.
8c8586c to
2781e8e
Compare
|
/approve-spec 2781e8e |
There was a problem hiding this comment.
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 tostyles.boxandstyles.card. - The
usePanGesturepage says not to set React state on everychangedevent (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,CardandCenter(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'}, |
There was a problem hiding this comment.
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}); |
There was a problem hiding this comment.
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', |
There was a problem hiding this comment.
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.
|
Fixed in aef79fd:
|
|
/approve-spec aef79fd |
There was a problem hiding this comment.
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]
|
/approve-spec aef79fd |
There was a problem hiding this comment.
Changes requested: one fix to the branch, with no code change needed.
- Regression: the stack line
Stack: #8655 → #8658, #9928no longer holds, because this branch contains neither #8658's head nor #8655's current head (each branch mergedmainon 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 ofmain, or rebase onto it) and declare a chain that holds, such asStack: #8655 → #9928in 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]
…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 usePanGesture page and its guidance ship in the same release, so the changeset says what the guidance warns against, not that it narrowed.
|
Fixed in 28476ba: this branch now merges #8655's head, 14b0fe7, and both descriptions carry |
There was a problem hiding this comment.
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]
There was a problem hiding this comment.
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
mainbut 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]
There was a problem hiding this comment.
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
mainbut 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]
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-107FR1 and FR6.architecture:public-component-apiINV22 asks for both APIs, the hook and itscreate…twin, not two example pages.Correction
usePanGesturepage opens with "A draggable box" in two forms side by side: one card made withusePanGesture, one withcreatePanGesture. Each card names its API, and both share one set of StyleX styles.Buttondiscards it from the keyboard, anduseAnnouncenames each discard.--duration-mediumwith--ease-move, the neutral step nearest the old 300 ms. The fly-off takes--duration-exitwith--ease-exit.--color-neutral) in the example's own StyleX, so the card reads in light and dark themes. The cards takeuser-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, theusePanGestureguidance now warns only against holding the drag offset in a large component's state.Evidence
Scope
Testing
Local gates at 28476ba, on #8655's head 14b0fe7.
createPanGesture's usage line: feat(core): createPanGesture and usePanGesture report a drag as values (spec:AST-107 FR1, FR6) #8655's sentence on selectable text and this branch's pointer to the shared example. This branch's own diff against feat(core): createPanGesture and usePanGesture report a drag as values (spec:AST-107 FR1, FR6) #8655 is otherwise unchanged: the same 13 files, +738 −530.pnpm build: the CLI typechecks. The pan tests with the sandbox route manifest and the touch-support bundle passed, 31 of 31.routes.lock.jsonmatches the generator.check:knowledgeandcheck:changesets: clean.node scripts/pre-review.mjs --base 14b0fe714f: no findings, 1,268 authored lines.Earlier evidence, at aef79fd (the same examples):
pnpm check:knowledge: clean.routes.lock.jsonmatchesnode 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/coreand@astryxdesign/cli.Rubric scorecards (template rubric 1.4)
Remaining deductions are intentional. The wash,
user-selectand the drag, spring and throw styles have no Astryx prop. The advanced card keeps its keyboard path, announcement and throw guards at 147 lines.