@astryxdesign/cli 0.7.7 → 0.7.8-canary.07ee4b5

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.
Files changed (64) hide show
  1. package/api/component/__fixtures__/resolutions/case-01.txt +30 -0
  2. package/api/component/__fixtures__/resolutions/case-02.txt +30 -0
  3. package/api/component/__fixtures__/resolutions/case-03.txt +30 -0
  4. package/api/component/__fixtures__/resolutions/case-04.txt +30 -0
  5. package/api/component/__fixtures__/resolutions/case-05.txt +30 -0
  6. package/api/component/__fixtures__/resolutions/case-06.txt +30 -0
  7. package/api/component/__fixtures__/resolutions/case-07.txt +30 -0
  8. package/api/component/__fixtures__/resolutions/case-08.txt +30 -0
  9. package/api/component/__fixtures__/resolutions/case-09.txt +30 -0
  10. package/api/component/__fixtures__/resolutions/case-10.txt +30 -0
  11. package/api/component/__fixtures__/resolutions/case-11.txt +30 -0
  12. package/api/component/__fixtures__/resolutions/case-12.txt +30 -0
  13. package/api/component/__fixtures__/resolutions/case-13.txt +25 -0
  14. package/api/component/__fixtures__/resolutions/modules.txt +308 -0
  15. package/api/component/component.mjs +11 -7
  16. package/api/gap-report/gap-report.mjs +9 -4
  17. package/api/integration/authoring-checks.mjs +31 -0
  18. package/api/integration/check/check.mjs +8 -3
  19. package/assets/codemods/transforms/next/index.mjs +11 -1
  20. package/assets/codemods/transforms/next/promote-tokenizer-presentation.mjs +191 -0
  21. package/assets/discover/official-packages.json +4 -8
  22. package/assets/docs/motion.doc.mjs +1 -1
  23. package/assets/docs/tree/tokens-duration.doc.mjs +4 -0
  24. package/assets/docs/tree/tokens.doc.mjs +1 -1
  25. package/assets/templates/blocks/components/Hooks/useAnnounceHookUsage.doc.mjs +14 -0
  26. package/assets/templates/blocks/components/Hooks/useAnnounceHookUsage.tsx +90 -0
  27. package/assets/templates/blocks/components/Hooks/useFocusTrapHookUsage.doc.mjs +14 -0
  28. package/assets/templates/blocks/components/Hooks/useFocusTrapHookUsage.tsx +70 -0
  29. package/assets/templates/blocks/components/Hooks/useHotkeysHookUsage.doc.mjs +23 -0
  30. package/assets/templates/blocks/components/Hooks/useHotkeysHookUsage.tsx +90 -0
  31. package/assets/templates/blocks/components/Hooks/useKeyboardHintHookUsage.doc.mjs +3 -11
  32. package/assets/templates/blocks/components/Hooks/useKeyboardHintHookUsage.tsx +60 -45
  33. package/assets/templates/blocks/components/Hooks/useLocaleHookUsage.doc.mjs +20 -0
  34. package/assets/templates/blocks/components/Hooks/useLocaleHookUsage.tsx +72 -0
  35. package/assets/templates/blocks/components/Hooks/useScrollableAreaHookUsage.doc.mjs +14 -0
  36. package/assets/templates/blocks/components/Hooks/useScrollableAreaHookUsage.tsx +90 -0
  37. package/assets/templates/blocks/components/Hooks/useTypeaheadHookUsage.doc.mjs +14 -0
  38. package/assets/templates/blocks/components/Hooks/useTypeaheadHookUsage.tsx +66 -0
  39. package/assets/templates/blocks/components/Lightbox/LightboxHookUsage.doc.mjs +15 -0
  40. package/assets/templates/blocks/components/Lightbox/LightboxHookUsage.tsx +62 -0
  41. package/assets/templates/blocks/components/Tokenizer/TokenizerClear.tsx +1 -0
  42. package/assets/templates/blocks/components/Tokenizer/TokenizerCreatable.tsx +1 -0
  43. package/assets/templates/blocks/components/Tokenizer/TokenizerEndContent.tsx +1 -0
  44. package/assets/templates/blocks/components/Tokenizer/TokenizerOverflow.tsx +2 -0
  45. package/assets/templates/blocks/components/createAnimator/AnimatorPlayingCardsVanilla.doc.mjs +14 -0
  46. package/assets/templates/blocks/components/createAnimator/AnimatorPlayingCardsVanilla.tsx +199 -0
  47. package/assets/templates/blocks/components/useAnimator/AnimatorPlayingCards.doc.mjs +21 -0
  48. package/assets/templates/blocks/components/useAnimator/AnimatorPlayingCards.tsx +210 -0
  49. package/assets/templates/pages/table-inbox/page.tsx +6 -0
  50. package/assets/templates/pages/work-item-detail/page.tsx +1 -0
  51. package/assets/theme.template.ts +2 -1
  52. package/clients/cli/commands/component.mjs +18 -8
  53. package/clients/cli/index.mjs +56 -11
  54. package/clients/cli/program.mjs +15 -0
  55. package/clients/cli/run.mjs +4 -1
  56. package/foundation/discovery/component-discovery.mjs +111 -16
  57. package/foundation/fs/listing-cache.d.mts +25 -0
  58. package/foundation/fs/listing-cache.mjs +69 -2
  59. package/foundation/fs/paths.mjs +50 -5
  60. package/foundation/integrations/public-imports.d.mts +24 -0
  61. package/foundation/integrations/public-imports.mjs +2 -2
  62. package/foundation/xle/registry.d.mts +1 -1
  63. package/foundation/xle/registry.mjs +11 -1
  64. package/package.json +9 -9
