torch-glare 2.3.0 → 2.4.1

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 (264) hide show
  1. package/README.md +8 -0
  2. package/apps/lib/components/ActionButton.tsx +7 -12
  3. package/apps/lib/components/ActionsGroup.tsx +4 -15
  4. package/apps/lib/components/AlertDialog.tsx +173 -191
  5. package/apps/lib/components/Avatar.tsx +13 -16
  6. package/apps/lib/components/Badge.tsx +7 -3
  7. package/apps/lib/components/BadgeField.tsx +76 -71
  8. package/apps/lib/components/Breadcrumb.tsx +49 -85
  9. package/apps/lib/components/Button.tsx +20 -19
  10. package/apps/lib/components/ButtonGroup.tsx +31 -41
  11. package/apps/lib/components/Calendar.tsx +51 -29
  12. package/apps/lib/components/Card.tsx +2 -13
  13. package/apps/lib/components/ChartBlockTool.ts +17 -52
  14. package/apps/lib/components/Checkbox.tsx +9 -16
  15. package/apps/lib/components/ContextMenu.tsx +110 -106
  16. package/apps/lib/components/CountBadge.tsx +4 -6
  17. package/apps/lib/components/DataTable.tsx +196 -216
  18. package/apps/lib/components/DataViews/DataViewRadio.tsx +10 -8
  19. package/apps/lib/components/DataViews/DataViewsConfigPanel.tsx +21 -55
  20. package/apps/lib/components/DataViews/DataViewsHeader.tsx +1 -3
  21. package/apps/lib/components/DataViews/DataViewsLayout.tsx +5 -12
  22. package/apps/lib/components/DataViews/FilterPanel.tsx +173 -150
  23. package/apps/lib/components/DataViews/HeaderSearch.tsx +1 -5
  24. package/apps/lib/components/DataViews/InboxView.tsx +22 -68
  25. package/apps/lib/components/DataViews/InboxViewCard.tsx +68 -77
  26. package/apps/lib/components/DataViews/KanbanView.tsx +8 -25
  27. package/apps/lib/components/DataViews/PanelControls.tsx +3 -13
  28. package/apps/lib/components/DataViews/SettingsPanel.tsx +83 -89
  29. package/apps/lib/components/DataViews/TableView.tsx +8 -28
  30. package/apps/lib/components/DataViews/TreeView.tsx +12 -40
  31. package/apps/lib/components/DataViews/badgeAdapter.ts +32 -28
  32. package/apps/lib/components/DataViews/fieldRenderers.tsx +106 -141
  33. package/apps/lib/components/DataViews/filters/DatePickerRangeFilter.tsx +87 -0
  34. package/apps/lib/components/DataViews/filters/DateRangePopover.tsx +39 -32
  35. package/apps/lib/components/DataViews/filters/PresetChips.tsx +15 -15
  36. package/apps/lib/components/DataViews/filters/RangeSliderWithInputs.tsx +69 -58
  37. package/apps/lib/components/DataViews/index.ts +26 -26
  38. package/apps/lib/components/DataViews/tree/TreeDrawer.tsx +12 -16
  39. package/apps/lib/components/DataViews/tree/TreeSidebar.tsx +28 -31
  40. package/apps/lib/components/DataViews/types.ts +111 -114
  41. package/apps/lib/components/DatePicker.tsx +198 -191
  42. package/apps/lib/components/Dialog.tsx +92 -105
  43. package/apps/lib/components/Divider.tsx +21 -24
  44. package/apps/lib/components/Drawer.tsx +79 -139
  45. package/apps/lib/components/DropdownMenu.tsx +144 -181
  46. package/apps/lib/components/FieldHint.tsx +4 -11
  47. package/apps/lib/components/Form.tsx +146 -155
  48. package/apps/lib/components/FormStepper.tsx +9 -39
  49. package/apps/lib/components/HeaderBar.tsx +119 -0
  50. package/apps/lib/components/ImageAttachment.tsx +111 -73
  51. package/apps/lib/components/InnerLabelField.tsx +20 -16
  52. package/apps/lib/components/Input.tsx +171 -172
  53. package/apps/lib/components/InputField.tsx +44 -45
  54. package/apps/lib/components/InputOTP.tsx +68 -69
  55. package/apps/lib/components/Label.tsx +31 -35
  56. package/apps/lib/components/LabelField.tsx +4 -5
  57. package/apps/lib/components/LabeledCheckBox.tsx +8 -12
  58. package/apps/lib/components/LabeledRadio.tsx +7 -5
  59. package/apps/lib/components/LinkButton.tsx +2 -9
  60. package/apps/lib/components/LoginButton.tsx +4 -9
  61. package/apps/lib/components/PasswordLevel.tsx +5 -5
  62. package/apps/lib/components/Popover.tsx +15 -33
  63. package/apps/lib/components/ProfileMenu.tsx +67 -72
  64. package/apps/lib/components/Radio.tsx +1 -5
  65. package/apps/lib/components/RadioCard.tsx +9 -28
  66. package/apps/lib/components/ScrollArea.tsx +45 -43
  67. package/apps/lib/components/SearchField.tsx +49 -39
  68. package/apps/lib/components/SearchableSelect.tsx +46 -52
  69. package/apps/lib/components/SearchableTable.tsx +199 -219
  70. package/apps/lib/components/SearchableTree.tsx +469 -0
  71. package/apps/lib/components/SearchableTreeDialog.tsx +493 -0
  72. package/apps/lib/components/SectionBlock.tsx +4 -16
  73. package/apps/lib/components/Select.tsx +53 -80
  74. package/apps/lib/components/SimpleSelect.tsx +196 -187
  75. package/apps/lib/components/Skeleton.tsx +9 -12
  76. package/apps/lib/components/SlideDatePicker.tsx +215 -166
  77. package/apps/lib/components/SpinLoading.tsx +33 -49
  78. package/apps/lib/components/Stepper.tsx +13 -56
  79. package/apps/lib/components/Switch.tsx +8 -10
  80. package/apps/lib/components/TabFormItem.tsx +3 -12
  81. package/apps/lib/components/TabSwitch.tsx +7 -34
  82. package/apps/lib/components/Table.tsx +60 -75
  83. package/apps/lib/components/TableDnDWrapper.ts +15 -48
  84. package/apps/lib/components/TextEditor.tsx +93 -104
  85. package/apps/lib/components/Textarea.tsx +8 -12
  86. package/apps/lib/components/Timeline.tsx +21 -41
  87. package/apps/lib/components/Toast.tsx +83 -83
  88. package/apps/lib/components/Toggle.tsx +112 -114
  89. package/apps/lib/components/ToggleButton.tsx +1 -1
  90. package/apps/lib/components/Tooltip.tsx +24 -19
  91. package/apps/lib/components/TransparentLabel.tsx +61 -62
  92. package/apps/lib/components/TreeDropDown.tsx +86 -52
  93. package/apps/lib/components/TreeFolder/TreeFolder.tsx +15 -48
  94. package/apps/lib/components/TreeFolder/TreeFolderBreadcrumb.tsx +16 -21
  95. package/apps/lib/components/TreeFolder/TreeFolderRow.tsx +9 -20
  96. package/apps/lib/components/TreeFolder/TreeFolderStyles.tsx +3 -3
  97. package/apps/lib/components/TreeFolder/icons.tsx +14 -17
  98. package/apps/lib/components/TreeFolder/index.ts +15 -8
  99. package/apps/lib/components/TreeFolder/treeFolderUtils.ts +47 -52
  100. package/apps/lib/components/TreeFolder/types.ts +32 -32
  101. package/apps/lib/components/TreeFolder/useTreeFolderDnD.ts +117 -123
  102. package/apps/lib/hooks/useActiveTreeItem.ts +52 -55
  103. package/apps/lib/hooks/useClickOutside.ts +21 -20
  104. package/apps/lib/hooks/useDataViewsState.ts +86 -80
  105. package/apps/lib/hooks/useIsMobile.ts +12 -12
  106. package/apps/lib/hooks/useResize.ts +54 -65
  107. package/apps/lib/hooks/useTagSelection.ts +201 -201
  108. package/apps/lib/layouts/CNLayout.tsx +181 -140
  109. package/apps/lib/layouts/DataViewCard.tsx +4 -18
  110. package/apps/lib/layouts/FieldSection.tsx +2 -6
  111. package/apps/lib/layouts/TreeSubLayout.tsx +24 -38
  112. package/apps/lib/providers/ThemeProvider.tsx +8 -23
  113. package/apps/lib/registry.json +1004 -0
  114. package/apps/lib/tsconfig.json +9 -0
  115. package/apps/lib/utils/cn.ts +1 -1
  116. package/apps/lib/utils/dataViews/columnUtils.ts +46 -44
  117. package/apps/lib/utils/dataViews/fieldUtils.ts +70 -71
  118. package/apps/lib/utils/dataViews/nestedDataUtils.tsx +129 -122
  119. package/apps/lib/utils/dataViews/pathUtils.ts +74 -67
  120. package/apps/lib/utils/dataViews/rangeUtils.ts +121 -112
  121. package/apps/lib/utils/dataViews/treeUtils.ts +204 -211
  122. package/apps/lib/utils/dateFormat.ts +64 -54
  123. package/apps/lib/utils/markdownParser.ts +2 -7
  124. package/apps/lib/utils/resize.ts +21 -25
  125. package/apps/lib/utils/types.ts +13 -13
  126. package/dist/bin/index.js +8 -2
  127. package/dist/bin/index.js.map +1 -1
  128. package/dist/src/shared/getAvailableFiles.d.ts.map +1 -1
  129. package/dist/src/shared/getAvailableFiles.js +6 -1
  130. package/dist/src/shared/getAvailableFiles.js.map +1 -1
  131. package/dist/src/shared/loadRegistry.d.ts +7 -0
  132. package/dist/src/shared/loadRegistry.d.ts.map +1 -0
  133. package/dist/src/shared/loadRegistry.js +31 -0
  134. package/dist/src/shared/loadRegistry.js.map +1 -0
  135. package/dist/src/shared/resolveInstallPlan.d.ts +12 -0
  136. package/dist/src/shared/resolveInstallPlan.d.ts.map +1 -0
  137. package/dist/src/shared/resolveInstallPlan.js +39 -0
  138. package/dist/src/shared/resolveInstallPlan.js.map +1 -0
  139. package/dist/src/types/main.d.ts +24 -0
  140. package/dist/src/types/main.d.ts.map +1 -1
  141. package/docs/README.md +10 -2
  142. package/docs/components/action-button.md +30 -24
  143. package/docs/components/actions-group.md +26 -20
  144. package/docs/components/alert-dialog.md +45 -45
  145. package/docs/components/avatar.md +6 -2
  146. package/docs/components/badge-field.md +6 -2
  147. package/docs/components/badge.md +7 -1
  148. package/docs/components/breadcrumb.md +15 -40
  149. package/docs/components/button-group.md +13 -10
  150. package/docs/components/button.md +58 -33
  151. package/docs/components/calendar.md +26 -19
  152. package/docs/components/card.md +19 -16
  153. package/docs/components/chart-block-tool.md +128 -0
  154. package/docs/components/checkbox.md +16 -8
  155. package/docs/components/cn-layout.md +7 -1
  156. package/docs/components/context-menu.md +47 -24
  157. package/docs/components/count-badge.md +7 -1
  158. package/docs/components/data-table.md +45 -33
  159. package/docs/components/data-views-config-panel.md +18 -14
  160. package/docs/components/data-views-layout.md +20 -17
  161. package/docs/components/date-picker.md +30 -23
  162. package/docs/components/dialog.md +43 -42
  163. package/docs/components/divider.md +10 -4
  164. package/docs/components/drawer.md +8 -33
  165. package/docs/components/dropdown-menu.md +51 -32
  166. package/docs/components/field-hint.md +37 -25
  167. package/docs/components/field-section.md +9 -3
  168. package/docs/components/form-stepper.md +6 -0
  169. package/docs/components/form.md +17 -20
  170. package/docs/components/header-bar.md +187 -0
  171. package/docs/components/image-attachment.md +33 -41
  172. package/docs/components/inbox-view.md +16 -5
  173. package/docs/components/inner-label-field.md +34 -24
  174. package/docs/components/input-field.md +18 -10
  175. package/docs/components/input-otp.md +14 -11
  176. package/docs/components/input.md +22 -16
  177. package/docs/components/kanban-view.md +15 -5
  178. package/docs/components/label-field.md +32 -22
  179. package/docs/components/label.md +43 -32
  180. package/docs/components/labeled-check-box.md +16 -8
  181. package/docs/components/labeled-radio.md +18 -11
  182. package/docs/components/link-button.md +7 -1
  183. package/docs/components/login-button.md +8 -2
  184. package/docs/components/password-level.md +37 -24
  185. package/docs/components/popover.md +26 -23
  186. package/docs/components/profile-menu.md +38 -27
  187. package/docs/components/radio-card.md +16 -9
  188. package/docs/components/radio.md +16 -8
  189. package/docs/components/scroll-area.md +6 -2
  190. package/docs/components/search-field.md +14 -6
  191. package/docs/components/searchable-select.md +19 -14
  192. package/docs/components/searchable-table.md +60 -41
  193. package/docs/components/searchable-tree-dialog.md +190 -0
  194. package/docs/components/searchable-tree.md +200 -0
  195. package/docs/components/section-block.md +130 -4
  196. package/docs/components/select.md +23 -18
  197. package/docs/components/simple-select.md +14 -10
  198. package/docs/components/skeleton.md +43 -33
  199. package/docs/components/slide-date-picker.md +37 -29
  200. package/docs/components/spin-loading.md +32 -23
  201. package/docs/components/stepper.md +6 -0
  202. package/docs/components/switch.md +14 -6
  203. package/docs/components/tab-form-item.md +7 -1
  204. package/docs/components/tab-switch.md +13 -6
  205. package/docs/components/table-dnd-wrapper.md +105 -0
  206. package/docs/components/table-view.md +15 -5
  207. package/docs/components/table.md +28 -28
  208. package/docs/components/text-editor.md +19 -13
  209. package/docs/components/textarea.md +15 -7
  210. package/docs/components/timeline.md +6 -0
  211. package/docs/components/toast.md +35 -26
  212. package/docs/components/toggle-button.md +24 -21
  213. package/docs/components/toggle.md +23 -15
  214. package/docs/components/tooltip.md +42 -30
  215. package/docs/components/transparent-label.md +29 -20
  216. package/docs/components/tree-drop-down.md +31 -23
  217. package/docs/components/tree-sub-layout.md +6 -2
  218. package/docs/components/tree-view.md +16 -5
  219. package/docs/explanation/architecture.md +54 -0
  220. package/docs/explanation/design-system.md +52 -0
  221. package/docs/how-to/data-views-from-backend-response.md +7 -4
  222. package/docs/how-to/guides.md +24 -18
  223. package/docs/migration/changelog.md +38 -0
  224. package/docs/reference/cli.md +87 -0
  225. package/docs/reference/components.md +11 -12
  226. package/docs/reference/hooks.md +8 -8
  227. package/docs/reference/providers.md +22 -22
  228. package/docs/reference/tailwind-plugins.md +2 -2
  229. package/docs/reference/theme.md +85 -0
  230. package/docs/reference/types.md +4 -4
  231. package/docs/reference/utilities.md +19 -26
  232. package/docs/tutorials/building-first-form.md +20 -13
  233. package/docs/tutorials/component-composition.md +34 -50
  234. package/docs/tutorials/getting-started.md +2 -2
  235. package/docs/tutorials/theming-basics.md +13 -10
  236. package/package.json +31 -3
  237. package/dist/src/commands/block.d.ts +0 -5
  238. package/dist/src/commands/block.d.ts.map +0 -1
  239. package/dist/src/commands/block.js +0 -255
  240. package/dist/src/commands/block.js.map +0 -1
  241. package/dist/src/shared/configureFonts.d.ts +0 -6
  242. package/dist/src/shared/configureFonts.d.ts.map +0 -1
  243. package/dist/src/shared/configureFonts.js +0 -106
  244. package/dist/src/shared/configureFonts.js.map +0 -1
  245. package/dist/src/shared/configureGlobalCss.d.ts +0 -6
  246. package/dist/src/shared/configureGlobalCss.d.ts.map +0 -1
  247. package/dist/src/shared/configureGlobalCss.js +0 -154
  248. package/dist/src/shared/configureGlobalCss.js.map +0 -1
  249. package/dist/src/shared/configureTailwind.d.ts +0 -7
  250. package/dist/src/shared/configureTailwind.d.ts.map +0 -1
  251. package/dist/src/shared/configureTailwind.js +0 -163
  252. package/dist/src/shared/configureTailwind.js.map +0 -1
  253. package/dist/src/shared/detectFramework.d.ts +0 -23
  254. package/dist/src/shared/detectFramework.d.ts.map +0 -1
  255. package/dist/src/shared/detectFramework.js +0 -119
  256. package/dist/src/shared/detectFramework.js.map +0 -1
  257. package/dist/src/shared/installBaseUtils.d.ts +0 -5
  258. package/dist/src/shared/installBaseUtils.d.ts.map +0 -1
  259. package/dist/src/shared/installBaseUtils.js +0 -79
  260. package/dist/src/shared/installBaseUtils.js.map +0 -1
  261. package/dist/src/shared/resolveAliases.d.ts +0 -24
  262. package/dist/src/shared/resolveAliases.d.ts.map +0 -1
  263. package/dist/src/shared/resolveAliases.js +0 -98
  264. package/dist/src/shared/resolveAliases.js.map +0 -1
