@astryxdesign/cli 0.7.10-canary.2c66211 → 0.7.10-canary.62f5ebc

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,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
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@astryxdesign/cli",
3
- "version": "0.7.10-canary.2c66211",
3
+ "version": "0.7.10-canary.62f5ebc",
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.2c66211",
128
- "@astryxdesign/core": "0.7.10-canary.2c66211",
129
- "@astryxdesign/lab": "0.7.10-canary.2c66211",
130
- "@astryxdesign/theme-neutral": "0.7.10-canary.2c66211"
127
+ "@astryxdesign/charts": "0.7.10-canary.62f5ebc",
128
+ "@astryxdesign/core": "0.7.10-canary.62f5ebc",
129
+ "@astryxdesign/lab": "0.7.10-canary.62f5ebc",
130
+ "@astryxdesign/theme-neutral": "0.7.10-canary.62f5ebc"
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.2c66211",
148
- "@astryxdesign/core": "0.7.10-canary.2c66211",
149
- "@astryxdesign/lab": "0.7.10-canary.2c66211",
150
- "@astryxdesign/theme-neutral": "0.7.10-canary.2c66211",
147
+ "@astryxdesign/charts": "0.7.10-canary.62f5ebc",
148
+ "@astryxdesign/core": "0.7.10-canary.62f5ebc",
149
+ "@astryxdesign/lab": "0.7.10-canary.62f5ebc",
150
+ "@astryxdesign/theme-neutral": "0.7.10-canary.62f5ebc",
151
151
  "@heroicons/react": "^2.2.0",
152
152
  "@stylexjs/stylex": "^0.19.0",
153
153
  "@types/babel__core": "^7.20.5",