@astryxdesign/cli 0.7.10-canary.d9ea179 → 0.7.10-canary.f88d572

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,14 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ /** @type {import('@astryxdesign/cli/authoring').TemplateDoc} */
4
+ export const doc = {
5
+ type: 'block',
6
+ exampleFor: 'useSnapPaging',
7
+ name: 'useSnapPaging — Onboarding Pages',
8
+ displayName: 'useSnapPaging — Onboarding Pages',
9
+ description:
10
+ "Onboarding cards in a Carousel with hasSnap={useSnapPaging()}: under a finger or a trackpad swipe, each flick moves one view and rests on a card's start edge. A switch picks one view or one card per flick through the hook's pages option.",
11
+ isReady: true,
12
+ aspectRatio: 4 / 3,
13
+ componentsUsed: ['Carousel', 'Card', 'Layout', 'Switch', 'Text'],
14
+ };
@@ -0,0 +1,49 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ 'use client';
4
+
5
+ import {useState} from 'react';
6
+ import {Card} from '@astryxdesign/core/Card';
7
+ import {Carousel} from '@astryxdesign/core/Carousel';
8
+ import {Stack} from '@astryxdesign/core/Layout';
9
+ import {useSnapPaging} from '@astryxdesign/core/SnapPaging';
10
+ import {Switch} from '@astryxdesign/core/Switch';
11
+ import {Text} from '@astryxdesign/core/Text';
12
+
13
+ const SCREENS = [
14
+ {title: 'Welcome', body: 'Swipe to see what is new.'},
15
+ {title: 'Shared albums', body: 'Invite friends to add their photos.'},
16
+ {title: 'Memories', body: 'See a day from years ago.'},
17
+ {title: 'Search', body: 'Find a photo by what is in it.'},
18
+ {title: 'All set', body: 'Your library is ready.'},
19
+ ];
20
+
21
+ export default function CarouselSnapPaging() {
22
+ const [isOneCard, setIsOneCard] = useState(false);
23
+ // A flick moves one view, or one card with {pages: 'item'}.
24
+ const paging = useSnapPaging({pages: isOneCard ? 'item' : 'view'});
25
+
26
+ return (
27
+ <Stack direction="vertical" gap={3} style={{maxWidth: 520, padding: 8}}>
28
+ <Switch
29
+ label="One card per flick"
30
+ value={isOneCard}
31
+ onChange={setIsOneCard}
32
+ />
33
+ <Carousel gap={2} hasSnap={paging} aria-label="Onboarding">
34
+ {SCREENS.map(screen => (
35
+ <Card key={screen.title} width={220} minHeight={160}>
36
+ <Stack direction="vertical" gap={1}>
37
+ <Text type="body" weight="bold">
38
+ {screen.title}
39
+ </Text>
40
+ <Text type="body" color="secondary">
41
+ {screen.body}
42
+ </Text>
43
+ </Stack>
44
+ </Card>
45
+ ))}
46
+ </Carousel>
47
+ </Stack>
48
+ );
49
+ }
@@ -0,0 +1,14 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ /** @type {import('@astryxdesign/cli/authoring').TemplateDoc} */
4
+ export const doc = {
5
+ type: 'block',
6
+ exampleFor: 'createDragToSnapPoints',
7
+ name: 'createDragToSnapPoints — Playing card in plain JavaScript',
8
+ displayName: 'createDragToSnapPoints — Playing card in plain JavaScript',
9
+ description:
10
+ 'The three-place playing card from the useDragToSnapPoints example, built in plain JavaScript with createDragToSnapPoints: a sideways drag settles it on the nearest place or the next after a flick, buttons settle it from the keyboard, and a live region announces the place. React only mounts it.',
11
+ isReady: true,
12
+ aspectRatio: 4 / 3,
13
+ componentsUsed: [],
14
+ };
@@ -0,0 +1,110 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ 'use client';
4
+
5
+ import {createDragToSnapPoints} from '@astryxdesign/core';
6
+
7
+ const PLACES = ['Hand', 'Table', 'Discard pile'];
8
+
9
+ /**
10
+ * A card that snaps between three places, in plain JavaScript: no React
11
+ * below this line. It returns a function that takes it down again.
12
+ */
13
+ function mountCard(table: HTMLElement, buttons: HTMLElement) {
14
+ const card = document.createElement('div');
15
+ card.textContent = 'Q\u2665';
16
+ Object.assign(card.style, {
17
+ width: '96px',
18
+ height: '136px',
19
+ display: 'grid',
20
+ placeItems: 'center',
21
+ font: 'bold 36px system-ui, sans-serif',
22
+ // The theme's surface and text, so the card reads in light and dark.
23
+ borderRadius: 'var(--radius-container)',
24
+ backgroundColor: 'var(--color-background-surface)',
25
+ color: 'var(--color-text-primary)',
26
+ boxShadow: '0 2px 8px var(--color-shadow)',
27
+ touchAction: 'none',
28
+ cursor: 'grab',
29
+ userSelect: 'none',
30
+ });
31
+ table.append(card);
32
+ const status = document.createElement('div');
33
+ status.setAttribute('aria-live', 'polite');
34
+ Object.assign(status.style, {position: 'absolute', clip: 'rect(0 0 0 0)'});
35
+ table.append(status);
36
+
37
+ // The places run in reading order, so leftward in a right-to-left layout.
38
+ // There the snap points are negative, so they sort the other way round.
39
+ const steps = [0, 110, 220];
40
+ const isRtl = getComputedStyle(table).direction === 'rtl';
41
+ const placeAt = (index: number) => (isRtl ? steps.length - 1 - index : index);
42
+ const snap = createDragToSnapPoints(card, {
43
+ axis: 'x',
44
+ snapPoints: isRtl ? steps.map(step => -step) : steps,
45
+ onSettle: index => {
46
+ status.textContent = `The card is on the ${PLACES[placeAt(index)].toLowerCase()}.`;
47
+ },
48
+ });
49
+ const controls = PLACES.map((name, index) => {
50
+ const button = document.createElement('button');
51
+ button.type = 'button';
52
+ button.textContent = name;
53
+ // The Astryx reset removes a native button's own look, so these take the
54
+ // theme's secondary button look.
55
+ Object.assign(button.style, {
56
+ height: 'var(--size-element-md)',
57
+ paddingInline: 'var(--spacing-3)',
58
+ border: 'none',
59
+ borderRadius: 'var(--radius-element)',
60
+ backgroundColor: 'var(--color-neutral)',
61
+ color: 'var(--color-text-primary)',
62
+ font: 'inherit',
63
+ fontSize: 'var(--text-label-size)',
64
+ fontWeight: 'var(--font-weight-medium)',
65
+ cursor: 'pointer',
66
+ });
67
+ button.addEventListener('click', () => snap.settleTo(placeAt(index)));
68
+ buttons.append(button);
69
+ return button;
70
+ });
71
+ return () => {
72
+ snap.destroy();
73
+ for (const button of controls) {
74
+ button.remove();
75
+ }
76
+ card.remove();
77
+ status.remove();
78
+ };
79
+ }
80
+
81
+ /**
82
+ * Mounts the card when the wrapper attaches, and takes it down when it
83
+ * detaches: its cleanup is the callback ref's.
84
+ */
85
+ function mountTable(wrapper: HTMLDivElement | null) {
86
+ if (wrapper == null) {
87
+ return undefined;
88
+ }
89
+ const table = wrapper.firstElementChild as HTMLElement;
90
+ const buttons = wrapper.lastElementChild as HTMLElement;
91
+ return mountCard(table, buttons);
92
+ }
93
+
94
+ export default function DragToSnapPointsCardVanilla() {
95
+ return (
96
+ <div
97
+ ref={mountTable}
98
+ style={{display: 'grid', gap: 16, padding: 16, maxWidth: 380}}>
99
+ <div
100
+ style={{
101
+ position: 'relative',
102
+ height: 150,
103
+ display: 'flex',
104
+ alignItems: 'center',
105
+ }}
106
+ />
107
+ <div style={{display: 'flex', gap: 8}} />
108
+ </div>
109
+ );
110
+ }
@@ -0,0 +1,21 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ /** @type {import('@astryxdesign/cli/authoring').TemplateDoc} */
4
+ export const doc = {
5
+ type: 'block',
6
+ exampleFor: 'useDragToSnapPoints',
7
+ name: 'useDragToSnapPoints — Playing card on three places',
8
+ displayName: 'useDragToSnapPoints — Playing card on three places',
9
+ description:
10
+ 'A playing card that a sideways drag moves between three places: a slow release settles on the nearest, a quick flick carries to the next, and a release moving back returns where it started. Buttons settle it from the keyboard, and the new place is announced. Built only on the public useDragToSnapPoints hook.',
11
+ isReady: true,
12
+ aspectRatio: 4 / 3,
13
+ componentsUsed: [
14
+ 'Card',
15
+ 'Button',
16
+ 'Layout',
17
+ 'Text',
18
+ 'VisuallyHidden',
19
+ 'useDragToSnapPoints',
20
+ ],
21
+ };
@@ -0,0 +1,74 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ 'use client';
4
+
5
+ import {useLayoutEffect, useRef, useState} from 'react';
6
+ import {Button} from '@astryxdesign/core/Button';
7
+ import {Card} from '@astryxdesign/core/Card';
8
+ import {useDragToSnapPoints} from '@astryxdesign/core/hooks';
9
+ import {HStack, VStack} from '@astryxdesign/core/Layout';
10
+ import {Text} from '@astryxdesign/core/Text';
11
+ import {VisuallyHidden} from '@astryxdesign/core/VisuallyHidden';
12
+
13
+ const PLACES = ['Hand', 'Table', 'Discard pile'];
14
+ /** How far along the row each place sits, in px from where the card rests. */
15
+ const STEPS = [0, 110, 220];
16
+
17
+ export default function DragToSnapPointsCard() {
18
+ const ref = useRef<HTMLDivElement>(null);
19
+ const [place, setPlace] = useState(0);
20
+ // The places run in reading order, so leftward in a right-to-left layout.
21
+ // There the snap points are negative, so they sort the other way round.
22
+ // The direction is the one the card renders in.
23
+ const [isRtl, setIsRtl] = useState(false);
24
+ // Reads the direction the browser computed for the card once it is laid
25
+ // out.
26
+ useLayoutEffect(() => {
27
+ if (ref.current != null) {
28
+ setIsRtl(getComputedStyle(ref.current).direction === 'rtl');
29
+ }
30
+ }, []);
31
+ const placeAt = (index: number) => (isRtl ? STEPS.length - 1 - index : index);
32
+ const {settleTo} = useDragToSnapPoints(ref, {
33
+ axis: 'x',
34
+ snapPoints: isRtl ? STEPS.map(step => -step) : STEPS,
35
+ onSettle: index => setPlace(placeAt(index)),
36
+ });
37
+
38
+ return (
39
+ <VStack gap={4} style={{maxWidth: 380, padding: 16}}>
40
+ <Text type="body">
41
+ Drag the card sideways and let go: it settles on the nearest place, or
42
+ the next one after a quick flick.
43
+ </Text>
44
+ <HStack gap={2} style={{height: 150, alignItems: 'center'}}>
45
+ <Card
46
+ ref={ref}
47
+ width={96}
48
+ minHeight={136}
49
+ style={{touchAction: 'none', cursor: 'grab', userSelect: 'none'}}
50
+ aria-label={`Queen of hearts, on the ${PLACES[place].toLowerCase()}`}>
51
+ <VStack gap={1} hAlign="center" style={{paddingBlock: 32}}>
52
+ <Text type="display-2" weight="bold">
53
+ Q
54
+ </Text>
55
+ <Text type="display-3">{'\u2665'}</Text>
56
+ </VStack>
57
+ </Card>
58
+ </HStack>
59
+ <HStack gap={2}>
60
+ {PLACES.map((name, index) => (
61
+ <Button
62
+ key={name}
63
+ label={name}
64
+ variant={index === place ? 'primary' : 'secondary'}
65
+ onClick={() => settleTo(placeAt(index))}
66
+ />
67
+ ))}
68
+ </HStack>
69
+ <VisuallyHidden as="div" aria-live="polite">
70
+ {`The card is on the ${PLACES[place].toLowerCase()}.`}
71
+ </VisuallyHidden>
72
+ </VStack>
73
+ );
74
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@astryxdesign/cli",
3
- "version": "0.7.10-canary.d9ea179",
3
+ "version": "0.7.10-canary.f88d572",
4
4
  "displayName": "CLI",
5
5
  "description": "Scaffold projects, browse templates, generate themes, and get agent-ready docs from the command line.",
6
6
  "author": "Meta Open Source",
@@ -124,10 +124,10 @@
124
124
  "zod": "^4.4.3"
125
125
  },
