@astryxdesign/cli 0.7.9-canary.2ea8f68 → 0.7.9-canary.2f3510b
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/README.md +1 -1
- package/api/component/__fixtures__/resolutions/modules.txt +4 -4
- package/api/search/_candidate-score.mjs +25 -23
- package/api/search/_main-searcher.mjs +1 -1
- package/api/search/_words.d.mts +44 -7
- package/api/search/_words.mjs +113 -21
- package/api/swizzle/_adapter.d.mts +10 -0
- package/api/swizzle/_adapter.mjs +24 -1
- package/api/swizzle/copy/copy.d.mts +17 -1
- package/api/swizzle/copy/copy.mjs +249 -9
- package/api/swizzle/swizzle.doc.mjs +1 -1
- package/api/swizzle/swizzle.type.mjs +1 -1
- package/api/theme/build/build.mjs +363 -73
- package/api/theme/build/core-interception.mjs +92 -29
- package/api/theme/build/icon-imports.d.mts +35 -4
- package/api/theme/build/icon-imports.mjs +299 -38
- package/assets/discover/official-packages.json +4 -0
- package/assets/docs/author-a-theme.doc.mjs +3 -1
- package/assets/docs/icons.doc.mjs +29 -0
- package/assets/docs/motion.doc.mjs +1 -1
- package/assets/docs/tree/calendar-systems.doc.mjs +146 -0
- package/assets/docs/tree/calendars.doc.mjs +46 -0
- package/assets/docs/tree/i18n-calendars.doc.mjs +51 -0
- package/assets/docs/tree/internationalization.doc.mjs +3 -3
- package/assets/templates/blocks/components/Calendar/useCalendarDaysHookUsage.doc.mjs +14 -0
- package/assets/templates/blocks/components/Calendar/useCalendarDaysHookUsage.tsx +71 -0
- package/assets/templates/blocks/components/Hooks/useMergedRefsHookUsage.doc.mjs +14 -0
- package/assets/templates/blocks/components/Hooks/useMergedRefsHookUsage.tsx +78 -0
- package/assets/templates/blocks/components/Hooks/useScrollOverflowHookUsage.doc.mjs +14 -0
- package/assets/templates/blocks/components/Hooks/useScrollOverflowHookUsage.tsx +94 -0
- package/assets/templates/blocks/components/Icon/useIconHookUsage.doc.mjs +19 -0
- package/assets/templates/blocks/components/Icon/useIconHookUsage.tsx +68 -0
- package/assets/templates/blocks/components/Link/useLinkComponentHookUsage.doc.mjs +14 -0
- package/assets/templates/blocks/components/Link/useLinkComponentHookUsage.tsx +89 -0
- package/assets/templates/blocks/components/Overlay/useOverlayHookUsage.doc.mjs +21 -0
- package/assets/templates/blocks/components/Overlay/useOverlayHookUsage.tsx +49 -0
- package/assets/templates/blocks/components/Tokenizer/TokenizerClear.doc.mjs +2 -1
- package/assets/templates/blocks/components/Tokenizer/TokenizerClear.tsx +2 -2
- package/assets/templates/blocks/components/Tokenizer/TokenizerCreatable.tsx +0 -1
- package/assets/templates/blocks/components/Tokenizer/TokenizerEndContent.tsx +0 -1
- package/assets/templates/blocks/components/Tokenizer/TokenizerOverflow.doc.mjs +2 -1
- package/assets/templates/blocks/components/Tokenizer/TokenizerOverflow.tsx +0 -2
- package/assets/templates/blocks/components/usePanGesture/PanDraggableBox.doc.mjs +15 -0
- package/assets/templates/blocks/components/usePanGesture/PanDraggableBox.tsx +98 -0
- package/assets/templates/blocks/components/usePanGesture/PanPlayingCard.doc.mjs +14 -0
- package/assets/templates/blocks/components/usePanGesture/PanPlayingCard.tsx +147 -0
- package/assets/templates/pages/table-inbox/page.tsx +11 -8
- package/assets/templates/pages/work-item-detail/page.tsx +6 -2
- package/assets/theme.template.ts +14 -2
- package/authoring/doctypes/base/type.ts +41 -0
- package/authoring/doctypes/component/component.doc.mjs +7 -1
- package/authoring/doctypes/component/type.ts +5 -0
- package/authoring/index.d.ts +2 -0
- package/clients/cli/commands/ensure-core-built.mjs +399 -43
- package/clients/cli/commands/swizzle.mjs +10 -0
- package/clients/cli/lib/component-format.mjs +49 -0
- package/foundation/config/project.mjs +27 -9
- package/foundation/discovery/component-discovery.mjs +56 -10
- package/foundation/env/search-path.d.mts +12 -0
- package/foundation/env/search-path.mjs +71 -43
- package/foundation/integrations/manifest-writer.d.mts +3 -4
- package/foundation/integrations/manifest-writer.mjs +5 -3
- package/foundation/release/cache.d.mts +11 -4
- package/foundation/release/cache.mjs +15 -7
- package/foundation/response/response-types.doc.mjs +1 -1
- package/foundation/text/levenshtein.d.mts +4 -1
- package/foundation/text/levenshtein.mjs +44 -1
- package/package.json +9 -9
- package/api/swizzle/_github.d.mts +0 -8
- package/api/swizzle/_github.mjs +0 -22
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
|
|
3
|
+
'use client';
|
|
4
|
+
|
|
5
|
+
import {createContext, use, useState, type AnchorHTMLAttributes} from 'react';
|
|
6
|
+
import {Card} from '@astryxdesign/core/Card';
|
|
7
|
+
import {VStack} from '@astryxdesign/core/Layout';
|
|
8
|
+
import {
|
|
9
|
+
LinkProvider,
|
|
10
|
+
useLinkComponent,
|
|
11
|
+
type LinkComponentType,
|
|
12
|
+
} from '@astryxdesign/core/Link';
|
|
13
|
+
import {Text} from '@astryxdesign/core/Text';
|
|
14
|
+
|
|
15
|
+
const NavigateContext = createContext<(to: string) => void>(() => {});
|
|
16
|
+
|
|
17
|
+
function RouterLink({
|
|
18
|
+
to,
|
|
19
|
+
href: _href,
|
|
20
|
+
...props
|
|
21
|
+
}: AnchorHTMLAttributes<HTMLAnchorElement> & {to: string}) {
|
|
22
|
+
const navigate = use(NavigateContext);
|
|
23
|
+
return (
|
|
24
|
+
<a
|
|
25
|
+
{...props}
|
|
26
|
+
href={to}
|
|
27
|
+
onClick={event => {
|
|
28
|
+
event.preventDefault();
|
|
29
|
+
navigate(to);
|
|
30
|
+
}}
|
|
31
|
+
/>
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function ArticleCard({
|
|
36
|
+
title,
|
|
37
|
+
href,
|
|
38
|
+
resolvedBy,
|
|
39
|
+
linkAs,
|
|
40
|
+
}: {
|
|
41
|
+
title: string;
|
|
42
|
+
href: string;
|
|
43
|
+
resolvedBy: string;
|
|
44
|
+
linkAs?: LinkComponentType;
|
|
45
|
+
}) {
|
|
46
|
+
const LinkComponent = useLinkComponent(linkAs);
|
|
47
|
+
return (
|
|
48
|
+
<Card padding={3}>
|
|
49
|
+
<VStack gap={1}>
|
|
50
|
+
<Text type="body" weight="bold">
|
|
51
|
+
<LinkComponent href={href}>{title}</LinkComponent>
|
|
52
|
+
</Text>
|
|
53
|
+
<Text type="supporting" color="secondary">
|
|
54
|
+
{resolvedBy}
|
|
55
|
+
</Text>
|
|
56
|
+
</VStack>
|
|
57
|
+
</Card>
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export default function UseLinkComponentHookUsage() {
|
|
62
|
+
const [route, setRoute] = useState('/');
|
|
63
|
+
|
|
64
|
+
return (
|
|
65
|
+
<VStack gap={3}>
|
|
66
|
+
<Text type="body">Router location: {route}</Text>
|
|
67
|
+
<NavigateContext value={setRoute}>
|
|
68
|
+
<LinkProvider component={RouterLink}>
|
|
69
|
+
<ArticleCard
|
|
70
|
+
title="Getting started"
|
|
71
|
+
href="/articles/getting-started"
|
|
72
|
+
resolvedBy="LinkProvider: the router's link, no page load"
|
|
73
|
+
/>
|
|
74
|
+
<ArticleCard
|
|
75
|
+
title="Style guide (PDF)"
|
|
76
|
+
href="#style-guide"
|
|
77
|
+
resolvedBy='as="a": a native anchor, even inside the provider'
|
|
78
|
+
linkAs="a"
|
|
79
|
+
/>
|
|
80
|
+
</LinkProvider>
|
|
81
|
+
</NavigateContext>
|
|
82
|
+
<ArticleCard
|
|
83
|
+
title="Release notes"
|
|
84
|
+
href="#release-notes"
|
|
85
|
+
resolvedBy="Outside the provider: the app's LinkProvider, or a native anchor"
|
|
86
|
+
/>
|
|
87
|
+
</VStack>
|
|
88
|
+
);
|
|
89
|
+
}
|
|
@@ -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: 'useOverlay',
|
|
7
|
+
name: 'useOverlay — Product Quick View',
|
|
8
|
+
displayName: 'useOverlay — Product Quick View',
|
|
9
|
+
description:
|
|
10
|
+
'A product card that is its own overlay container: useOverlay returns the ref and props to spread on the Card and a bottom strip to render once over the image. Hovering the card, or moving keyboard focus into it, slides in a Quick view button along the bottom of the image, and leaving hides it again. The image is a link that the strip leaves clickable above it, and Tab lands on it first so the next Tab reaches Quick view.',
|
|
11
|
+
isReady: true,
|
|
12
|
+
aspectRatio: 4 / 3,
|
|
13
|
+
componentsUsed: [
|
|
14
|
+
'Overlay',
|
|
15
|
+
'Card',
|
|
16
|
+
'AspectRatio',
|
|
17
|
+
'Button',
|
|
18
|
+
'Layout',
|
|
19
|
+
'Text',
|
|
20
|
+
],
|
|
21
|
+
};
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
|
|
3
|
+
'use client';
|
|
4
|
+
|
|
5
|
+
import type {RefObject} from 'react';
|
|
6
|
+
import {AspectRatio} from '@astryxdesign/core/AspectRatio';
|
|
7
|
+
import {Button} from '@astryxdesign/core/Button';
|
|
8
|
+
import {Card} from '@astryxdesign/core/Card';
|
|
9
|
+
import {VStack} from '@astryxdesign/core/Layout';
|
|
10
|
+
import {useOverlay} from '@astryxdesign/core/Overlay';
|
|
11
|
+
import {Text} from '@astryxdesign/core/Text';
|
|
12
|
+
|
|
13
|
+
export default function UseOverlayHookUsage() {
|
|
14
|
+
const overlay = useOverlay({
|
|
15
|
+
showOn: 'hover',
|
|
16
|
+
position: 'bottom',
|
|
17
|
+
align: 'center',
|
|
18
|
+
content: <Button label="Quick view" variant="secondary" size="sm" />,
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
return (
|
|
22
|
+
<Card
|
|
23
|
+
width={280}
|
|
24
|
+
padding={0}
|
|
25
|
+
ref={overlay.containerRef as RefObject<HTMLDivElement | null>}
|
|
26
|
+
{...overlay.containerProps}>
|
|
27
|
+
<div style={{position: 'relative'}}>
|
|
28
|
+
<a href="#ceramic-mug">
|
|
29
|
+
<AspectRatio ratio={1}>
|
|
30
|
+
<img
|
|
31
|
+
src="/template-assets/light-product-1.png"
|
|
32
|
+
alt="Ceramic mug"
|
|
33
|
+
style={{width: '100%', height: '100%', objectFit: 'cover'}}
|
|
34
|
+
/>
|
|
35
|
+
</AspectRatio>
|
|
36
|
+
</a>
|
|
37
|
+
{overlay.element}
|
|
38
|
+
</div>
|
|
39
|
+
<VStack gap={1} padding={3}>
|
|
40
|
+
<Text type="body" weight="bold">
|
|
41
|
+
Ceramic mug
|
|
42
|
+
</Text>
|
|
43
|
+
<Text type="supporting" color="secondary">
|
|
44
|
+
$24
|
|
45
|
+
</Text>
|
|
46
|
+
</VStack>
|
|
47
|
+
</Card>
|
|
48
|
+
);
|
|
49
|
+
}
|
|
@@ -6,7 +6,8 @@ export const doc = {
|
|
|
6
6
|
exampleFor: 'Tokenizer',
|
|
7
7
|
name: 'Tokenizer \u2014 Clear',
|
|
8
8
|
displayName: 'Tokenizer \u2014 Clear',
|
|
9
|
-
description:
|
|
9
|
+
description:
|
|
10
|
+
"Tokenizer with a built-in clear-all button for bulk removal of all selected tokens. On touch screens, clear through the sheet's Clear all.",
|
|
10
11
|
isReady: true,
|
|
11
12
|
aspectRatio: 16 / 9,
|
|
12
13
|
componentsUsed: ['Tokenizer', 'Layout', 'Text'],
|
|
@@ -29,7 +29,8 @@ export default function TokenizerClear() {
|
|
|
29
29
|
<div style={{display: 'grid', gridTemplateColumns: 'minmax(0, 400px)'}}>
|
|
30
30
|
<Stack direction="vertical" gap={2}>
|
|
31
31
|
<Text type="supporting" color="secondary">
|
|
32
|
-
Clear-all button appears when tokens are selected
|
|
32
|
+
Clear-all button appears when tokens are selected; on touch screens,
|
|
33
|
+
clear through the sheet's Clear all
|
|
33
34
|
</Text>
|
|
34
35
|
<Tokenizer
|
|
35
36
|
label="Team Members"
|
|
@@ -38,7 +39,6 @@ export default function TokenizerClear() {
|
|
|
38
39
|
value={value}
|
|
39
40
|
onChange={items => setValue(items)}
|
|
40
41
|
hasClear
|
|
41
|
-
presentation="popover"
|
|
42
42
|
/>
|
|
43
43
|
</Stack>
|
|
44
44
|
</div>
|
|
@@ -6,7 +6,8 @@ export const doc = {
|
|
|
6
6
|
exampleFor: 'Tokenizer',
|
|
7
7
|
name: 'Tokenizer \u2014 Overflow',
|
|
8
8
|
displayName: 'Tokenizer \u2014 Overflow',
|
|
9
|
-
description:
|
|
9
|
+
description:
|
|
10
|
+
'Tokenizer with overflow truncation when unfocused. Inline mode pushes content down on expand; layer mode overlays without shifting layout. Overflow modes apply to the inline field.',
|
|
10
11
|
isReady: true,
|
|
11
12
|
aspectRatio: 16 / 9,
|
|
12
13
|
componentsUsed: ['Tokenizer', 'Layout', 'Text'],
|
|
@@ -41,7 +41,6 @@ export default function TokenizerOverflow() {
|
|
|
41
41
|
value={inlineValue}
|
|
42
42
|
onChange={items => setInlineValue(items)}
|
|
43
43
|
tokenOverflowBehavior="unfocusedInline"
|
|
44
|
-
presentation="popover"
|
|
45
44
|
/>
|
|
46
45
|
</Stack>
|
|
47
46
|
<Stack direction="vertical" gap={1}>
|
|
@@ -55,7 +54,6 @@ export default function TokenizerOverflow() {
|
|
|
55
54
|
value={layerValue}
|
|
56
55
|
onChange={items => setLayerValue(items)}
|
|
57
56
|
tokenOverflowBehavior="unfocusedLayer"
|
|
58
|
-
presentation="popover"
|
|
59
57
|
/>
|
|
60
58
|
</Stack>
|
|
61
59
|
</Stack>
|
|
@@ -0,0 +1,15 @@
|
|
|
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: 'usePanGesture',
|
|
7
|
+
alsoExampleFor: ['createPanGesture'],
|
|
8
|
+
name: 'usePanGesture — A draggable box',
|
|
9
|
+
displayName: 'usePanGesture — A draggable box',
|
|
10
|
+
description:
|
|
11
|
+
'The smallest pan example, in two forms side by side: the usePanGesture hook and the createPanGesture factory. The factory takes any element, React or not. Each card names its API, follows a drag from a finger, a mouse or a pen, and springs back, with the same StyleX styles. A starting point for a draggable tile, a swipe or any drag-and-release gesture.',
|
|
12
|
+
isReady: true,
|
|
13
|
+
aspectRatio: 4 / 3,
|
|
14
|
+
componentsUsed: ['Card', 'Center', 'HStack'],
|
|
15
|
+
};
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
|
|
3
|
+
'use client';
|
|
4
|
+
|
|
5
|
+
import {useCallback, useRef, useState, type Ref} from 'react';
|
|
6
|
+
import * as stylex from '@stylexjs/stylex';
|
|
7
|
+
import {createPanGesture} from '@astryxdesign/core';
|
|
8
|
+
import {Card} from '@astryxdesign/core/Card';
|
|
9
|
+
import {Center} from '@astryxdesign/core/Center';
|
|
10
|
+
import {HStack} from '@astryxdesign/core/HStack';
|
|
11
|
+
import {usePanGesture, type PanGestureEvent} from '@astryxdesign/core/hooks';
|
|
12
|
+
import {
|
|
13
|
+
colorVars,
|
|
14
|
+
durationVars,
|
|
15
|
+
easeVars,
|
|
16
|
+
radiusVars,
|
|
17
|
+
} from '@astryxdesign/core/theme/tokens.stylex';
|
|
18
|
+
|
|
19
|
+
const styles = stylex.create({
|
|
20
|
+
// A wash under the stage, so the box on top reads in light and dark themes.
|
|
21
|
+
stage: {
|
|
22
|
+
backgroundColor: colorVars['--color-neutral'],
|
|
23
|
+
borderRadius: radiusVars['--radius-container'],
|
|
24
|
+
},
|
|
25
|
+
box: {cursor: 'grab', userSelect: 'none'},
|
|
26
|
+
// Let go, the box springs back, unless the person reduces motion.
|
|
27
|
+
springBack: {
|
|
28
|
+
transition: {
|
|
29
|
+
default: `translate ${durationVars['--duration-medium']} ${easeVars['--ease-move']}`,
|
|
30
|
+
'@media (prefers-reduced-motion: reduce)': 'none',
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
drag: (x: number, y: number) => ({translate: `${x}px ${y}px`}),
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
type Drag = {x: number; y: number; held: boolean};
|
|
37
|
+
const REST: Drag = {x: 0, y: 0, held: false};
|
|
38
|
+
|
|
39
|
+
/** The box follows a held drag and goes back to rest when it ends. */
|
|
40
|
+
function nextDrag({state, translation}: PanGestureEvent): Drag {
|
|
41
|
+
const held = state === 'began' || state === 'changed';
|
|
42
|
+
return held ? {...translation, held} : REST;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** The same stage and card for both forms; the card names its API. */
|
|
46
|
+
function DraggableBox(props: {
|
|
47
|
+
name: string;
|
|
48
|
+
ref: Ref<HTMLDivElement>;
|
|
49
|
+
drag: Drag;
|
|
50
|
+
}) {
|
|
51
|
+
const {name, ref, drag} = props;
|
|
52
|
+
return (
|
|
53
|
+
<Center width="min(280px, 80vw)" height={180} xstyle={styles.stage}>
|
|
54
|
+
<Card
|
|
55
|
+
ref={ref}
|
|
56
|
+
padding={6}
|
|
57
|
+
elevation="med"
|
|
58
|
+
xstyle={[
|
|
59
|
+
styles.box,
|
|
60
|
+
styles.drag(drag.x, drag.y),
|
|
61
|
+
!drag.held && styles.springBack,
|
|
62
|
+
]}>
|
|
63
|
+
{name}
|
|
64
|
+
</Card>
|
|
65
|
+
</Center>
|
|
66
|
+
);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function WithHook() {
|
|
70
|
+
const box = useRef<HTMLDivElement>(null);
|
|
71
|
+
const [drag, setDrag] = useState(REST);
|
|
72
|
+
usePanGesture(box, {onPan: event => setDrag(nextDrag(event))});
|
|
73
|
+
return <DraggableBox name="usePanGesture" ref={box} drag={drag} />;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function WithFactory() {
|
|
77
|
+
const [drag, setDrag] = useState(REST);
|
|
78
|
+
// A callback ref: its cleanup takes the pan down with the box.
|
|
79
|
+
const draggable = useCallback((box: HTMLDivElement | null) => {
|
|
80
|
+
if (box == null) {
|
|
81
|
+
return undefined;
|
|
82
|
+
}
|
|
83
|
+
const pan = createPanGesture(box, {
|
|
84
|
+
onPan: event => setDrag(nextDrag(event)),
|
|
85
|
+
});
|
|
86
|
+
return () => pan.destroy();
|
|
87
|
+
}, []);
|
|
88
|
+
return <DraggableBox name="createPanGesture" ref={draggable} drag={drag} />;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export default function PanDraggableBox() {
|
|
92
|
+
return (
|
|
93
|
+
<HStack gap={6} wrap="wrap" justify="center">
|
|
94
|
+
<WithHook />
|
|
95
|
+
<WithFactory />
|
|
96
|
+
</HStack>
|
|
97
|
+
);
|
|
98
|
+
}
|
|
@@ -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: 'usePanGesture',
|
|
7
|
+
name: 'usePanGesture — A playing card (advanced)',
|
|
8
|
+
displayName: 'usePanGesture — A playing card (advanced)',
|
|
9
|
+
description:
|
|
10
|
+
'An advanced usePanGesture example: a playing card follows a drag, settles back on a gentle release and flies off on a quick flick, while a Discard button deals the next card from the keyboard and announces it. Drag, settle and throw are StyleX styles driven by React state. A pattern for swipe-to-dismiss, card decks and flick gestures.',
|
|
11
|
+
isReady: true,
|
|
12
|
+
aspectRatio: 4 / 3,
|
|
13
|
+
componentsUsed: ['Button', 'Card', 'Center', 'Text', 'VStack'],
|
|
14
|
+
};
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
|
|
3
|
+
'use client';
|
|
4
|
+
|
|
5
|
+
import {useRef, useState} from 'react';
|
|
6
|
+
import * as stylex from '@stylexjs/stylex';
|
|
7
|
+
import {Button} from '@astryxdesign/core/Button';
|
|
8
|
+
import {Card} from '@astryxdesign/core/Card';
|
|
9
|
+
import {Center} from '@astryxdesign/core/Center';
|
|
10
|
+
import {useAnnounce, usePanGesture} from '@astryxdesign/core/hooks';
|
|
11
|
+
import {Text} from '@astryxdesign/core/Text';
|
|
12
|
+
import {VStack} from '@astryxdesign/core/VStack';
|
|
13
|
+
import {
|
|
14
|
+
colorVars,
|
|
15
|
+
durationVars,
|
|
16
|
+
easeVars,
|
|
17
|
+
radiusVars,
|
|
18
|
+
} from '@astryxdesign/core/theme/tokens.stylex';
|
|
19
|
+
|
|
20
|
+
const DECK = [
|
|
21
|
+
{face: 'A\u2660', name: 'Ace of spades'},
|
|
22
|
+
{face: 'K\u2665', name: 'King of hearts'},
|
|
23
|
+
{face: 'Q\u2663', name: 'Queen of clubs'},
|
|
24
|
+
{face: 'J\u2666', name: 'Jack of diamonds'},
|
|
25
|
+
];
|
|
26
|
+
/** A release faster than this (px/s) throws the card away. */
|
|
27
|
+
const THROW_SPEED = 1000;
|
|
28
|
+
/** How far a thrown card travels while it fades, px. */
|
|
29
|
+
const THROW_DISTANCE = 160;
|
|
30
|
+
const EXIT = `${durationVars['--duration-exit']} ${easeVars['--ease-exit']}`;
|
|
31
|
+
|
|
32
|
+
const styles = stylex.create({
|
|
33
|
+
// A wash under the stage, so the card on top reads in light and dark themes.
|
|
34
|
+
stage: {
|
|
35
|
+
backgroundColor: colorVars['--color-neutral'],
|
|
36
|
+
borderRadius: radiusVars['--radius-container'],
|
|
37
|
+
overflow: 'hidden',
|
|
38
|
+
},
|
|
39
|
+
card: {cursor: 'grab', userSelect: 'none'},
|
|
40
|
+
// A gentle release settles the card back, unless the person reduces motion.
|
|
41
|
+
settle: {
|
|
42
|
+
transition: {
|
|
43
|
+
default: `translate ${durationVars['--duration-medium']} ${easeVars['--ease-move']}`,
|
|
44
|
+
'@media (prefers-reduced-motion: reduce)': 'none',
|
|
45
|
+
},
|
|
46
|
+
},
|
|
47
|
+
// A flick throws it off to one side as it fades.
|
|
48
|
+
thrown: {
|
|
49
|
+
opacity: 0,
|
|
50
|
+
transition: {
|
|
51
|
+
default: `translate ${EXIT}, opacity ${EXIT}`,
|
|
52
|
+
'@media (prefers-reduced-motion: reduce)': 'none',
|
|
53
|
+
},
|
|
54
|
+
},
|
|
55
|
+
drag: (x: number, y: number) => ({translate: `${x}px ${y}px`}),
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
type Pose = {x: number; y: number; motion: 'rest' | 'settle' | 'thrown'};
|
|
59
|
+
|
|
60
|
+
export default function PanPlayingCard() {
|
|
61
|
+
const card = useRef<HTMLDivElement>(null);
|
|
62
|
+
const [top, setTop] = useState(0);
|
|
63
|
+
const [pose, setPose] = useState<Pose>({x: 0, y: 0, motion: 'rest'});
|
|
64
|
+
const announce = useAnnounce();
|
|
65
|
+
/** A throw is in flight: the next card is dealt when it ends. */
|
|
66
|
+
const throwing = useRef(false);
|
|
67
|
+
/** The drag in progress met a throw: the rest of it moves nothing. */
|
|
68
|
+
const ignoringDrag = useRef(false);
|
|
69
|
+
const shown = DECK[top % DECK.length];
|
|
70
|
+
|
|
71
|
+
function discard(direction: number) {
|
|
72
|
+
const element = card.current;
|
|
73
|
+
// One throw at a time: a second Discard during it would deal twice.
|
|
74
|
+
if (element == null || throwing.current) {
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
throwing.current = true;
|
|
78
|
+
ignoringDrag.current = true;
|
|
79
|
+
setPose({x: direction * THROW_DISTANCE, y: 0, motion: 'thrown'});
|
|
80
|
+
// The next card's face and its place at the center commit together.
|
|
81
|
+
const dealNext = () => {
|
|
82
|
+
throwing.current = false;
|
|
83
|
+
announce(`${shown.name} discarded`);
|
|
84
|
+
setTop(value => value + 1);
|
|
85
|
+
setPose({x: 0, y: 0, motion: 'rest'});
|
|
86
|
+
};
|
|
87
|
+
if (matchMedia('(prefers-reduced-motion: reduce)').matches) {
|
|
88
|
+
dealNext();
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
// Once the throw's style applies, deal when its transitions settle: at
|
|
92
|
+
// the theme's duration, or at once when a stylesheet stops them.
|
|
93
|
+
requestAnimationFrame(() => {
|
|
94
|
+
const ends = element.getAnimations().map(animation => animation.finished);
|
|
95
|
+
void Promise.allSettled(ends).then(dealNext);
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
usePanGesture(card, {
|
|
100
|
+
onPan: ({state, translation, velocity}) => {
|
|
101
|
+
// A drag that meets a throw is ignored to its end, or the next card
|
|
102
|
+
// would jump to it.
|
|
103
|
+
if (state === 'began') {
|
|
104
|
+
ignoringDrag.current = throwing.current;
|
|
105
|
+
}
|
|
106
|
+
if (ignoringDrag.current) {
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
if (state === 'began' || state === 'changed') {
|
|
110
|
+
setPose({...translation, motion: 'rest'});
|
|
111
|
+
} else if (state === 'ended' && Math.abs(velocity.x) > THROW_SPEED) {
|
|
112
|
+
discard(Math.sign(velocity.x));
|
|
113
|
+
} else {
|
|
114
|
+
setPose({x: 0, y: 0, motion: 'settle'});
|
|
115
|
+
}
|
|
116
|
+
},
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
return (
|
|
120
|
+
<VStack gap={4} padding={4} width="min(360px, 80vw)">
|
|
121
|
+
<Center height={280} xstyle={styles.stage}>
|
|
122
|
+
<Card
|
|
123
|
+
ref={card}
|
|
124
|
+
// An image's name is all a screen reader announces, so it names the
|
|
125
|
+
// card.
|
|
126
|
+
role="img"
|
|
127
|
+
aria-label={shown.name}
|
|
128
|
+
width={80}
|
|
129
|
+
height={112}
|
|
130
|
+
elevation="med"
|
|
131
|
+
xstyle={[
|
|
132
|
+
styles.card,
|
|
133
|
+
styles.drag(pose.x, pose.y),
|
|
134
|
+
pose.motion !== 'rest' && styles[pose.motion],
|
|
135
|
+
]}>
|
|
136
|
+
<Center height="100%">
|
|
137
|
+
<Text size="3xl" weight="bold">
|
|
138
|
+
{shown.face}
|
|
139
|
+
</Text>
|
|
140
|
+
</Center>
|
|
141
|
+
</Card>
|
|
142
|
+
</Center>
|
|
143
|
+
{/* The drag's keyboard and assistive-technology path (WCAG 2.5.7). */}
|
|
144
|
+
<Button label="Discard the top card" onClick={() => discard(1)} />
|
|
145
|
+
</VStack>
|
|
146
|
+
);
|
|
147
|
+
}
|
|
@@ -82,6 +82,7 @@ import {
|
|
|
82
82
|
StackItem,
|
|
83
83
|
VStack,
|
|
84
84
|
} from '@astryxdesign/core/Layout';
|
|
85
|
+
import {rtlStyles} from '@astryxdesign/core/utils';
|
|
85
86
|
import {
|
|
86
87
|
durationVars,
|
|
87
88
|
easeVars,
|
|
@@ -1391,7 +1392,13 @@ function ConversationPane({
|
|
|
1391
1392
|
<Button
|
|
1392
1393
|
label="Inbox"
|
|
1393
1394
|
variant="ghost"
|
|
1394
|
-
icon={
|
|
1395
|
+
icon={
|
|
1396
|
+
<Icon
|
|
1397
|
+
icon={ArrowLeftIcon}
|
|
1398
|
+
size="sm"
|
|
1399
|
+
xstyle={rtlStyles.mirror}
|
|
1400
|
+
/>
|
|
1401
|
+
}
|
|
1395
1402
|
onClick={onClose}
|
|
1396
1403
|
/>
|
|
1397
1404
|
}
|
|
@@ -1840,7 +1847,9 @@ function ComposeWindow({
|
|
|
1840
1847
|
// than being rejected for not matching anything.
|
|
1841
1848
|
hasCreate
|
|
1842
1849
|
// Stamps data-autofocus, which is what the sheet looks for
|
|
1843
|
-
// once the window is actually visible.
|
|
1850
|
+
// once the window is actually visible. It applies to the
|
|
1851
|
+
// inline field: on a compact touch screen the field opens
|
|
1852
|
+
// its own sheet and ignores it.
|
|
1844
1853
|
//
|
|
1845
1854
|
// Deliberately without `hasEntriesOnFocus`: the two together
|
|
1846
1855
|
// mean the window can never open without the full directory
|
|
@@ -1874,10 +1883,6 @@ function ComposeWindow({
|
|
|
1874
1883
|
)}
|
|
1875
1884
|
</>
|
|
1876
1885
|
}
|
|
1877
|
-
// The recipient rows read as one header, so all three stay
|
|
1878
|
-
// inline fields on every device; the sheet has no end lane
|
|
1879
|
-
// for the Cc and Bcc buttons.
|
|
1880
|
-
presentation="popover"
|
|
1881
1886
|
/>
|
|
1882
1887
|
{hasCc ? (
|
|
1883
1888
|
<Tokenizer
|
|
@@ -1888,7 +1893,6 @@ function ComposeWindow({
|
|
|
1888
1893
|
value={cc}
|
|
1889
1894
|
onChange={items => setCc(items)}
|
|
1890
1895
|
hasCreate
|
|
1891
|
-
presentation="popover"
|
|
1892
1896
|
/>
|
|
1893
1897
|
) : null}
|
|
1894
1898
|
{hasBcc ? (
|
|
@@ -1900,7 +1904,6 @@ function ComposeWindow({
|
|
|
1900
1904
|
value={bcc}
|
|
1901
1905
|
onChange={items => setBcc(items)}
|
|
1902
1906
|
hasCreate
|
|
1903
|
-
presentation="popover"
|
|
1904
1907
|
/>
|
|
1905
1908
|
) : null}
|
|
1906
1909
|
<TextInput
|
|
@@ -29,6 +29,7 @@ import {MoreMenu} from '@astryxdesign/core/MoreMenu';
|
|
|
29
29
|
import type {DropdownMenuOption} from '@astryxdesign/core/DropdownMenu';
|
|
30
30
|
import {Link} from '@astryxdesign/core/Link';
|
|
31
31
|
import {Icon} from '@astryxdesign/core/Icon';
|
|
32
|
+
import {rtlStyles} from '@astryxdesign/core/utils';
|
|
32
33
|
import {AspectRatio} from '@astryxdesign/core/AspectRatio';
|
|
33
34
|
import {Divider} from '@astryxdesign/core/Divider';
|
|
34
35
|
import {StatusDot} from '@astryxdesign/core/StatusDot';
|
|
@@ -381,7 +382,11 @@ function PageHeader({
|
|
|
381
382
|
<HStack gap={4} vAlign="center" wrap="wrap">
|
|
382
383
|
<Link href="#" type="supporting" color="secondary">
|
|
383
384
|
<HStack as="span" gap={1} vAlign="center">
|
|
384
|
-
<Icon
|
|
385
|
+
<Icon
|
|
386
|
+
icon={ArrowLeftIcon}
|
|
387
|
+
size="sm"
|
|
388
|
+
xstyle={rtlStyles.mirror}
|
|
389
|
+
/>
|
|
385
390
|
All Tasks
|
|
386
391
|
</HStack>
|
|
387
392
|
</Link>
|
|
@@ -463,7 +468,6 @@ function PageHeader({
|
|
|
463
468
|
onRemove={onRemove}
|
|
464
469
|
/>
|
|
465
470
|
)}
|
|
466
|
-
presentation="popover"
|
|
467
471
|
/>
|
|
468
472
|
</HStack>
|
|
469
473
|
</VStack>
|
package/assets/theme.template.ts
CHANGED
|
@@ -181,8 +181,8 @@ export const myTheme = defineTheme({
|
|
|
181
181
|
radius: {base: 4, multiplier: 1},
|
|
182
182
|
|
|
183
183
|
/**
|
|
184
|
-
* Motion. Two knobs set how
|
|
185
|
-
*
|
|
184
|
+
* Motion. Two knobs set how it feels. tempo also times the touch springs;
|
|
185
|
+
* character sets only the CSS curves for now:
|
|
186
186
|
* tempo — 1 is Astryx's own; 0.75 the quickest, 1.5 the slowest.
|
|
187
187
|
* character — 'crisp' | 'standard' | 'expressive': the entrance and move
|
|
188
188
|
* curves (--ease-entrance, --ease-move). --ease-exit, the curve for
|
|
@@ -346,6 +346,18 @@ export const myTheme = defineTheme({
|
|
|
346
346
|
*/
|
|
347
347
|
// iconVariants: ['outline', 'filled'],
|
|
348
348
|
|
|
349
|
+
/**
|
|
350
|
+
* Choose which shared icon a component's own icon role uses, by slot, such
|
|
351
|
+
* as `code-block-copy` for CodeBlock's copy button. A value is an icon name,
|
|
352
|
+
* `null` to hide the icon, a partial `{icon, variant, size}` request, or a
|
|
353
|
+
* pure function of the slot's state that returns one.
|
|
354
|
+
* Keep a slot function in its own module and import it, so a built theme
|
|
355
|
+
* can import it too. Here `copySlot` is
|
|
356
|
+
* `({copied}) => ({icon: copied ? 'checkDouble' : 'copy'})`.
|
|
357
|
+
* Reference: `astryx docs icons`; each component's docs list its slots.
|
|
358
|
+
*/
|
|
359
|
+
// componentIcons: {'code-block-copy': copySlot},
|
|
360
|
+
|
|
349
361
|
/**
|
|
350
362
|
* Replace the small components that DRAW control state — the checkbox box,
|
|
351
363
|
* the radio dot, the mark on a chosen option — by indicator name rather than
|