@@ -0,0 +1,191 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ /**
4
+ * @file Codemod: move Tokenizer's experimental presentation to the stable prop
5
+ *
6
+ * `experimental={{presentation: x}}` on a Tokenizer becomes
7
+ * `presentation={x}`, or `presentation="x"` for a string. Tokenizer no longer
8
+ * reads `experimental`, and `presentation` takes the same values, so the
9
+ * rewrite restores the surface the call selected. Other keys stay in the
10
+ * `experimental` object, and an object left empty is removed. Built on the
11
+ * shared `transformProp` helper, so it does not follow variables, helpers,
12
+ * wrappers, or types. Where it cannot prove the result it leaves the call
13
+ * unchanged with a TODO: an `experimental` value that is not an object
14
+ * literal, a spread or computed key in it, a Tokenizer that already passes
15
+ * `presentation`, and a Tokenizer that spreads props. A spread can carry
16
+ * `presentation`, also as `undefined`, and then the result changes with the
17
+ * moved attribute before or after it. Each TODO names its case and is added
18
+ * once, so a second run changes nothing.
19
+ */
20
+
21
+ import {transformProp} from '../../transform-prop.mjs';
22
+
23
+ export const meta = {
24
+ title: "Move Tokenizer's removed experimental presentation to presentation",
25
+ description:
26
+ 'Rewrites `experimental={{presentation: x}}` on Tokenizer to ' +
27
+ '`presentation={x}`; Tokenizer no longer reads `experimental`. Leaves a ' +
28
+ 'TODO where the experimental value is not an object literal, where the ' +
29
+ 'Tokenizer already passes presentation, and where it spreads props.',
30
+ };
31
+
32
+ const CORE_IMPORT_RE = /^@(astryxdesign|xds)\/core(?:\/|$)/;
33
+ const COMPONENT_PROPS = new Map([['Tokenizer', new Set(['experimental'])]]);
34
+
35
+ const TODO_PREFIX =
36
+ ' TODO(astryx upgrade): experimental.presentation was removed in favor of ' +
37
+ 'presentation. ';
38
+ /** @param {string} reason */
39
+ const moveTodo = reason =>
40
+ `${TODO_PREFIX}Move the value to presentation; the codemod left this one ` +
41
+ `unchanged because ${reason}. `;
42
+ /** One TODO per case, so the reader knows what to check. */
43
+ const TODOS = {
44
+ notLiteral: moveTodo('the value is not a literal object'),
45
+ unprovenKey: moveTodo('the object has a spread or a computed key'),
46
+ repeatedKey: moveTodo('the object sets presentation more than once'),
47
+ presentationSet: `${TODO_PREFIX}presentation is already set; remove experimental.presentation. `,
48
+ spread: moveTodo('a spread may also set presentation'),
49
+ };
50
+
51
+ const TYPE_WRAPPERS = new Set([
52
+ 'TSAsExpression',
53
+ 'TSSatisfiesExpression',
54
+ 'TSTypeAssertion',
55
+ 'TSNonNullExpression',
56
+ 'TypeCastExpression',
57
+ 'ParenthesizedExpression',
58
+ ]);
59
+
60
+ /** @param {any} node */
61
+ function unwrap(node) {
62
+ let current = node;
63
+ while (current && TYPE_WRAPPERS.has(current.type)) {
64
+ current = current.expression;
65
+ }
66
+ return current;
67
+ }
68
+
69
+ /** The static key of an object entry, or null. @param {any} entry */
70
+ function keyName(entry) {
71
+ if (
72
+ (entry.type !== 'ObjectProperty' && entry.type !== 'Property') ||
73
+ entry.computed
74
+ ) {
75
+ return null;
76
+ }
77
+ const key = entry.key;
78
+ if (key.type === 'Identifier') {
79
+ return key.name;
80
+ }
81
+ if (
82
+ (key.type === 'StringLiteral' || key.type === 'Literal') &&
83
+ typeof key.value === 'string'
84
+ ) {
85
+ return key.value;
86
+ }
87
+ return null;
88
+ }
89
+
90
+ /** @param {any} j @param {any} node @param {string} text */
91
+ function addComment(j, node, text) {
92
+ node.comments ??= [];
93
+ if (node.comments.some((/** @type {any} */ c) => c.value === text)) {
94
+ return false;
95
+ }
96
+ node.comments.push(j.commentBlock(text, true, false));
97
+ return true;
98
+ }
99
+
100
+ /**
101
+ * @param {import('../../../../authoring/codemod/type').AstryxCodemodFile} file
102
+ * @param {import('../../../../authoring/codemod/type').CodemodTransformApi} api
103
+ * @returns {string | null | undefined}
104
+ */
105
+ export default function transformer(file, api) {
106
+ const j = api.jscodeshift;
107
+ const root = j(file.source);
108
+ let hasChanges = false;
109
+
110
+ transformProp(
111
+ root,
112
+ j,
113
+ {
114
+ matchesImport: source => CORE_IMPORT_RE.test(source),
115
+ components: COMPONENT_PROPS,
116
+ },
117
+ propPath => {
118
+ const opening = propPath.parent?.node;
119
+ const attributes = opening?.attributes ?? [];
120
+ const prop = propPath.node;
121
+ const value =
122
+ prop.value?.type === 'JSXExpressionContainer'
123
+ ? unwrap(prop.value.expression)
124
+ : null;
125
+ const entries =
126
+ value?.type === 'ObjectExpression' ? value.properties : [];
127
+ const presentationEntries = entries.filter(
128
+ (/** @type {any} */ entry) => keyName(entry) === 'presentation',
129
+ );
130
+ const hasUnprovenEntry = entries.some(
131
+ (/** @type {any} */ entry) => keyName(entry) == null,
132
+ );
133
+ if (
134
+ value?.type === 'ObjectExpression' &&
135
+ presentationEntries.length === 0 &&
136
+ !hasUnprovenEntry
137
+ ) {
138
+ return;
139
+ }
140
+ const hasPresentation = attributes.some(
141
+ (/** @type {any} */ a) =>
142
+ a.type === 'JSXAttribute' && a.name?.name === 'presentation',
143
+ );
144
+ const hasSpread = attributes.some(
145
+ (/** @type {any} */ a) => a.type === 'JSXSpreadAttribute',
146
+ );
147
+ const todo =
148
+ value?.type !== 'ObjectExpression'
149
+ ? TODOS.notLiteral
150
+ : hasUnprovenEntry
151
+ ? TODOS.unprovenKey
152
+ : hasPresentation
153
+ ? TODOS.presentationSet
154
+ : presentationEntries.length > 1
155
+ ? TODOS.repeatedKey
156
+ : hasSpread
157
+ ? TODOS.spread
158
+ : null;
159
+ if (todo != null) {
160
+ hasChanges = addComment(j, prop, todo) || hasChanges;
161
+ return;
162
+ }
163
+
164
+ const entry = presentationEntries[0];
165
+ const entryValue = entry.value;
166
+ const literal = unwrap(entryValue);
167
+ const attributeValue =
168
+ (literal?.type === 'StringLiteral' || literal?.type === 'Literal') &&
169
+ typeof literal.value === 'string'
170
+ ? j.stringLiteral(literal.value)
171
+ : j.jsxExpressionContainer(entryValue);
172
+ const presentation = j.jsxAttribute(
173
+ j.jsxIdentifier('presentation'),
174
+ attributeValue,
175
+ );
176
+ value.properties = entries.filter((/** @type {any} */ e) => e !== entry);
177
+ const index = opening.attributes.indexOf(prop);
178
+ if (value.properties.length === 0) {
179
+ opening.attributes.splice(index, 1, presentation);
180
+ } else {
181
+ opening.attributes.splice(index + 1, 0, presentation);
182
+ }
183
+ hasChanges = true;
184
+ },
185
+ );
186
+
187
+ if (!hasChanges) return undefined;
188
+ // `auto` keeps every reprinted string's own quotes and writes the new
189
+ // attribute string in double quotes, as JSX attributes are written.
190
+ return root.toSource({quote: 'auto'});
191
+ }
@@ -140,14 +140,6 @@
140
140
  "kind": "component",
