@astryxdesign/cli 0.7.10-canary.fe949d4 → 0.7.10-canary.fef4d91
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.
- package/assets/discover/official-packages.json +4 -0
- package/assets/templates/blocks/components/Carousel/CarouselSnapPaging.doc.mjs +14 -0
- package/assets/templates/blocks/components/Carousel/CarouselSnapPaging.tsx +49 -0
- package/assets/templates/blocks/components/MultiSelector/useMultiComboboxHookUsage.doc.mjs +23 -0
- package/assets/templates/blocks/components/MultiSelector/useMultiComboboxHookUsage.tsx +164 -0
- package/assets/templates/blocks/components/createDragToSnapPoints/DragToSnapPointsCardVanilla.doc.mjs +14 -0
- package/assets/templates/blocks/components/createDragToSnapPoints/DragToSnapPointsCardVanilla.tsx +110 -0
- package/assets/templates/blocks/components/useDragToSnapPoints/DragToSnapPointsCard.doc.mjs +21 -0
- package/assets/templates/blocks/components/useDragToSnapPoints/DragToSnapPointsCard.tsx +74 -0
- package/package.json +9 -9
|
@@ -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,23 @@
|
|
|
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: 'useMultiCombobox',
|
|
7
|
+
name: 'useMultiCombobox — Issue Labels',
|
|
8
|
+
displayName: 'useMultiCombobox — Issue Labels',
|
|
9
|
+
description:
|
|
10
|
+
'A Labels field built on useMultiCombobox: typing filters the labels, the arrow keys move the active option while focus stays in the field, Enter or a click toggles a label and the list stays open, and selected labels show as removable tokens above the field.',
|
|
11
|
+
isReady: true,
|
|
12
|
+
aspectRatio: 4 / 3,
|
|
13
|
+
icons: {CheckIcon: 'check'},
|
|
14
|
+
componentsUsed: [
|
|
15
|
+
'MultiSelector',
|
|
16
|
+
'Card',
|
|
17
|
+
'TextInput',
|
|
18
|
+
'Item',
|
|
19
|
+
'Icon',
|
|
20
|
+
'Token',
|
|
21
|
+
'Layout',
|
|
22
|
+
],
|
|
23
|
+
};
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
|
|
3
|
+
'use client';
|
|
4
|
+
|
|
5
|
+
import {useId, useRef, useState} from 'react';
|
|
6
|
+
import {CheckIcon} from '@heroicons/react/24/outline';
|
|
7
|
+
import {Card} from '@astryxdesign/core/Card';
|
|
8
|
+
import {useAnnounce} from '@astryxdesign/core/hooks';
|
|
9
|
+
import {Icon} from '@astryxdesign/core/Icon';
|
|
10
|
+
import {Item} from '@astryxdesign/core/Item';
|
|
11
|
+
import {HStack, VStack} from '@astryxdesign/core/Layout';
|
|
12
|
+
import {useMultiCombobox} from '@astryxdesign/core/MultiSelector';
|
|
13
|
+
import {TextInput} from '@astryxdesign/core/TextInput';
|
|
14
|
+
import {Token} from '@astryxdesign/core/Token';
|
|
15
|
+
import {isImeKeyEvent} from '@astryxdesign/core/utils';
|
|
16
|
+
|
|
17
|
+
const LABELS = [
|
|
18
|
+
{value: 'bug', label: 'Bug'},
|
|
19
|
+
{value: 'docs', label: 'Documentation'},
|
|
20
|
+
{value: 'a11y', label: 'Accessibility'},
|
|
21
|
+
{value: 'perf', label: 'Performance'},
|
|
22
|
+
{value: 'good-first-issue', label: 'Good first issue'},
|
|
23
|
+
];
|
|
24
|
+
|
|
25
|
+
function filterLabels(query: string) {
|
|
26
|
+
const needle = query.trim().toLowerCase();
|
|
27
|
+
return LABELS.filter(item => item.label.toLowerCase().includes(needle));
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export default function UseMultiComboboxHookUsage() {
|
|
31
|
+
const listboxId = useId();
|
|
32
|
+
const inputRef = useRef<HTMLInputElement>(null);
|
|
33
|
+
const [query, setQuery] = useState('');
|
|
34
|
+
const [isOpen, setIsOpen] = useState(false);
|
|
35
|
+
const [selected, setSelected] = useState<string[]>(['bug']);
|
|
36
|
+
const matches = filterLabels(query);
|
|
37
|
+
const announce = useAnnounce({hasReplace: true});
|
|
38
|
+
|
|
39
|
+
const toggle = (value: string) =>
|
|
40
|
+
setSelected(current =>
|
|
41
|
+
current.includes(value)
|
|
42
|
+
? current.filter(item => item !== value)
|
|
43
|
+
: [...current, value],
|
|
44
|
+
);
|
|
45
|
+
|
|
46
|
+
const combobox = useMultiCombobox({
|
|
47
|
+
selectableItems: matches,
|
|
48
|
+
isOpen,
|
|
49
|
+
hasSearch: true,
|
|
50
|
+
// With no match there is no option to point at, so the list stays shut.
|
|
51
|
+
onOpen: () => {
|
|
52
|
+
if (matches.length === 0) {
|
|
53
|
+
return false;
|
|
54
|
+
}
|
|
55
|
+
setIsOpen(true);
|
|
56
|
+
},
|
|
57
|
+
onClose: () => setIsOpen(false),
|
|
58
|
+
onToggle: toggle,
|
|
59
|
+
listboxId,
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
return (
|
|
63
|
+
<Card width={360} padding={4}>
|
|
64
|
+
<VStack gap={2}>
|
|
65
|
+
<HStack gap={1} wrap="wrap">
|
|
66
|
+
{LABELS.filter(item => selected.includes(item.value)).map(item => (
|
|
67
|
+
<Token
|
|
68
|
+
key={item.value}
|
|
69
|
+
label={item.label}
|
|
70
|
+
// The removed token's button unmounts, so focus goes back to
|
|
71
|
+
// the field instead of the page.
|
|
72
|
+
onRemove={() => {
|
|
73
|
+
toggle(item.value);
|
|
74
|
+
inputRef.current?.focus();
|
|
75
|
+
}}
|
|
76
|
+
/>
|
|
77
|
+
))}
|
|
78
|
+
</HStack>
|
|
79
|
+
<TextInput
|
|
80
|
+
ref={inputRef}
|
|
81
|
+
label="Labels"
|
|
82
|
+
placeholder="Filter labels"
|
|
83
|
+
role="combobox"
|
|
84
|
+
aria-autocomplete="list"
|
|
85
|
+
aria-expanded={isOpen}
|
|
86
|
+
aria-controls={isOpen ? listboxId : undefined}
|
|
87
|
+
aria-activedescendant={combobox.activeDescendantId}
|
|
88
|
+
value={query}
|
|
89
|
+
onChange={nextQuery => {
|
|
90
|
+
const nextMatches = filterLabels(nextQuery);
|
|
91
|
+
setQuery(nextQuery);
|
|
92
|
+
setIsOpen(true);
|
|
93
|
+
combobox.setHighlightedIndex(nextMatches.length > 0 ? 0 : -1);
|
|
94
|
+
if (nextQuery.trim() !== query.trim()) {
|
|
95
|
+
announce(
|
|
96
|
+
nextMatches.length === 0
|
|
97
|
+
? 'No labels match'
|
|
98
|
+
: nextMatches.length === 1
|
|
99
|
+
? '1 label'
|
|
100
|
+
: `${nextMatches.length} labels`,
|
|
101
|
+
);
|
|
102
|
+
}
|
|
103
|
+
}}
|
|
104
|
+
onClick={combobox.onTriggerClick}
|
|
105
|
+
onKeyDown={event => {
|
|
106
|
+
// Keys that compose a Korean, Japanese or Chinese syllable belong
|
|
107
|
+
// to the input method. Home, End, PageUp and PageDown keep their
|
|
108
|
+
// text-field meaning.
|
|
109
|
+
if (
|
|
110
|
+
isImeKeyEvent(event.nativeEvent) ||
|
|
111
|
+
['Home', 'End', 'PageUp', 'PageDown'].includes(event.key)
|
|
112
|
+
) {
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
// With no active option, Enter submits a surrounding form.
|
|
116
|
+
if (event.key === 'Enter' && combobox.activeDescendantId == null) {
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
combobox.onKeyDown(event);
|
|
120
|
+
}}
|
|
121
|
+
onBlur={() => {
|
|
122
|
+
setIsOpen(false);
|
|
123
|
+
combobox.setHighlightedIndex(-1);
|
|
124
|
+
}}
|
|
125
|
+
/>
|
|
126
|
+
{isOpen && (
|
|
127
|
+
<VStack
|
|
128
|
+
as="ul"
|
|
129
|
+
gap={0}
|
|
130
|
+
id={listboxId}
|
|
131
|
+
role="listbox"
|
|
132
|
+
aria-label="Labels"
|
|
133
|
+
aria-multiselectable
|
|
134
|
+
// Focus stays on the field when an option is pressed.
|
|
135
|
+
onMouseDown={event => event.preventDefault()}>
|
|
136
|
+
{matches.map((item, index) => (
|
|
137
|
+
<Item
|
|
138
|
+
key={item.value}
|
|
139
|
+
as="li"
|
|
140
|
+
id={combobox.getItemId(index)}
|
|
141
|
+
role="option"
|
|
142
|
+
// Selection is a check mark, so the highlight below stays the
|
|
143
|
+
// only fill on the row and the active option is always visible.
|
|
144
|
+
aria-checked={selected.includes(item.value)}
|
|
145
|
+
density="compact"
|
|
146
|
+
label={item.label}
|
|
147
|
+
endContent={
|
|
148
|
+
selected.includes(item.value) && (
|
|
149
|
+
<Icon icon={CheckIcon} size="sm" />
|
|
150
|
+
)
|
|
151
|
+
}
|
|
152
|
+
isHighlighted={index === combobox.highlightedIndex}
|
|
153
|
+
onClick={() => toggle(item.value)}
|
|
154
|
+
// Highlight follows pointer movement: a list that opens under
|
|
155
|
+
// a resting pointer keeps the active option the keys set.
|
|
156
|
+
onMouseMove={() => combobox.onItemMouseEnter(item, index)}
|
|
157
|
+
/>
|
|
158
|
+
))}
|
|
159
|
+
</VStack>
|
|
160
|
+
)}
|
|
161
|
+
</VStack>
|
|
162
|
+
</Card>
|
|
163
|
+
);
|
|
164
|
+
}
|
|
@@ -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
|
+
};
|
package/assets/templates/blocks/components/createDragToSnapPoints/DragToSnapPointsCardVanilla.tsx
ADDED
|
@@ -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.
|
|
3
|
+
"version": "0.7.10-canary.fef4d91",
|
|
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.
|
|
128
|
-
"@astryxdesign/core": "0.7.10-canary.
|
|
129
|
-
"@astryxdesign/lab": "0.7.10-canary.
|
|
130
|
-
"@astryxdesign/theme-neutral": "0.7.10-canary.
|
|
127
|
+
"@astryxdesign/charts": "0.7.10-canary.fef4d91",
|
|
128
|
+
"@astryxdesign/core": "0.7.10-canary.fef4d91",
|
|
129
|
+
"@astryxdesign/lab": "0.7.10-canary.fef4d91",
|
|
130
|
+
"@astryxdesign/theme-neutral": "0.7.10-canary.fef4d91"
|
|
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.
|
|
148
|
-
"@astryxdesign/core": "0.7.10-canary.
|
|
149
|
-
"@astryxdesign/lab": "0.7.10-canary.
|
|
150
|
-
"@astryxdesign/theme-neutral": "0.7.10-canary.
|
|
147
|
+
"@astryxdesign/charts": "0.7.10-canary.fef4d91",
|
|
148
|
+
"@astryxdesign/core": "0.7.10-canary.fef4d91",
|
|
149
|
+
"@astryxdesign/lab": "0.7.10-canary.fef4d91",
|
|
150
|
+
"@astryxdesign/theme-neutral": "0.7.10-canary.fef4d91",
|
|
151
151
|
"@heroicons/react": "^2.2.0",
|
|
152
152
|
"@stylexjs/stylex": "^0.19.0",
|
|
153
153
|
"@types/babel__core": "^7.20.5",
|