@@ -0,0 +1,493 @@
1
+ "use client";
2
+
3
+ import {
4
+ forwardRef,
5
+ InputHTMLAttributes,
6
+ ReactNode,
7
+ useEffect,
8
+ useMemo,
9
+ useRef,
10
+ useState,
11
+ } from "react";
12
+ import { cn } from "../utils/cn";
13
+ import { Themes } from "../utils/types";
14
+ import { Dialog, DialogTrigger, DialogContent, DialogTitle } from "./Dialog";
15
+ import { Icon, Input, Group } from "./Input";
16
+ import { Button, LoadingIcon } from "./Button";
17
+
18
+ /**
19
+ * SearchableTreeDialog — a field that opens a modal Dialog to pick a node from a tree.
20
+ *
21
+ * Same layout as SearchableTable (trigger → dialog with a search input + a
22
+ * scrollable area), but the area renders a hierarchical tree instead of a table.
23
+ *
24
+ * Interaction (matches the Figma `Search.Overlay` design):
25
+ * • A FOLDER row (a node with children) toggles expand/collapse on click —
26
+ * folders are not selectable.
27
+ * • A LEAF row (no children) selects the node and closes the dialog.
28
+ * Nesting is shown with indentation + a vertical connector rail per level
29
+ * (no chevron). Search filters matching nodes and keeps/expands ancestors.
30
+ *
31
+ * Accepts either NESTED data (each node exposes its children via getNodeChildren)
32
+ * or FLAT data (pass `parentIdKey` and it builds the tree internally).
33
+ */
34
+
35
+ interface Props<T> {
36
+ /** Tree nodes. Nested by default; flat when `parentIdKey` is provided. */
37
+ nodes: T[];
38
+ getNodeId: (node: T) => string;
39
+ getNodeLabel: (node: T) => ReactNode;
40
+ /** Returns a node's children (nested mode). Ignored when `parentIdKey` is set. */
41
+ getNodeChildren?: (node: T) => T[] | undefined;
42
+ /**
43
+ * When set, `nodes` is treated as a FLAT list and the tree is built from this
44
+ * key (each item's parent id). Root items have a nullish parent id.
45
+ */
46
+ parentIdKey?: keyof T & string;
47
+
48
+ /** Controlled selected node (optional). */
49
+ value?: T | null;
50
+ onSelect?: (node: T) => void;
51
+
52
+ /** Plain-text label used for search matching; defaults to String(getNodeLabel). */
53
+ getSearchText?: (node: T) => string;
54
+
55
+ /** Trigger placeholder shown until a node is selected. */
56
+ placeholder?: string;
57
+ /** Placeholder for the search input inside the dialog. */
58
+ searchPlaceholder?: string;
59
+ /** Label shown on the dialog's search field. */
60
+ title?: string;
61
+
62
+ size?: "XS" | "S" | "M";
63
+ variant?: "SystemStyle" | "PresentationStyle";
64
+ icon?: ReactNode;
65
+ theme?: Themes;
66
+ dir?: string;
67
+ className?: string;
68
+ /**
69
+ * Expand every node by default when the dialog opens. Defaults to `true` so
70
+ * children are visible as soon as the tree opens (matches the Figma design).
71
+ */
72
+ defaultExpanded?: boolean;
73
+ /**
74
+ * When true, folder rows (nodes with children) are ALSO selectable: clicking
75
+ * any node — folder or leaf — selects it and closes the dialog. When false
76
+ * (default), folders only toggle expand/collapse and only leaves are selectable.
77
+ */
78
+ selectableFolders?: boolean;
79
+
80
+ // --- Async (optional; static `nodes` still works) ---
81
+ /** When true (default), filters locally. Set false for server-side search. */
82
+ filterClientSide?: boolean;
83
+ /** Debounced as the user types — refetch your data here (server search). */
84
+ onSearchChange?: (query: string) => void;
85
+ searchDebounceMs?: number;
86
+ /** Whether a fetch is in flight; shows a loading indicator. */
87
+ loading?: boolean;
88
+ }
89
+
90
+ /** Normalized internal node — always nested with resolved id/label/children. */
91
+ interface TreeNode<T> {
92
+ id: string;
93
+ label: ReactNode;
94
+ searchText: string;
95
+ raw: T;
96
+ children: TreeNode<T>[];
97
+ }
98
+
99
+ export function SearchableTreeDialog<T>({
100
+ nodes,
101
+ getNodeId,
102
+ getNodeLabel,
103
+ getNodeChildren,
104
+ parentIdKey,
105
+ value,
106
+ onSelect,
107
+ getSearchText,
108
+ placeholder = "Select…",
109
+ searchPlaceholder = "Search…",
110
+ title = "Select an item",
111
+ size = "M",
112
+ variant = "PresentationStyle",
113
+ icon,
114
+ theme,
115
+ dir,
116
+ className,
117
+ defaultExpanded = true,
118
+ selectableFolders = false,
119
+ filterClientSide = true,
120
+ onSearchChange,
121
+ searchDebounceMs = 300,
122
+ loading = false,
123
+ }: Props<T>) {
124
+ const [open, setOpen] = useState(false);
125
+ const [search, setSearch] = useState("");
126
+ const inputRef = useRef<HTMLInputElement | null>(null);
127
+
128
+ const searchTextOf = (node: T) => getSearchText?.(node) ?? String(getNodeLabel(node) ?? "");
129
+
130
+ // Normalize raw data (nested OR flat) into a uniform nested TreeNode shape.
131
+ const tree = useMemo<TreeNode<T>[]>(() => {
132
+ const toNode = (raw: T, children: TreeNode<T>[]): TreeNode<T> => ({
133
+ id: getNodeId(raw),
134
+ label: getNodeLabel(raw),
135
+ searchText: searchTextOf(raw),
136
+ raw,
137
+ children,
138
+ });
139
+
140
+ // Flat mode: build nesting from parentIdKey.
141
+ if (parentIdKey) {
142
+ const byId = new Map<string, TreeNode<T>>();
143
+ const roots: TreeNode<T>[] = [];
144
+ for (const raw of nodes) byId.set(getNodeId(raw), toNode(raw, []));
145
+ for (const raw of nodes) {
146
+ const node = byId.get(getNodeId(raw))!;
147
+ const parentId = raw[parentIdKey] as unknown as string | null | undefined;
148
+ const parent = parentId != null ? byId.get(String(parentId)) : undefined;
149
+ if (parent) parent.children.push(node);
150
+ else roots.push(node);
151
+ }
152
+ return roots;
153
+ }
154
+
155
+ // Nested mode: recurse via getNodeChildren.
156
+ const build = (raw: T): TreeNode<T> => toNode(raw, (getNodeChildren?.(raw) ?? []).map(build));
157
+ return nodes.map(build);
158
+ // eslint-disable-next-line react-hooks/exhaustive-deps
159
+ }, [nodes, parentIdKey, getNodeChildren]);
160
+
161
+ // Filter the tree by the query, keeping ancestors of any match. In server-side
162
+ // mode the data is already filtered, so we render it as-is.
163
+ const visibleTree = useMemo<TreeNode<T>[]>(() => {
164
+ const q = search.trim().toLowerCase();
165
+ if (!filterClientSide || !q) return tree;
166
+ const filter = (list: TreeNode<T>[]): TreeNode<T>[] =>
167
+ list.reduce<TreeNode<T>[]>((acc, node) => {
168
+ const kids = filter(node.children);
169
+ const self = node.searchText.toLowerCase().includes(q);
170
+ if (self || kids.length) acc.push({ ...node, children: kids });
171
+ return acc;
172
+ }, []);
173
+ return filter(tree);
174
+ }, [tree, search, filterClientSide]);
175
+
176
+ // Expand-state: when searching (or defaultExpanded), expand everything so the
177
+ // matched paths are visible; otherwise honor user toggles.
178
+ const [expanded, setExpanded] = useState<Set<string>>(new Set());
179
+ const forceExpand = (filterClientSide && search.trim().length > 0) || defaultExpanded;
180
+ const isExpanded = (id: string) => forceExpand || expanded.has(id);
181
+ const toggle = (id: string) =>
182
+ setExpanded((prev) => {
183
+ const next = new Set(prev);
184
+ next.has(id) ? next.delete(id) : next.add(id);
185
+ return next;
186
+ });
187
+
188
+ // Debounced server search.
189
+ useEffect(() => {
190
+ if (!onSearchChange) return;
191
+ const t = setTimeout(() => onSearchChange(search.trim()), searchDebounceMs);
192
+ return () => clearTimeout(t);
193
+ }, [search, onSearchChange, searchDebounceMs]);
194
+
195
+ // Reset the query when the dialog closes.
196
+ useEffect(() => {
197
+ if (!open) setSearch("");
198
+ }, [open]);
199
+
200
+ const selectedId = value != null ? getNodeId(value) : undefined;
201
+
202
+ // Leaf rows select + close; folder rows toggle expand/collapse (handled inline).
203
+ const handleSelect = (node: TreeNode<T>) => {
204
+ onSelect?.(node.raw);
205
+ setOpen(false);
206
+ };
207
+
208
+ // Folder rows when `selectableFolders` is on: behave just like a leaf —
209
+ // select the node and close the dialog so it shows in the field.
210
+ const handleSelectFolder = (node: TreeNode<T>) => {
211
+ handleSelect(node);
212
+ };
213
+
214
+ // Trigger label = selected node's label, else placeholder.
215
+ const triggerLabel = value != null ? getNodeLabel(value) : placeholder;
216
+
217
+ return (
218
+ <Dialog open={open} onOpenChange={setOpen}>
219
+ <DialogTrigger asChild>
220
+ <Group
221
+ dir={dir}
222
+ data-theme={theme}
223
+ variant={variant}
224
+ size={size === "XS" ? "S" : size}
225
+ role="button"
226
+ tabIndex={0}
227
+ className={cn("flex w-full items-center gap-1 p-1 cursor-pointer", className)}
228
+ >
229
+ {icon && <Icon>{icon}</Icon>}
230
+ <span
231
+ className={cn(
232
+ "flex-1 px-1 truncate typography-body-medium-regular",
233
+ value != null
234
+ ? "text-content-presentation-action-light-primary"
235
+ : "text-content-presentation-action-light-secondary",
236
+ )}
237
+ >
238
+ {triggerLabel}
239
+ </span>
240
+ {/* Chevron toggle — boxed icon button matching the Select component. */}
241
+ <Button
242
+ as="span"
243
+ buttonType="icon"
244
+ tabIndex={-1}
245
+ aria-label={open ? "Close" : "Open"}
246
+ className={cn(
247
+ "shrink-0 h-[32px] w-[32px] rounded-[4px]",
248
+ open && "bg-background-presentation-action-hover text-white",
249
+ )}
250
+ >
251
+ <i
252
+ className={cn(
253
+ "ri-arrow-down-s-line text-[20px] transition-all duration-100 ease-in-out",
254
+ open && "rotate-180",
255
+ )}
256
+ />
257
+ </Button>
258
+ </Group>
259
+ </DialogTrigger>
260
+
261
+ <DialogContent
262
+ dir={dir}
263
+ data-theme={theme}
264
+ onOpenAutoFocus={(e) => {
265
+ e.preventDefault();
266
+ inputRef.current?.focus();
267
+ }}
268
+ className="w-[min(640px,90vw)] bg-transparent !items-stretch rounded-[14px] shadow-none gap-0"
269
+ >
270
+ <DialogTitle className="sr-only">{title ?? "Select an item"}</DialogTitle>
271
+
272
+ {/* SearchBar — frosted top-bar shell (z-2 in Figma). */}
273
+ <TreeSearchInput
274
+ ref={inputRef}
275
+ variant={variant}
276
+ theme={theme}
277
+ dir={dir}
278
+ label={title}
279
+ value={search}
280
+ placeholder={searchPlaceholder}
281
+ onChange={(e) => setSearch(e.target.value)}
282
+ />
283
+
284
+ {/* SearchResult.Container — inset 12px each side, tucked under the bar (z-1). */}
285
+ <div className="flex w-full items-start px-[12px]">
286
+ {/* Body — frosted surface that connects to the bar with rounded-bottom. */}
287
+ <div className="flex-1 min-w-px max-h-[55vh] overflow-auto scrollbar-hide rounded-b-[14px] pt-[8px] pb-[4px] px-[4px] bg-[rgba(61,64,69,0.72)] backdrop-blur-[21px] shadow-[0_0_32px_2px_rgba(0,0,0,0.20),0_0_48px_2px_rgba(0,0,0,0.05)]">
288
+ {visibleTree.length > 0 ? (
289
+ <div className="flex flex-col gap-[4px]">
290
+ {/* "Tree" section label. */}
291
+ {title && (
292
+ <div className="flex items-end pt-[4px] px-[12px]">
293
+ <span className="typography-body-small-medium text-content-presentation-global-primary-light">
294
+ {title}
295
+ </span>
296
+ </div>
297
+ )}
298
+
299
+ {/* Rows — translucent fill, 1px gaps, rounded + clipped group. */}
300
+ <div className="flex flex-col gap-px overflow-clip rounded-[10px]">
301
+ <TreeLevel
302
+ nodes={visibleTree}
303
+ depth={0}
304
+ selectedId={selectedId}
305
+ selectableFolders={selectableFolders}
306
+ isExpanded={isExpanded}
307
+ onToggle={toggle}
308
+ onSelect={handleSelect}
309
+ onSelectFolder={handleSelectFolder}
310
+ />
311
+ </div>
312
+ </div>
313
+ ) : (
314
+ !loading && (
315
+ <div className="px-3 py-6 text-center typography-body-small-regular text-white-alpha-75">
316
+ No results found
317
+ </div>
318
+ )
319
+ )}
320
+
321
+ {loading && (
322
+ <div className="flex items-center justify-center py-3">
323
+ <LoadingIcon size="M" />
324
+ </div>
325
+ )}
326
+ </div>
327
+ </div>
328
+ </DialogContent>
329
+ </Dialog>
330
+ );
331
+ }
332
+
333
+ SearchableTreeDialog.displayName = "SearchableTreeDialog";
334
+
335
+ /* -------------------------------------------------------------------------- */
336
+ /* Recursive tree renderer */
337
+ /* -------------------------------------------------------------------------- */
338
+
339
+ function TreeLevel<T>({
340
+ nodes,
341
+ depth,
342
+ selectedId,
343
+ selectableFolders = false,
344
+ isExpanded,
345
+ onToggle,
346
+ onSelect,
347
+ onSelectFolder,
348
+ }: {
349
+ nodes: TreeNode<T>[];
350
+ depth: number;
351
+ selectedId?: string;
352
+ selectableFolders?: boolean;
353
+ isExpanded: (id: string) => boolean;
354
+ onToggle: (id: string) => void;
355
+ onSelect: (node: TreeNode<T>) => void;
356
+ onSelectFolder: (node: TreeNode<T>) => void;
357
+ }) {
358
+ return (
359
+ <>
360
+ {nodes.map((node) => {
361
+ const hasChildren = node.children.length > 0;
362
+ const open = isExpanded(node.id);
363
+ const selected = selectedId === node.id;
364
+ // Leaf rows always select + close. Folder rows either select + toggle
365
+ // (selectableFolders) or just toggle expand/collapse.
366
+ const onRowClick = () =>
367
+ !hasChildren
368
+ ? onSelect(node)
369
+ : selectableFolders
370
+ ? onSelectFolder(node)
371
+ : onToggle(node.id);
372
+ // Whether THIS row participates in the selected/hover highlight.
373
+ const highlightable = !hasChildren || selectableFolders;
374
+ return (
375
+ <div key={node.id} className="flex flex-col gap-px">
376
+ {/* item-container — full-width row with the design's grey fill. */}
377
+ <div
378
+ role="button"
379
+ tabIndex={0}
380
+ aria-expanded={hasChildren ? open : undefined}
381
+ onClick={onRowClick}
382
+ onKeyDown={(e) => {
383
+ if (e.key === "Enter" || e.key === " ") {
384
+ e.preventDefault();
385
+ onRowClick();
386
+ }
387
+ }}
388
+ className={cn(
389
+ "group flex items-center px-[2px] cursor-pointer bg-[rgba(184,192,204,0.36)]",
390
+ )}
391
+ >
392
+ {/* Connector rails — one full-height vertical line per ancestor level. */}
393
+ {Array.from({ length: depth }).map((_, i) => (
394
+ <div
395
+ key={i}
396
+ aria-hidden
397
+ className="flex h-[33px] shrink-0 items-center overflow-clip px-[14px]"
398
+ >
399
+ <div className="h-full w-px shrink-0 bg-white-alpha-40" />
400
+ </div>
401
+ ))}
402
+
403
+ {/* Padding + label — inner row that highlights on hover/select. */}
404
+ <div className="flex flex-1 min-w-px flex-col items-start py-[2px]">
405
+ <div
406
+ className={cn(
407
+ "flex w-full items-center gap-2 px-[12px] py-[4px] rounded-[8px]",
408
+ "transition-all duration-300 ease-in-out",
409
+ "text-content-presentation-global-primary-light",
410
+ // Selectable rows (leaves, or folders when selectableFolders)
411
+ // highlight on hover/select; non-selectable folders only toggle,
412
+ // so they read as de-emphasized (opacity-50) and get no highlight.
413
+ !highlightable && "opacity-50",
414
+ highlightable &&
415
+ "group-hover:bg-white-50 group-hover:text-black-1000 group-hover:shadow-[0_0_16px_0_rgba(0,0,0,0.36)]",
416
+ highlightable && selected && "bg-white-alpha-75 text-black-1000",
417
+ )}
418
+ >
419
+ <span className="flex-1 min-w-px truncate typography-body-medium-regular">
420
+ {node.label}
421
+ </span>
422
+ </div>
423
+ </div>
424
+ </div>
425
+
426
+ {hasChildren && open && (
427
+ <TreeLevel
428
+ nodes={node.children}
429
+ depth={depth + 1}
430
+ selectedId={selectedId}
431
+ selectableFolders={selectableFolders}
432
+ isExpanded={isExpanded}
433
+ onToggle={onToggle}
434
+ onSelect={onSelect}
435
+ onSelectFolder={onSelectFolder}
436
+ />
437
+ )}
438
+ </div>
439
+ );
440
+ })}
441
+ </>
442
+ );
443
+ }
444
+
445
+ /* -------------------------------------------------------------------------- */
446
+ /* Inline-label search field (self-contained, mirrors SearchableTable's). */
447
+ /* -------------------------------------------------------------------------- */
448
+
449
+ interface TreeSearchInputProps extends Omit<InputHTMLAttributes<HTMLInputElement>, "size"> {
450
+ variant?: "SystemStyle" | "PresentationStyle";
451
+ theme?: Themes;
452
+ label?: string;
453
+ }
454
+
455
+ const TreeSearchInput = forwardRef<HTMLInputElement, TreeSearchInputProps>(
456
+ ({ variant = "PresentationStyle", theme, label, className, ...props }, ref) => (
457
+ <div className="relative z-[2] flex w-full flex-col items-start gap-[10px] p-[3px] rounded-[14px] bg-[rgba(61,64,69,0.65)] shadow-[0_0_18px_0_rgba(0,0,0,0.40)] backdrop-blur-[21px]">
458
+ <Group
459
+ data-theme={theme}
460
+ variant={variant}
461
+ size="M"
462
+ className={cn(
463
+ "group flex w-full items-center hover:border-blue-sparkle-400 gap-[10px] px-[15px] py-[10px] rounded-[11px] transition-colors",
464
+ "border border-white-alpha-40 bg-[rgba(37,44,57,0.30)]",
465
+ "hover:bg-background-presentation-table-row-hover",
466
+ "focus-within:bg-background-presentation-table-row-hover",
467
+ className,
468
+ )}
469
+ >
470
+ <Icon className="shrink-0">
471
+ <i className="ri-search-line text-[18px] text-content-presentation-global-secondary transition-colors group-hover:text-white group-focus-within:text-white" />
472
+ </Icon>
473
+
474
+ {label && (
475
+ <span className="shrink-0 text-content-presentation-global-primary-light typography-headers-medium-regular opacity-80 transition-colors group-hover:text-white group-focus-within:text-white">
476
+ {label}
477
+ </span>
478
+ )}
479
+
480
+ <Input
481
+ ref={ref}
482
+ {...props}
483
+ className={cn(
484
+ "min-w-[100px] flex-1 !h-[24px] bg-transparent",
485
+ "text-content-presentation-action-light-primary placeholder:hover:text-white-alpha-75",
486
+ "transition-colors group-hover:!text-white group-focus-within:!text-white",
487
+ )}
488
+ />
489
+ </Group>
490
+ </div>
491
+ ),
492
+ );
493
+ TreeSearchInput.displayName = "TreeSearchInput";
@@ -21,14 +21,9 @@ const titleBadge = cva(
21
21
  },
