@astryxdesign/cli 0.7.7-canary.d111827 → 0.7.7-canary.e02c955

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,14 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ /** @type {import('@astryxdesign/cli/authoring').TemplateDoc} */
4
+ export const doc = {
5
+ type: 'block',
6
+ exampleFor: 'useCombobox',
7
+ name: 'useCombobox — Assign To Field',
8
+ displayName: 'useCombobox — Assign To Field',
9
+ description:
10
+ 'An "Assign to" TextInput and a list of Item rows, with the field, listbox and option props from useCombobox spread onto them: typing filters a list of teammates, ArrowUp and ArrowDown move the active option while focus stays in the input, Enter picks it and Escape closes the list.',
11
+ isReady: true,
12
+ aspectRatio: 4 / 3,
13
+ componentsUsed: ['Card', 'TextInput', 'Item', 'Text', 'Layout'],
14
+ };
@@ -0,0 +1,113 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ 'use client';
4
+
5
+ import {useId, useState} from 'react';
6
+ import {Card} from '@astryxdesign/core/Card';
7
+ import {useAnnounce} from '@astryxdesign/core/hooks';
8
+ import {Item} from '@astryxdesign/core/Item';
9
+ import {VStack} from '@astryxdesign/core/Layout';
10
+ import {useCombobox} from '@astryxdesign/core/Selector';
11
+ import {Text} from '@astryxdesign/core/Text';
12
+ import {TextInput} from '@astryxdesign/core/TextInput';
13
+
14
+ type Teammate = {value: string; label: string; disabled?: boolean};
15
+
16
+ const TEAMMATES: Teammate[] = [
17
+ {value: 'ada', label: 'Ada Lovelace'},
18
+ {value: 'alan', label: 'Alan Turing'},
19
+ {value: 'grace', label: 'Grace Hopper (away)', disabled: true},
20
+ {value: 'katherine', label: 'Katherine Johnson'},
21
+ {value: 'margaret', label: 'Margaret Hamilton'},
22
+ ];
23
+
24
+ function matching(query: string): Teammate[] {
25
+ const needle = query.trim().toLowerCase();
26
+ return TEAMMATES.filter(teammate =>
27
+ teammate.label.toLowerCase().includes(needle),
28
+ );
29
+ }
30
+
31
+ export default function UseComboboxHookUsage() {
32
+ const listboxId = useId();
33
+ const announce = useAnnounce({hasReplace: true});
34
+ const [query, setQuery] = useState('');
35
+ const [isOpen, setIsOpen] = useState(false);
36
+ const [assignee, setAssignee] = useState<string>();
37
+ const options = matching(query);
38
+
39
+ const combobox = useCombobox({
40
+ selectableItems: options,
41
+ isOpen,
42
+ onOpen: () => setIsOpen(true),
43
+ onClose: () => setIsOpen(false),
44
+ onSelect: value => {
45
+ setAssignee(TEAMMATES.find(teammate => teammate.value === value)?.label);
46
+ setQuery('');
47
+ },
48
+ listboxId,
49
+ });
50
+
51
+ return (
52
+ <Card width={320} padding={4}>
53
+ <VStack gap={2}>
54
+ <TextInput
55
+ label="Assign to"
56
+ value={query}
57
+ onChange={next => {
58
+ const matches = matching(next);
59
+ setQuery(next);
60
+ setIsOpen(true);
61
+ // A new query makes its first enabled match active, so Enter
62
+ // picks it.
63
+ combobox.setHighlightedIndex(
64
+ matches.findIndex(teammate => !teammate.disabled),
65
+ );
66
+ if (next.trim() !== query.trim()) {
67
+ announce(
68
+ matches.length === 0
69
+ ? 'No one matches'
70
+ : matches.length === 1
71
+ ? '1 teammate'
72
+ : `${matches.length} teammates`,
73
+ );
74
+ }
75
+ }}
76
+ onBlur={() => {
77
+ setIsOpen(false);
78
+ combobox.setHighlightedIndex(-1);
79
+ }}
80
+ {...combobox.getFieldProps()}
81
+ />
82
+ {isOpen && options.length > 0 ? (
83
+ <VStack
84
+ as="ul"
85
+ gap={0}
86
+ aria-label="Teammates"
87
+ {...combobox.getListboxProps()}>
88
+ {options.map((teammate, index) => (
89
+ <Item
90
+ key={teammate.value}
91
+ as="li"
92
+ density="compact"
93
+ label={teammate.label}
94
+ isHighlighted={index === combobox.highlightedIndex}
95
+ // Item writes aria-selected from isSelected, so the active
96
+ // option has to be passed here to keep aria-selected="true".
97
+ isSelected={index === combobox.highlightedIndex}
98
+ isDisabled={teammate.disabled}
99
+ {...combobox.getOptionProps(index)}
100
+ />
101
+ ))}
102
+ </VStack>
103
+ ) : null}
104
+ {isOpen && options.length === 0 ? (
105
+ <Text type="supporting">No one matches</Text>
106
+ ) : null}
107
+ <Text type="supporting">
108
+ {assignee == null ? 'Unassigned' : `Assigned to ${assignee}`}
109
+ </Text>
110
+ </VStack>
111
+ </Card>
112
+ );
113
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@astryxdesign/cli",
3
- "version": "0.7.7-canary.d111827",
3
+ "version": "0.7.7-canary.e02c955",
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.7-canary.d111827",
128
- "@astryxdesign/core": "0.7.7-canary.d111827",
129
- "@astryxdesign/lab": "0.7.7-canary.d111827",
130
- "@astryxdesign/theme-neutral": "0.7.7-canary.d111827"
127
+ "@astryxdesign/charts": "0.7.7-canary.e02c955",
128
+ "@astryxdesign/core": "0.7.7-canary.e02c955",
129
+ "@astryxdesign/lab": "0.7.7-canary.e02c955",
130
+ "@astryxdesign/theme-neutral": "0.7.7-canary.e02c955"
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.7-canary.d111827",
148
- "@astryxdesign/core": "0.7.7-canary.d111827",
149
- "@astryxdesign/lab": "0.7.7-canary.d111827",
150
- "@astryxdesign/theme-neutral": "0.7.7-canary.d111827",
147
+ "@astryxdesign/charts": "0.7.7-canary.e02c955",
148
+ "@astryxdesign/core": "0.7.7-canary.e02c955",
149
+ "@astryxdesign/lab": "0.7.7-canary.e02c955",
150
+ "@astryxdesign/theme-neutral": "0.7.7-canary.e02c955",
151
151
  "@heroicons/react": "^2.2.0",
152
152
  "@stylexjs/stylex": "^0.19.0",
153
153
  "@types/babel__core": "^7.20.5",