@astryxdesign/cli 0.7.9-canary.ffa495b → 0.7.10-canary.010db3f
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/CHANGELOG.md +80 -0
- package/README.md +1 -1
- package/api/component/__fixtures__/resolutions/modules.txt +5 -6
- package/api/search/_candidate-score.mjs +25 -23
- package/api/search/_gather-components.mjs +2 -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 +16 -0
- package/assets/docs/author-a-theme.doc.mjs +3 -1
- package/assets/docs/getting-started.doc.mjs +20 -0
- 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/Carousel/CarouselSnapPaging.doc.mjs +14 -0
- package/assets/templates/blocks/components/Carousel/CarouselSnapPaging.tsx +49 -0
- package/assets/templates/blocks/components/Hooks/useInputContainerHookUsage.doc.mjs +15 -0
- package/assets/templates/blocks/components/Hooks/useInputContainerHookUsage.tsx +93 -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/useScrollLockHookUsage.doc.mjs +14 -0
- package/assets/templates/blocks/components/Hooks/useScrollLockHookUsage.tsx +80 -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/MultiSelector/useMultiComboboxHookUsage.doc.mjs +23 -0
- package/assets/templates/blocks/components/MultiSelector/useMultiComboboxHookUsage.tsx +164 -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/Table/useTableSortableStateHookUsage.doc.mjs +14 -0
- package/assets/templates/blocks/components/Table/useTableSortableStateHookUsage.tsx +61 -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/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/ai-chat-landing/page.tsx +0 -9
- package/assets/templates/themes/neutral/neutralPaletteRefs.generated.ts +2 -2
- package/assets/templates/themes/neutral/neutralTheme.ts +30 -4
- 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/authoring-self-docs.mjs +2 -2
- package/foundation/discovery/cli-self-docs.mjs +2 -1
- package/foundation/discovery/component-discovery.mjs +56 -10
- package/foundation/discovery/docs-discovery.mjs +6 -4
- package/foundation/discovery/icon-definition-discovery.mjs +3 -3
- package/foundation/discovery/template-adapter.mjs +5 -7
- package/foundation/discovery/theme-discovery.mjs +8 -10
- package/foundation/doc-compiler/tree.mjs +2 -2
- package/foundation/env/search-path.d.mts +12 -0
- package/foundation/env/search-path.mjs +71 -43
- package/foundation/fs/listing-cache.d.mts +3 -1
- package/foundation/fs/listing-cache.mjs +63 -11
- package/foundation/fs/paths.mjs +2 -1
- 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 +6 -18
- package/api/swizzle/_github.d.mts +0 -8
- package/api/swizzle/_github.mjs +0 -22
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
|
|
3
|
+
'use client';
|
|
4
|
+
|
|
5
|
+
import {useEffect, useState} from 'react';
|
|
6
|
+
import * as stylex from '@stylexjs/stylex';
|
|
7
|
+
import {Button} from '@astryxdesign/core/Button';
|
|
8
|
+
import {useFocusTrap, useScrollLock} from '@astryxdesign/core/hooks';
|
|
9
|
+
import {VStack} from '@astryxdesign/core/Layout';
|
|
10
|
+
import {Link} from '@astryxdesign/core/Link';
|
|
11
|
+
import {colorVars, spacingVars} from '@astryxdesign/core/theme/tokens.stylex';
|
|
12
|
+
|
|
13
|
+
const styles = stylex.create({
|
|
14
|
+
menu: {
|
|
15
|
+
width: '100%',
|
|
16
|
+
height: '100%',
|
|
17
|
+
maxWidth: 'none',
|
|
18
|
+
maxHeight: 'none',
|
|
19
|
+
margin: 0,
|
|
20
|
+
borderWidth: 0,
|
|
21
|
+
overflowY: 'auto',
|
|
22
|
+
padding: spacingVars['--spacing-4'],
|
|
23
|
+
color: colorVars['--color-text-primary'],
|
|
24
|
+
backgroundColor: colorVars['--color-background-surface'],
|
|
25
|
+
},
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
const MENU_ITEMS = ['Products', 'Pricing', 'Customers', 'Support'];
|
|
29
|
+
|
|
30
|
+
export default function UseScrollLockHookUsage() {
|
|
31
|
+
const [isOpen, setIsOpen] = useState(false);
|
|
32
|
+
useScrollLock(isOpen);
|
|
33
|
+
const {containerRef, focusFirst} = useFocusTrap<HTMLDialogElement>({
|
|
34
|
+
isActive: isOpen,
|
|
35
|
+
onEscape: close,
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
// The dialog leaves the top layer before the state change, so the page is
|
|
39
|
+
// no longer inert when the focus trap hands focus back to Menu.
|
|
40
|
+
function close() {
|
|
41
|
+
containerRef.current?.close();
|
|
42
|
+
setIsOpen(false);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
useEffect(() => {
|
|
46
|
+
const dialog = containerRef.current;
|
|
47
|
+
if (isOpen && dialog != null && !dialog.open) {
|
|
48
|
+
dialog.showModal();
|
|
49
|
+
focusFirst();
|
|
50
|
+
}
|
|
51
|
+
}, [isOpen, containerRef, focusFirst]);
|
|
52
|
+
|
|
53
|
+
return (
|
|
54
|
+
<>
|
|
55
|
+
<Button label="Menu" onClick={() => setIsOpen(true)} />
|
|
56
|
+
<dialog
|
|
57
|
+
ref={containerRef}
|
|
58
|
+
aria-label="Menu"
|
|
59
|
+
onCancel={event => {
|
|
60
|
+
event.preventDefault();
|
|
61
|
+
close();
|
|
62
|
+
}}
|
|
63
|
+
{...stylex.props(styles.menu)}>
|
|
64
|
+
<nav aria-label="Site menu">
|
|
65
|
+
<VStack gap={4} hAlign="start">
|
|
66
|
+
<Button label="Close menu" variant="secondary" onClick={close} />
|
|
67
|
+
{MENU_ITEMS.map(item => (
|
|
68
|
+
<Link
|
|
69
|
+
key={item}
|
|
70
|
+
href={`#menu-${item.toLowerCase()}`}
|
|
71
|
+
onClick={close}>
|
|
72
|
+
{item}
|
|
73
|
+
</Link>
|
|
74
|
+
))}
|
|
75
|
+
</VStack>
|
|
76
|
+
</nav>
|
|
77
|
+
</dialog>
|
|
78
|
+
</>
|
|
79
|
+
);
|
|
80
|
+
}
|
|
@@ -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: 'useScrollOverflow',
|
|
7
|
+
name: 'useScrollOverflow — Filter Strip Edge Fades',
|
|
8
|
+
displayName: 'useScrollOverflow — Filter Strip Edge Fades',
|
|
9
|
+
description:
|
|
10
|
+
'A row of active filters that scrolls sideways. useScrollOverflow reports which edge has hidden filters, and the strip fades only that edge: none while every filter fits, the end at the start, both mid-scroll and the start at the end. Adding or removing a filter updates the fades, and in a right-to-left layout the start edge is on the right.',
|
|
11
|
+
isReady: true,
|
|
12
|
+
aspectRatio: 4 / 3,
|
|
13
|
+
componentsUsed: ['Token', 'Button', 'Switch', 'Layout'],
|
|
14
|
+
};
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
|
|
3
|
+
'use client';
|
|
4
|
+
|
|
5
|
+
import {useState} from 'react';
|
|
6
|
+
import * as stylex from '@stylexjs/stylex';
|
|
7
|
+
import {Button} from '@astryxdesign/core/Button';
|
|
8
|
+
import {useScrollOverflow} from '@astryxdesign/core/hooks';
|
|
9
|
+
import {HStack, VStack} from '@astryxdesign/core/Layout';
|
|
10
|
+
import {Switch} from '@astryxdesign/core/Switch';
|
|
11
|
+
import {Token} from '@astryxdesign/core/Token';
|
|
12
|
+
import {spacingVars} from '@astryxdesign/core/theme/tokens.stylex';
|
|
13
|
+
|
|
14
|
+
const FADE = spacingVars['--spacing-8'];
|
|
15
|
+
const FADE_FROM_LEFT = `linear-gradient(to right, transparent, black ${FADE})`;
|
|
16
|
+
const FADE_FROM_RIGHT = `linear-gradient(to left, transparent, black ${FADE})`;
|
|
17
|
+
|
|
18
|
+
const styles = stylex.create({
|
|
19
|
+
strip: {
|
|
20
|
+
display: 'flex',
|
|
21
|
+
gap: spacingVars['--spacing-2'],
|
|
22
|
+
overflowX: 'auto',
|
|
23
|
+
},
|
|
24
|
+
filter: {
|
|
25
|
+
flexShrink: 0,
|
|
26
|
+
},
|
|
27
|
+
fadeLeft: {
|
|
28
|
+
maskImage: FADE_FROM_LEFT,
|
|
29
|
+
},
|
|
30
|
+
fadeRight: {
|
|
31
|
+
maskImage: FADE_FROM_RIGHT,
|
|
32
|
+
},
|
|
33
|
+
fadeBoth: {
|
|
34
|
+
maskImage: `linear-gradient(to right, transparent, black ${FADE}, black calc(100% - ${FADE}), transparent)`,
|
|
35
|
+
},
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
const FILTERS = [
|
|
39
|
+
'Open now',
|
|
40
|
+
'Free delivery',
|
|
41
|
+
'Vegetarian',
|
|
42
|
+
'Under $15',
|
|
43
|
+
'Top rated',
|
|
44
|
+
'Outdoor seating',
|
|
45
|
+
'Pet friendly',
|
|
46
|
+
];
|
|
47
|
+
|
|
48
|
+
export default function UseScrollOverflowHookUsage() {
|
|
49
|
+
const [filters, setFilters] = useState(FILTERS.slice(0, 2));
|
|
50
|
+
const [isRtl, setIsRtl] = useState(false);
|
|
51
|
+
const {scrollRef, overflowStart, overflowEnd} = useScrollOverflow();
|
|
52
|
+
const nextFilter = FILTERS.find(filter => !filters.includes(filter));
|
|
53
|
+
const fadeStart = isRtl ? styles.fadeRight : styles.fadeLeft;
|
|
54
|
+
const fadeEnd = isRtl ? styles.fadeLeft : styles.fadeRight;
|
|
55
|
+
|
|
56
|
+
return (
|
|
57
|
+
<VStack gap={3} width={320}>
|
|
58
|
+
<div dir={isRtl ? 'rtl' : 'ltr'}>
|
|
59
|
+
<div
|
|
60
|
+
ref={scrollRef}
|
|
61
|
+
role="group"
|
|
62
|
+
aria-label="Active filters"
|
|
63
|
+
{...stylex.props(
|
|
64
|
+
styles.strip,
|
|
65
|
+
overflowStart && overflowEnd
|
|
66
|
+
? styles.fadeBoth
|
|
67
|
+
: overflowStart
|
|
68
|
+
? fadeStart
|
|
69
|
+
: overflowEnd && fadeEnd,
|
|
70
|
+
)}>
|
|
71
|
+
{filters.map(filter => (
|
|
72
|
+
<Token
|
|
73
|
+
key={filter}
|
|
74
|
+
label={filter}
|
|
75
|
+
xstyle={styles.filter}
|
|
76
|
+
onRemove={() =>
|
|
77
|
+
setFilters(current => current.filter(item => item !== filter))
|
|
78
|
+
}
|
|
79
|
+
/>
|
|
80
|
+
))}
|
|
81
|
+
</div>
|
|
82
|
+
</div>
|
|
83
|
+
<HStack gap={3} vAlign="center">
|
|
84
|
+
<Button
|
|
85
|
+
label="Add filter"
|
|
86
|
+
variant="secondary"
|
|
87
|
+
isDisabled={nextFilter == null}
|
|
88
|
+
onClick={() => nextFilter && setFilters([...filters, nextFilter])}
|
|
89
|
+
/>
|
|
90
|
+
<Switch label="Right to left" value={isRtl} onChange={setIsRtl} />
|
|
91
|
+
</HStack>
|
|
92
|
+
</VStack>
|
|
93
|
+
);
|
|
94
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
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: 'useIcon',
|
|
7
|
+
name: 'useIcon — Status Row',
|
|
8
|
+
displayName: 'useIcon — Status Row',
|
|
9
|
+
description:
|
|
10
|
+
'A custom status row that draws the semantic success, warning and error icons with useIcon. The same row renders under the current theme and under a Theme whose icons override those three, and its icons change with no change to the component.',
|
|
11
|
+
isReady: true,
|
|
12
|
+
aspectRatio: 4 / 3,
|
|
13
|
+
componentsUsed: ['Theme', 'Layout', 'Text'],
|
|
14
|
+
icons: {
|
|
15
|
+
CheckBadgeIcon: 'success',
|
|
16
|
+
ExclamationCircleIcon: 'warning',
|
|
17
|
+
NoSymbolIcon: 'error',
|
|
18
|
+
},
|
|
19
|
+
};
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
|
|
3
|
+
'use client';
|
|
4
|
+
|
|
5
|
+
import {
|
|
6
|
+
CheckBadgeIcon,
|
|
7
|
+
ExclamationCircleIcon,
|
|
8
|
+
NoSymbolIcon,
|
|
9
|
+
} from '@heroicons/react/24/solid';
|
|
10
|
+
import {useIcon} from '@astryxdesign/core/Icon';
|
|
11
|
+
import {HStack, VStack} from '@astryxdesign/core/Layout';
|
|
12
|
+
import {Text} from '@astryxdesign/core/Text';
|
|
13
|
+
import {Theme, defineTheme, useTheme} from '@astryxdesign/core/theme';
|
|
14
|
+
|
|
15
|
+
const statusIconTheme = defineTheme({
|
|
16
|
+
name: 'status-icons-docs',
|
|
17
|
+
icons: {
|
|
18
|
+
success: <CheckBadgeIcon width="1em" height="1em" />,
|
|
19
|
+
warning: <ExclamationCircleIcon width="1em" height="1em" />,
|
|
20
|
+
error: <NoSymbolIcon width="1em" height="1em" />,
|
|
21
|
+
},
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
function StatusRow() {
|
|
25
|
+
const success = useIcon('success');
|
|
26
|
+
const warning = useIcon('warning');
|
|
27
|
+
const error = useIcon('error');
|
|
28
|
+
|
|
29
|
+
return (
|
|
30
|
+
<HStack gap={4}>
|
|
31
|
+
<HStack gap={1} vAlign="center">
|
|
32
|
+
{success}
|
|
33
|
+
<Text type="body">Passed</Text>
|
|
34
|
+
</HStack>
|
|
35
|
+
<HStack gap={1} vAlign="center">
|
|
36
|
+
{warning}
|
|
37
|
+
<Text type="body">Flaky</Text>
|
|
38
|
+
</HStack>
|
|
39
|
+
<HStack gap={1} vAlign="center">
|
|
40
|
+
{error}
|
|
41
|
+
<Text type="body">Failed</Text>
|
|
42
|
+
</HStack>
|
|
43
|
+
</HStack>
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export default function UseIconHookUsage() {
|
|
48
|
+
const {mode} = useTheme();
|
|
49
|
+
|
|
50
|
+
return (
|
|
51
|
+
<VStack gap={4}>
|
|
52
|
+
<VStack gap={2}>
|
|
53
|
+
<Text type="supporting" color="secondary">
|
|
54
|
+
Current theme
|
|
55
|
+
</Text>
|
|
56
|
+
<StatusRow />
|
|
57
|
+
</VStack>
|
|
58
|
+
<Theme theme={statusIconTheme} mode={mode}>
|
|
59
|
+
<VStack gap={2}>
|
|
60
|
+
<Text type="supporting" color="secondary">
|
|
61
|
+
Theme with its own status icons
|
|
62
|
+
</Text>
|
|
63
|
+
<StatusRow />
|
|
64
|
+
</VStack>
|
|
65
|
+
</Theme>
|
|
66
|
+
</VStack>
|
|
67
|
+
);
|
|
68
|
+
}
|
|
@@ -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: 'useLinkComponent',
|
|
7
|
+
name: 'useLinkComponent — Article Cards',
|
|
8
|
+
displayName: 'useLinkComponent — Article Cards',
|
|
9
|
+
description:
|
|
10
|
+
'A custom Article card renders its title link with the component useLinkComponent resolves: the as prop first, then the nearest LinkProvider, then a native anchor. Inside a LinkProvider wired to a client-side router, the title navigates without a page load and updates the router location. With as="a" the title is a native anchor even inside the provider, and outside the provider it falls back to the next provider up or a native anchor.',
|
|
11
|
+
isReady: true,
|
|
12
|
+
aspectRatio: 4 / 3,
|
|
13
|
+
componentsUsed: ['LinkProvider', 'Card', 'Layout', 'Text'],
|
|
14
|
+
};
|
|
@@ -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,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,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
|
+
}
|
|
@@ -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: 'useTableSortableState',
|
|
7
|
+
name: 'useTableSortableState — Multi-Sort Orders',
|
|
8
|
+
displayName: 'useTableSortableState — Multi-Sort Orders',
|
|
9
|
+
description:
|
|
10
|
+
'Orders with no sort code of their own: useTableSortableState owns the sort state, returns the sorted orders, and hands useTableSortable a ready config. Click Customer, then Shift-click Total, to sort by customer and then by total within each customer. A line above the orders reads the current sort state from the hook.',
|
|
11
|
+
isReady: true,
|
|
12
|
+
aspectRatio: 4 / 3,
|
|
13
|
+
componentsUsed: ['Table', 'Layout', 'Text'],
|
|
14
|
+
};
|