Skip to content

Commit 288574e

Browse files
committed
feat(lab): PageControl, UIPageControl's indicators: a tap steps a page, a finger scrubs, every pointer pages
PageControl is a row of page indicators, the current one highlighted, that pages like UIPageControl on iOS 26 (measured on the iOS 26.2 simulator): - What it draws: 9.67 px indicators 8 px apart, at most ten slots; with more pages the row is a window whose edge slots shrink and slide on UIKit's spring; the old indicator fades out after a change. - How it pages: the app owns the page (`value`, `onChange`). A tap on either side of the current indicator asks for the next or the previous page (mirrored in RTL); a finger that travels 16 px scrubs to the indicator under it and jogs past a window's edge; a press held 155 ms shows the held platter and dims the others. A vertical swipe stays the page's scroll. - Every pointer: with a mouse or a pen a click steps one page toward its side and a drag scrubs; the platter, the dimming, the window's slide and the fades stay the touch presentation, on a coarse pointer. - Reduce Motion: every change fades in 200 ms, nothing travels. - Accessibility: one adjustable `slider` ("Page 3 of 5"); the arrow keys, Home and End change the page. Under a coarse pointer an invisible hit area grows the control toward 44 px, as far as its neighbours allow. - A mouse scrub on a cropped long row holds the row still until the lift, so the page stays the dot under the pointer. Its measured values live in its own table (pageControlTable.ts): only PageControl reads them, so they stay in Lab. It reaches Core's pan and tap recognizers, each element's shared animator, the Reduce Motion cross-fade, the hit-area watcher and the touch presentation through Core's internal touch entry. `astryx discover` lists it, and the registry has its route. Its timing holds on a loaded runner. A jog step commits in the timer's own task (`flushSync`): a render scheduled after it could wait behind a busy page's other tasks past the next step, and two steps would show as one. A jog step counts from when the previous one was due, so a timer that runs late does not slow the run (after a stall longer than a step, from the late step: no burst). The window's slide starts 50 ms after the change at a start time on the document timeline, for the strip and every dot, which a busy main thread cannot push back as it would a timer. The held-platter proof dates each read on the page's clock from the touch, the clock the 155 ms runs on, and the slide proof dates the change at the lift's first event, the task the change commits in, not by the next frame or the end of that task. The slide's storyboard arms the harness's hold before the tap (`armHold`), so the page holds the motion as it starts, however late the test reads it. The RTL scrub holds the finger 6 px past the content's edge, where the jog steps about once a second, so exactly one step comes before the lift with hundreds of milliseconds to spare. The unit tests' media-query stub answers from the case's pointer at every read: Core's gesture host keeps the `(pointer: coarse)` list it asked for when the document's host was created, so a stub that froze its answer let an earlier mouse case's pointer reach a later touch case (that case failed after any mouse case, and passed alone).
1 parent 1ea5d3e commit 288574e

14 files changed

Lines changed: 3667 additions & 0 deletions

File tree

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
'@astryxdesign/cli': patch
3+
---
4+
5+
[feat] `astryx discover` lists the experimental PageControl component from `@astryxdesign/lab`.
6+
7+
@vjeux
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
// Copyright (c) Meta Platforms, Inc. and affiliates.
2+
3+
import {useState} from 'react';
4+
import type {Meta, StoryObj} from '@storybook/react';
5+
import * as stylex from '@stylexjs/stylex';
6+
import {PageControl} from '@astryxdesign/lab';
7+
import {
8+
colorVars,
9+
radiusVars,
10+
spacingVars,
11+
typographyVars,
12+
} from '@astryxdesign/core/theme/tokens.stylex';
13+
14+
const styles = stylex.create({
15+
stack: {
16+
display: 'flex',
17+
flexDirection: 'column',
18+
alignItems: 'center',
19+
gap: spacingVars['--spacing-3'],
20+
padding: spacingVars['--spacing-6'],
21+
fontFamily: typographyVars['--font-family-body'],
22+
},
23+
page: {
24+
width: 280,
25+
height: 160,
26+
display: 'grid',
27+
placeItems: 'center',
28+
borderRadius: radiusVars['--radius-element'],
29+
backgroundColor: colorVars['--color-background-muted'],
30+
color: colorVars['--color-text-primary'],
31+
fontSize: 20,
32+
fontWeight: 600,
33+
},
34+
});
35+
36+
const meta: Meta<typeof PageControl> = {
37+
title: 'Lab/PageControl',
38+
component: PageControl,
39+
parameters: {layout: 'centered'},
40+
};
41+
42+
export default meta;
43+
type Story = StoryObj<typeof PageControl>;
44+
45+
function Paged({count, start = 0}: {count: number; start?: number}) {
46+
const [page, setPage] = useState(start);
47+
return (
48+
<div {...stylex.props(styles.stack)}>
49+
<div {...stylex.props(styles.page)} data-testid="page">
50+
Page {page + 1}
51+
</div>
52+
<PageControl count={count} value={page} onChange={setPage} />
53+
</div>
54+
);
55+
}
56+
57+
export const Default: Story = {
58+
render: () => <Paged count={5} start={2} />,
59+
};
60+
61+
export const ManyPages: Story = {
62+
name: 'Many Pages (50)',
63+
render: () => <Paged count={50} start={25} />,
64+
};
65+
66+
export const SinglePageHidden: Story = {
67+
name: 'Single Page (hidesForSinglePage)',
68+
render: () => (
69+
<PageControl count={1} value={0} onChange={() => {}} hidesForSinglePage />
70+
),
71+
};