141
141
  "name": "LogStream"
142
142
  },
143
- {
144
- "kind": "component",
145
- "name": "MobilePowerSearch"
146
- },
147
- {
148
- "kind": "component",
149
- "name": "MobileTokenizer"
150
- },
151
143
  {
152
144
  "kind": "component",
153
145
  "name": "RadialChart"
@@ -160,6 +152,10 @@
160
152
  "kind": "component",
161
153
  "name": "Schedule"
162
154
  },
155
+ {
156
+ "kind": "component",
157
+ "name": "SelectableCardGroup"
158
+ },
163
159
  {
164
160
  "kind": "component",
165
161
  "name": "Stat"
@@ -35,7 +35,7 @@ export const docs = {
35
35
  content: [
36
36
  {
37
37
  type: 'prose',
38
- text: 'Nine duration tokens in fast, medium, and slow bands.',
38
+ text: 'Nine duration tokens in fast, medium, and slow bands, and `--duration-exit`, the standard dismissal duration, which follows `--duration-fast`.',
39
39
  },
40
40
  {
41
41
  type: 'token-ref',
@@ -68,6 +68,10 @@ export const docs = {
68
68
  [
69
69
  "--duration-slow-max",
70
70
  "1300ms"
71
+ ],
72
+ [
73
+ "--duration-exit",
74
+ "var(--duration-fast)"
71
75
  ]
72
76
  ]
73
77
  }
@@ -2,7 +2,7 @@
2
2
 
3
3
  // AUTO-GENERATED — do not edit manually.
4
4
  // Run: node scripts/generate-token-docs.mjs
5
- // Total: 285 tokens across 15 categories.
5
+ // Total: 286 tokens across 15 categories.
6
6
 
7
7
  /** @type {import('@astryxdesign/cli/authoring').NamespaceDoc} */
8
8
  export const docs = {
@@ -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: 'useAnnounce',
7
+ name: 'useAnnounce — Filter Result Count',
8
+ displayName: 'useAnnounce — Filter Result Count',
9
+ description:
10
+ 'A product filter that announces its result count with useAnnounce: once typing pauses for 500 ms, a screen reader hears "3 results" or "No results". The count has its own hasReplace instance, as the hook\'s docs advise for a changing value.',
11
+ isReady: true,
12
+ aspectRatio: 4 / 3,
13
+ componentsUsed: ['Card', 'TextInput', 'List', 'Text', 'Layout'],
14
+ };
@@ -0,0 +1,90 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ 'use client';
4
+
5
+ import {useEffect, useRef, useState} from 'react';
6
+ import {Card} from '@astryxdesign/core/Card';
7
+ import {useAnnounce} from '@astryxdesign/core/hooks';
8
+ import {VStack} from '@astryxdesign/core/Layout';
9
+ import {List, ListItem} from '@astryxdesign/core/List';
10
+ import {Text} from '@astryxdesign/core/Text';
11
+ import {TextInput} from '@astryxdesign/core/TextInput';
12
+
13
+ const PRODUCTS = [
14
+ 'Desk lamp',
15
+ 'Desk organizer',
16
+ 'Standing desk',
17
+ 'Office chair',
18
+ 'Chair mat',
19
+ 'Monitor arm',
20
+ 'Monitor stand',
21
+ 'Keyboard tray',
22
+ ];
23
+
24
+ const ANNOUNCE_DELAY_MS = 500;
25
+
26
+ function filterProducts(query: string): string[] {
27
+ const needle = query.trim().toLowerCase();
28
+ return PRODUCTS.filter(product => product.toLowerCase().includes(needle));
29
+ }
30
+
31
+ export default function UseAnnounceHookUsage() {
32
+ const announce = useAnnounce({hasReplace: true});
33
+ const [query, setQuery] = useState('');
34
+ const timerRef = useRef<ReturnType<typeof setTimeout> | null>(null);
35
+ const matches = filterProducts(query);
36
+ const count = matches.length;
37
+
38
+ const handleChange = (value: string) => {
39
+ setQuery(value);
40
+ if (timerRef.current != null) {
41
+ clearTimeout(timerRef.current);
42
+ timerRef.current = null;
43
+ }
44
+ if (value === '') {
45
+ return;
46
+ }
47
+ const nextCount = filterProducts(value).length;
48
+ timerRef.current = setTimeout(() => {
49
+ timerRef.current = null;
50
+ announce(
51
+ nextCount === 0
52
+ ? 'No results'
53
+ : `${nextCount} ${nextCount === 1 ? 'result' : 'results'}`,
54
+ );
55
+ }, ANNOUNCE_DELAY_MS);
56
+ };
57
+
58
+ // A count still pending at unmount would be spoken for a filter that is gone.
59
+ useEffect(() => {
60
+ return () => {
61
+ if (timerRef.current != null) {
62
+ clearTimeout(timerRef.current);
63
+ }
64
+ };
65
+ }, []);
66
+
67
+ return (
68
+ <Card width={360} padding={4}>
69
+ <VStack gap={3}>
70
+ <TextInput
71
+ label="Filter products"
72
+ value={query}
73
+ onChange={handleChange}
74
+ hasClear
75
+ />
76
+ {count === 0 ? (
77
+ <Text type="body" color="secondary">
78
+ No results
79
+ </Text>
80
+ ) : (
81
+ <List density="compact">
82
+ {matches.map(product => (
83
+ <ListItem key={product} label={product} />
84
+ ))}
85
+ </List>
86
+ )}
87
+ </VStack>
88
+ </Card>
89
+ );
90
+ }
@@ -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: 'useFocusTrap',
7
+ name: 'useFocusTrap — Quick Edit Panel',
8
+ displayName: 'useFocusTrap — Quick Edit Panel',
9
+ description:
10
+ 'A custom quick-edit panel, not built on Dialog, that traps focus with useFocusTrap: focusFirst moves focus to its field on open, Tab and Shift+Tab stay inside it, Escape closes it through onEscape, and closing returns focus to the Quick edit button.',
11
+ isReady: true,
12
+ aspectRatio: 4 / 3,
13
+ componentsUsed: ['Card', 'Button', 'TextInput', 'Text', 'Layout'],
14
+ };
@@ -0,0 +1,70 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ 'use client';
4
+
5
+ import {useEffect, useState} from 'react';
6
+ import {Button} from '@astryxdesign/core/Button';
7
+ import {Card} from '@astryxdesign/core/Card';
8
+ import {useFocusTrap} from '@astryxdesign/core/hooks';
9
+ import {HStack, VStack} from '@astryxdesign/core/Layout';
10
+ import {Text} from '@astryxdesign/core/Text';
11
+ import {TextInput} from '@astryxdesign/core/TextInput';
12
+
13
+ export default function UseFocusTrapHookUsage() {
14
+ const [isOpen, setIsOpen] = useState(false);
15
+ const [title, setTitle] = useState('Update onboarding guide');
16
+ const [draft, setDraft] = useState(title);
17
+ const close = () => setIsOpen(false);
18
+ const {containerRef, focusFirst} = useFocusTrap<HTMLDivElement>({
19
+ isActive: isOpen,
20
+ onEscape: close,
21
+ });
22
+
23
+ // Runs after commit, once the panel is mounted and useFocusTrap has recorded
24
+ // the opener, so closing the panel returns focus to it.
25
+ useEffect(() => {
26
+ if (isOpen) {
27
+ focusFirst();
28
+ }
29
+ }, [isOpen, focusFirst]);
30
+
31
+ return (
32
+ <HStack gap={4} vAlign="start">
33
+ <VStack gap={2}>
34
+ <Text type="body" weight="bold">
35
+ {title}
36
+ </Text>
37
+ <Button
38
+ label="Quick edit"
39
+ onClick={() => {
40
+ setDraft(title);
41
+ setIsOpen(true);
42
+ }}
43
+ />
44
+ </VStack>
45
+ {isOpen && (
46
+ <Card
47
+ ref={containerRef}
48
+ role="dialog"
49
+ aria-label="Quick edit"
50
+ width={280}
51
+ padding={4}>
52
+ <VStack gap={3}>
53
+ <TextInput label="Title" value={draft} onChange={setDraft} />
54
+ <HStack gap={2} hAlign="end">
55
+ <Button label="Cancel" variant="secondary" onClick={close} />
56
+ <Button
57
+ label="Save"
58
+ variant="primary"
59
+ onClick={() => {
60
+ setTitle(draft);
61
+ close();
62
+ }}
63
+ />
64
+ </HStack>
65
+ </VStack>
66
+ </Card>
67
+ )}
68
+ </HStack>
69
+ );
70
+ }
@@ -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: 'useHotkeys',
7
+ name: 'useHotkeys — Search and Help Shortcuts',
8
+ displayName: 'useHotkeys — Search and Help Shortcuts',
9
+ description:
10
+ 'Page shortcuts registered with useHotkeys: "/" focuses the search field and "?" opens the shortcut help, while typing either character in the field just types it. A switch turns the single-key shortcuts off through isDisabled.',
11
+ isReady: true,
12
+ aspectRatio: 4 / 3,
13
+ componentsUsed: [
14
+ 'Card',
15
+ 'TextInput',
16
+ 'Button',
17
+ 'Switch',
18
+ 'Dialog',
19
+ 'Kbd',
20
+ 'Text',
21
+ 'Layout',
22
+ ],
23
+ };
@@ -0,0 +1,90 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ 'use client';
4
+
5
+ import {useRef, useState} from 'react';
6
+ import {Button} from '@astryxdesign/core/Button';
7
+ import {Card} from '@astryxdesign/core/Card';
8
+ import {Dialog, DialogHeader} from '@astryxdesign/core/Dialog';
9
+ import {useHotkeys} from '@astryxdesign/core/hooks';
10
+ import {Kbd} from '@astryxdesign/core/Kbd';
11
+ import {
12
+ HStack,
13
+ Layout,
14
+ LayoutContent,
15
+ StackItem,
16
+ VStack,
17
+ } from '@astryxdesign/core/Layout';
18
+ import {Switch} from '@astryxdesign/core/Switch';
19
+ import {Text} from '@astryxdesign/core/Text';
20
+ import {TextInput} from '@astryxdesign/core/TextInput';
21
+
22
+ export default function UseHotkeysHookUsage() {
23
+ const searchRef = useRef<HTMLInputElement>(null);
24
+ const [query, setQuery] = useState('');
25
+ const [isHelpOpen, setIsHelpOpen] = useState(false);
26
+ // Single-character shortcuts need an off switch (WCAG 2.1.4).
27
+ const [hasShortcuts, setHasShortcuts] = useState(true);
28
+
29
+ useHotkeys([
30
+ {
31
+ keys: '/',
32
+ onPress: () => searchRef.current?.focus(),
33
+ isDisabled: !hasShortcuts,
34
+ },
35
+ {
36
+ keys: '?',
37
+ onPress: () => setIsHelpOpen(true),
38
+ isDisabled: !hasShortcuts,
39
+ },
40
+ ]);
41
+
42
+ return (
43
+ <Card width={480} padding={4}>
44
+ <VStack gap={3}>
45
+ <HStack gap={2} vAlign="center">
46
+ <StackItem size="fill">
47
+ <TextInput
48
+ ref={searchRef}
49
+ label="Search"
50
+ isLabelHidden
51
+ placeholder="Search projects"
52
+ value={query}
53
+ onChange={setQuery}
54
+ />
55
+ </StackItem>
56
+ <Button label="Shortcuts" onClick={() => setIsHelpOpen(true)} />
57
+ </HStack>
58
+ <Switch
59
+ label="Single-key shortcuts"
60
+ value={hasShortcuts}
61
+ onChange={setHasShortcuts}
62
+ />
63
+ </VStack>
64
+ <Dialog isOpen={isHelpOpen} onOpenChange={setIsHelpOpen}>
65
+ <Layout
66
+ header={
67
+ <DialogHeader
68
+ title="Keyboard shortcuts"
69
+ onOpenChange={setIsHelpOpen}
70
+ />
71
+ }
72
+ content={
73
+ <LayoutContent>
74
+ <VStack gap={2}>
75
+ <HStack gap={2} vAlign="center">
76
+ <Kbd keys="/" />
77
+ <Text type="body">Focus search</Text>
78
+ </HStack>
79
+ <HStack gap={2} vAlign="center">
80
+ <Kbd keys="?" />
81
+ <Text type="body">Show this help</Text>
82
+ </HStack>
83
+ </VStack>
84
+ </LayoutContent>
85
+ }
86
+ />
87
+ </Dialog>
88
+ </Card>
89
+ );
90
+ }
@@ -7,17 +7,9 @@ export const doc = {
7
7
  name: 'useKeyboardHint — Arrow-key Hint',
8
8
  displayName: 'useKeyboardHint — Arrow-key Hint',
9
9
  description:
10
- 'Toolbar shows an ephemeral "← → to navigate" hint on first keyboard focus via useKeyboardHint, teaching sighted keyboard users that arrows move within the group.',
10
+ 'A custom five-star rating with one Tab stop calls useKeyboardHint directly: tabbing into it shows a "← → to navigate" hint, the first arrow press dismisses it, and tabbing back in does not show it again.',
11
11
  isReady: true,
12
12
  aspectRatio: 16 / 9,
13
- componentsUsed: [
14
- 'Toolbar',
15
- 'Button',
16
- 'Icon',
17
- 'Card',
18
- 'Section',
19
- 'Text',
20
- 'Layout',
21
- ],
22
- icons: {BoldIcon: 'bold', ItalicIcon: 'italic', UnderlineIcon: 'underline'},
13
+ componentsUsed: ['Button', 'Icon', 'Card', 'Layout'],
14
+ icons: {StarIcon: 'star'},
23
15
  };