Skip to content
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changeset/cli-discover-page-control.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@astryxdesign/cli': patch
---

[feat] `astryx discover` lists the experimental PageControl component from `@astryxdesign/lab`.

@vjeux
7 changes: 7 additions & 0 deletions .changeset/core-internal-entries-page-control.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@astryxdesign/core': patch
---

[chore] Internal: `@astryxdesign/core/internal/touch` also re-exports an element's shared animator, the Reduce Motion cross-fade, and the coarse-pointer touch hit area's hook and layer, for Lab's PageControl. It is an internal entry reserved for Astryx's own packages, outside the public API.

@vjeux
76 changes: 76 additions & 0 deletions apps/storybook/stories/PageControl.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
// Copyright (c) Meta Platforms, Inc. and affiliates.

import {useState} from 'react';
import type {Meta, StoryObj} from '@storybook/react';
import * as stylex from '@stylexjs/stylex';
import {PageControl} from '@astryxdesign/lab';
import {
colorVars,
radiusVars,
spacingVars,
typographyVars,
} from '@astryxdesign/core/theme/tokens.stylex';

const styles = stylex.create({
stack: {
display: 'flex',
flexDirection: 'column',
alignItems: 'center',
gap: spacingVars['--spacing-3'],
padding: spacingVars['--spacing-6'],
fontFamily: typographyVars['--font-family-body'],
},
page: {
width: 280,
height: 160,
display: 'grid',
placeItems: 'center',
borderRadius: radiusVars['--radius-element'],
backgroundColor: colorVars['--color-background-muted'],
color: colorVars['--color-text-primary'],
fontSize: 20,
fontWeight: 600,
},
});

const meta: Meta<typeof PageControl> = {
title: 'Lab/PageControl',
component: PageControl,
parameters: {layout: 'centered'},
};

export default meta;
type Story = StoryObj<typeof PageControl>;

function Paged({totalPages, start = 1}: {totalPages: number; start?: number}) {
const [page, setPage] = useState(start);
return (
<div {...stylex.props(styles.stack)}>
<div {...stylex.props(styles.page)} data-testid="page">
Page {page}
</div>
<PageControl totalPages={totalPages} page={page} onChange={setPage} />
</div>
);
}

export const Default: Story = {
render: () => <Paged totalPages={5} start={3} />,
};

export const ManyPages: Story = {
name: 'Many Pages (50)',
render: () => <Paged totalPages={50} start={26} />,
};

export const SinglePageHidden: Story = {
name: 'Single Page (hidesForSinglePage)',
render: () => (
<PageControl
totalPages={1}
page={1}
onChange={() => {}}
hidesForSinglePage
/>
),
};
5 changes: 5 additions & 0 deletions internal/shadcn-registry/routes.lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -632,6 +632,11 @@
"path": "components/lab/navigation-stack",
"aliases": []
},
{
"name": "component-lab-page-control",
"path": "components/lab/page-control",
"aliases": []
},
{
"name": "component-lab-radial-chart",
"path": "components/lab/radial-chart",
Expand Down
4 changes: 4 additions & 0 deletions packages/cli/assets/discover/official-packages.json
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,10 @@
"kind": "component",
"name": "NavigationStack"
},
{
"kind": "component",
"name": "PageControl"
},
{
"kind": "component",
"name": "RadialChart"
Expand Down
22 changes: 22 additions & 0 deletions packages/core/src/internal/touch.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,28 @@ describe('internal/touch', () => {
expect(entry.navigation).toBeDefined();
});

it("re-exports by name what Lab's PageControl also reads", async () => {
const entry: Record<string, unknown> = await import('./touch');
const animator = await import('../motion/animator');
const reduced = await import('../motion/reducedMotion');
const hitArea = await import('../utils/touchHitArea');
const hitAreaStyles = await import('../utils/touchHitArea.stylex');
expect(entry.animatorFor).toBe(animator.animatorFor);
expect(entry.reducedMotionFade).toBe(reduced.reducedMotionFade);
expect(entry.useTouchHitArea).toBe(hitArea.useTouchHitArea);
expect(entry.touchHitAreaStyles).toBe(hitAreaStyles.touchHitAreaStyles);
// An identity check passes when both sides are undefined, so each name
// must also be defined.
for (const name of [
'animatorFor',
'reducedMotionFade',
'useTouchHitArea',
]) {
expect(typeof entry[name], name).toBe('function');
}
expect(entry.touchHitAreaStyles).toBeDefined();
});

it('attaches no window or document listeners when it loads', async () => {
vi.resetModules();
const onWindow = vi.spyOn(window, 'addEventListener');
Expand Down
13 changes: 10 additions & 3 deletions packages/core/src/internal/touch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
* @file touch.ts
* @input The gesture core: the arena, the recognizers and their geometry.
* Also the pan, the motion engine and math, and the touch-presentation,
* direction and focus helpers that Lab components read
* direction, focus and hit-area helpers that Lab components read
* @output `@astryxdesign/core/internal/touch`: the gesture core's primitives
* and the motion, touch-presentation, direction and focus modules for Lab
* components, re-exported by name
* and the motion, touch-presentation, direction, focus and hit-area
* modules for Lab components, re-exported by name
* @position An internal entry reserved for Astryx's own packages:
* undocumented, outside the public API and its compatibility promise
* (spec:AST-017 FR21), versioned in lockstep with Core, and allowed only in
Expand Down Expand Up @@ -95,3 +95,10 @@ export {
} from '../motion/uikit/springs';
export {focusForLastInput, isFocusLost} from '../utils/focusReturn';
export {useInteractionModalityTracking} from '../utils/interactionModality';

// Lab's PageControl also reads an element's shared animator, the Reduce
// Motion cross-fade, and the touch hit area's hook and layer.
export {animatorFor} from '../motion/animator';
export {reducedMotionFade} from '../motion/reducedMotion';
export {useTouchHitArea} from '../utils/touchHitArea';
export {touchHitAreaStyles} from '../utils/touchHitArea.stylex';
74 changes: 74 additions & 0 deletions packages/lab/src/PageControl/PageControl.doc.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
// Copyright (c) Meta Platforms, Inc. and affiliates.

/** @type {import('@astryxdesign/cli/authoring').ComponentDoc} */

export const docs = {
name: 'PageControl',
displayName: 'Page Control',
category: 'Navigation',
keywords: [
'page control',
'page indicator',
'pager dots',
'dots',
'carousel dots',
'onboarding',
'paging',
],
description:
'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.',
props: [
{
name: 'totalPages',
type: 'number',
description: 'Number of pages.',
required: true,
},
{
name: 'page',
type: 'number',
description: 'Current page number (1-based). Page 1 is the first page.',
required: true,
},
{
name: 'onChange',
type: '(page: number) => void',
description:
'Called with the page, 1-based, that 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 page together.',
required: true,
},
{
name: 'label',
type: 'string',
description:
'Names the control for assistive technology. Defaults to "Page indicators", localized.',
},
{
name: 'hidesForSinglePage',
type: 'boolean',
description: 'Render nothing when there is only one page.',
default: 'false',
},
],
usage: {
description:
'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 page in step with the view in both directions.',
bestPractices: [
{
guidance: true,
description:
'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.',
},
{
guidance: true,
description:
'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.',
},
{
guidance: false,
description:
"Don't use it for long lists of results (use Pagination) or for choosing between views (use SegmentedControl or TabList).",
},
],
},
};
Loading
Loading