@astryxdesign/cli 0.7.8-canary.ed33727 → 0.7.8-canary.f10bc91

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,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: 'useTreeFocus',
7
+ name: 'useTreeFocus — Keyboard File Tree',
8
+ displayName: 'useTreeFocus — Keyboard File Tree',
9
+ description:
10
+ 'A custom file tree built from plain rows with tree roles. useTreeFocus gives it the WAI-ARIA tree keyboard model: ArrowUp and ArrowDown move over the visible rows, ArrowRight opens a folder or moves into it, ArrowLeft closes it or moves to its parent, Home and End jump to the ends, a typed letter jumps to a matching name, Enter opens a file, and only one row is in the tab order.',
11
+ isReady: true,
12
+ aspectRatio: 4 / 3,
13
+ componentsUsed: ['Icon', 'Text', 'Layout'],
14
+ icons: {ChevronDownIcon: 'chevronDown', ChevronRightIcon: 'chevronRight'},
15
+ };
@@ -0,0 +1,98 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ 'use client';
4
+
5
+ import {useState} from 'react';
6
+ import {useTreeFocus} from '@astryxdesign/core/hooks';
7
+ import {Icon} from '@astryxdesign/core/Icon';
8
+ import {HStack, VStack} from '@astryxdesign/core/Layout';
9
+ import {Text} from '@astryxdesign/core/Text';
10
+ import {rtlStyles} from '@astryxdesign/core/utils';
11
+ import {ChevronDownIcon, ChevronRightIcon} from '@heroicons/react/24/outline';
12
+
13
+ type FileNode = {name: string; children?: FileNode[]};
14
+
15
+ const FILES: FileNode[] = [
16
+ {name: 'src', children: [{name: 'index.ts'}, {name: 'theme.ts'}]},
17
+ {name: 'docs', children: [{name: 'intro.md'}, {name: 'usage.md'}]},
18
+ {name: 'package.json'},
19
+ {name: 'README.md'},
20
+ ];
21
+
22
+ const FOLDERS = new Set(
23
+ FILES.filter(node => node.children != null).map(node => node.name),
24
+ );
25
+
26
+ export default function UseTreeFocusHookUsage() {
27
+ const [expanded, setExpanded] = useState<ReadonlySet<string>>(
28
+ () => new Set(['src']),
29
+ );
30
+ const [openFile, setOpenFile] = useState<string | null>(null);
31
+ const toggle = (name: string) =>
32
+ setExpanded(current => {
33
+ const next = new Set(current);
34
+ if (!next.delete(name)) {
35
+ next.add(name);
36
+ }
37
+ return next;
38
+ });
39
+ const {treeRef, handleKeyDown, handleFocus} = useTreeFocus({
40
+ hasRovingTabIndex: true,
41
+ onToggleExpand: toggle,
42
+ onActivate: (_item, name) => {
43
+ if (name == null || FOLDERS.has(name)) {
44
+ return false;
45
+ }
46
+ setOpenFile(name);
47
+ return true;
48
+ },
49
+ });
50
+
51
+ const renderRow = (node: FileNode, level: 1 | 2) => {
52
+ const isFolder = node.children != null;
53
+ const isExpanded = expanded.has(node.name);
54
+ return (
55
+ <HStack
56
+ key={node.name}
57
+ role="treeitem"
58
+ aria-level={level}
59
+ aria-expanded={isFolder ? isExpanded : undefined}
60
+ aria-selected={isFolder ? undefined : openFile === node.name}
61
+ data-tree-id={node.name}
62
+ gap={1}
63
+ vAlign="center"
64
+ paddingInlineStart={isFolder ? 0 : level === 1 ? 5 : 10}
65
+ onClick={() => (isFolder ? toggle(node.name) : setOpenFile(node.name))}>
66
+ {isFolder &&
67
+ (isExpanded ? (
68
+ <Icon icon={ChevronDownIcon} />
69
+ ) : (
70
+ // The collapsed chevron points toward the inline end, where
71
+ // ArrowRight (ArrowLeft under RTL) opens the folder.
72
+ <Icon icon={ChevronRightIcon} xstyle={rtlStyles.mirror} />
73
+ ))}
74
+ <Text type="body">{node.name}</Text>
75
+ </HStack>
76
+ );
77
+ };
78
+
79
+ return (
80
+ <VStack gap={3} width={240}>
81
+ <VStack
82
+ ref={treeRef}
83
+ role="tree"
84
+ aria-label="Files"
85
+ gap={1}
86
+ onKeyDown={handleKeyDown}
87
+ onFocus={handleFocus}>
88
+ {FILES.flatMap(node => [
89
+ renderRow(node, 1),
90
+ ...(expanded.has(node.name)
91
+ ? (node.children ?? []).map(child => renderRow(child, 2))
92
+ : []),
93
+ ])}
94
+ </VStack>
95
+ <Text type="supporting">Open file: {openFile ?? 'none'}</Text>
96
+ </VStack>
97
+ );
98
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@astryxdesign/cli",
3
- "version": "0.7.8-canary.ed33727",
3
+ "version": "0.7.8-canary.f10bc91",
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.8-canary.ed33727",
128
- "@astryxdesign/core": "0.7.8-canary.ed33727",
129
- "@astryxdesign/lab": "0.7.8-canary.ed33727",
130
- "@astryxdesign/theme-neutral": "0.7.8-canary.ed33727"
127
+ "@astryxdesign/charts": "0.7.8-canary.f10bc91",
128
+ "@astryxdesign/core": "0.7.8-canary.f10bc91",
129
+ "@astryxdesign/lab": "0.7.8-canary.f10bc91",
130
+ "@astryxdesign/theme-neutral": "0.7.8-canary.f10bc91"
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.8-canary.ed33727",
148
- "@astryxdesign/core": "0.7.8-canary.ed33727",
149
- "@astryxdesign/lab": "0.7.8-canary.ed33727",
150
- "@astryxdesign/theme-neutral": "0.7.8-canary.ed33727",
147
+ "@astryxdesign/charts": "0.7.8-canary.f10bc91",
148
+ "@astryxdesign/core": "0.7.8-canary.f10bc91",
149
+ "@astryxdesign/lab": "0.7.8-canary.f10bc91",
150
+ "@astryxdesign/theme-neutral": "0.7.8-canary.f10bc91",
151
151
  "@heroicons/react": "^2.2.0",
152
152
  "@stylexjs/stylex": "^0.19.0",
153
153
  "@types/babel__core": "^7.20.5",