126
126
  "peerDependencies": {
127
- "@astryxdesign/charts": "0.7.10-canary.d9ea179",
128
- "@astryxdesign/core": "0.7.10-canary.d9ea179",
129
- "@astryxdesign/lab": "0.7.10-canary.d9ea179",
130
- "@astryxdesign/theme-neutral": "0.7.10-canary.d9ea179"
127
+ "@astryxdesign/charts": "0.7.10-canary.f88d572",
128
+ "@astryxdesign/core": "0.7.10-canary.f88d572",
129
+ "@astryxdesign/lab": "0.7.10-canary.f88d572",
130
+ "@astryxdesign/theme-neutral": "0.7.10-canary.f88d572"
131
131
  },
132
132
  "peerDependenciesMeta": {
133
133
  "@astryxdesign/charts": {
@@ -144,10 +144,10 @@
144
144
  }
145
145
  },
146
146
  "devDependencies": {
147
- "@astryxdesign/charts": "0.7.10-canary.d9ea179",
148
- "@astryxdesign/core": "0.7.10-canary.d9ea179",
149
- "@astryxdesign/lab": "0.7.10-canary.d9ea179",
150
- "@astryxdesign/theme-neutral": "0.7.10-canary.d9ea179",
147
+ "@astryxdesign/charts": "0.7.10-canary.f88d572",
148
+ "@astryxdesign/core": "0.7.10-canary.f88d572",
149
+ "@astryxdesign/lab": "0.7.10-canary.f88d572",
150
+ "@astryxdesign/theme-neutral": "0.7.10-canary.f88d572",
151
151
  "@heroicons/react": "^2.2.0",
152
152
  "@stylexjs/stylex": "^0.19.0",
153
153
  "@types/babel__core": "^7.20.5",