22
22
  );
23
23
 
24
- export type SectionColor = NonNullable<
25
- VariantProps<typeof titleBadge>["color"]
26
- >;
24
+ export type SectionColor = NonNullable<VariantProps<typeof titleBadge>["color"]>;
27
25
 
28
- export interface SectionBlockProps extends Omit<
29
- HTMLAttributes<HTMLDivElement>,
30
- "title"
31
- > {
26
+ export interface SectionBlockProps extends Omit<HTMLAttributes<HTMLDivElement>, "title"> {
32
27
  color?: SectionColor;
33
28
  title?: ReactNode;
34
29
  icon?: ReactNode;
@@ -63,9 +58,7 @@ export const SectionBlock = forwardRef<HTMLDivElement, SectionBlockProps>(
63
58
  {...props}
64
59
  >
65
60
  {title && (
66
- <div
67
- className={cn("flex px-[6px] flex-col gap-[10px]", headerClassName)}
68
- >
61
+ <div className={cn("flex px-[6px] flex-col gap-[10px]", headerClassName)}>
69
62
  <div className={cn(titleBadge({ color }))}>
70
63
  <span className="flex items-center gap-1.5">
71
64
  {icon}
@@ -74,12 +67,7 @@ export const SectionBlock = forwardRef<HTMLDivElement, SectionBlockProps>(
74
67
  </div>
75
68
  </div>
76
69
  )}
77
- <div
78
- className={cn(
79
- "flex px-[42px] flex-col gap-[2px] px-[42px]",
80
- bodyClassName,
81
- )}
82
- >
70
+ <div className={cn("flex px-[42px] flex-col gap-[2px] px-[42px]", bodyClassName)}>
83
71
  <div className="flex w-full divide-y divide-gray-300 min-w-[300px] flex-col items-start ">
84
72
  {children}
85
73
  </div>