‎internal/shadcn-registry/routes.lock.json‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -627,6 +627,11 @@
627627
"path": "components/lab/mobile-tokenizer",
628628
"aliases": []
629629
},
630+
{
631+
"name": "component-lab-page-control",
632+
"path": "components/lab/page-control",
633+
"aliases": []
634+
},
630635
{
631636
"name": "component-lab-radial-chart",
632637
"path": "components/lab/radial-chart",

‎packages/cli/assets/discover/official-packages.json‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,10 @@
148148
"kind": "component",
149149
"name": "MobileTokenizer"
150150
},
151+
{
152+
"kind": "component",
153+
"name": "PageControl"
154+
},
151155
{
152156
"kind": "component",
153157
"name": "RadialChart"
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
// Copyright (c) Meta Platforms, Inc. and affiliates.
2+
3+
/** @type {import('@astryxdesign/cli/authoring').ComponentDoc} */
4+
5+
export const docs = {
6+
name: 'PageControl',
7+
displayName: 'Page Control',
8+
category: 'Navigation',
9+
keywords: [
10+
'page control',
11+
'page indicator',
12+
'pager dots',
13+
'dots',
14+
'carousel dots',
15+
'onboarding',
16+
'paging',
17+
],
18+
description:
19+
'A row of page indicators under a paging view, as on iOS: one dot per page, the current one highlighted. A tap or a click to either side of the current dot moves one page that way, and sliding a finger or dragging the mouse across the dots scrubs straight to the page under it. Under a finger (any touch device, iOS and Android alike), with more than ten pages the row is a window whose edge dots shrink to show there is more, and a held finger shows a platter behind the dots; with a mouse a long row is cropped to the control. Experimental: lands in lab first.',
20+
props: [
21+
{
22+
name: 'count',
23+
type: 'number',
24+
description: 'Number of pages.',
25+
required: true,
26+
},
27+
{
28+
name: 'value',
29+
type: 'number',
30+
description: 'The current page, 0-based.',
31+
required: true,
32+
},
33+
{
34+
name: 'onChange',
35+
type: '(page: number) => void',
36+
description:
37+
'Called with the page a tap, a click, a scrub, an arrow key, Home, End or an assistive technology asks for; a scrub calls it each time the page under the pointer changes, so a quick sweep can skip a page. Update the paging view and value together.',
38+
required: true,
39+
},
40+
{
41+
name: 'label',
42+
type: 'string',
43+
description:
44+
'Names the control for assistive technology. Defaults to "Page indicators", localized.',
45+
},
46+
{
47+
name: 'hidesForSinglePage',
48+
type: 'boolean',
49+
description: 'Render nothing when there is only one page.',
50+
default: 'false',
51+
},
52+
],
53+
usage: {
54+
description:
55+
'Use PageControl below a paging view, such as a Carousel with `hasSnap` or onboarding screens, to show how many pages there are and which one is showing. Keep its value in step with the view in both directions.',
56+
bestPractices: [
57+
{
58+
guidance: true,
59+
description:
60+
'Pair it with a view that pages by swipe: the control is a secondary way to move and the main way to see where you are.',
61+
},
62+
{
63+
guidance: true,
64+
description:
65+
'Keep pages few enough to count at a glance; past ten the row stays a fixed width, shows a window of them and scrolls as the page changes.',
66+
},
67+
{
68+
guidance: false,
69+
description:
70+
"Don't use it for long lists of results (use Pagination) or for choosing between views (use SegmentedControl or TabList).",
71+
},
72+
],
73+
},
74+
};

0 commit comments

Comments
 (0)