@particle-academy/react-fancy 1.9.1 → 2.1.0
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.
- package/dist/icons.cjs +14 -0
- package/dist/icons.cjs.map +1 -0
- package/dist/icons.d.cts +1 -0
- package/dist/icons.d.ts +1 -0
- package/dist/icons.js +3 -0
- package/dist/icons.js.map +1 -0
- package/dist/index.cjs +273 -92
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +36 -2
- package/dist/index.d.ts +36 -2
- package/dist/index.js +238 -39
- package/dist/index.js.map +1 -1
- package/docs/TreeNav.md +35 -0
- package/package.json +11 -1
- package/dist/styles.d.cts +0 -2
- package/dist/styles.d.ts +0 -2
package/docs/TreeNav.md
CHANGED
|
@@ -49,6 +49,8 @@ const files: TreeNodeData[] = [
|
|
|
49
49
|
| selectedId | `string` | - | Currently selected node ID |
|
|
50
50
|
| onSelect | `(id: string, node: TreeNodeData) => void` | - | Selection callback |
|
|
51
51
|
| onNodeContextMenu | `(e: React.MouseEvent, node: TreeNodeData) => void` | - | Right-click callback per node |
|
|
52
|
+
| draggable | `boolean` | `false` | Enable drag-and-drop reordering |
|
|
53
|
+
| onNodeMove | `(sourceId: string, targetId: string, position: DropPosition) => void` | - | Callback when a node is moved via drag-and-drop |
|
|
52
54
|
| expandedIds | `string[]` | - | Controlled expanded node IDs |
|
|
53
55
|
| defaultExpandedIds | `string[]` | - | Initial expanded nodes (uncontrolled) |
|
|
54
56
|
| onExpandedChange | `(ids: string[]) => void` | - | Callback when expanded state changes |
|
|
@@ -142,6 +144,39 @@ Override with the `icon` field on any node:
|
|
|
142
144
|
{ id: "special", label: "config", icon: <GearIcon /> }
|
|
143
145
|
```
|
|
144
146
|
|
|
147
|
+
## Drag and Drop
|
|
148
|
+
|
|
149
|
+
Enable drag-and-drop reordering with the `draggable` prop. The tree itself is never mutated — your `onNodeMove` callback receives the source, target, and position, and you update state accordingly.
|
|
150
|
+
|
|
151
|
+
```tsx
|
|
152
|
+
import { TreeNav } from "@particle-academy/react-fancy";
|
|
153
|
+
import type { TreeNodeData, DropPosition } from "@particle-academy/react-fancy";
|
|
154
|
+
|
|
155
|
+
const [files, setFiles] = useState<TreeNodeData[]>(initialFiles);
|
|
156
|
+
|
|
157
|
+
function handleNodeMove(sourceId: string, targetId: string, position: DropPosition) {
|
|
158
|
+
// position is "before", "after", or "inside" (folders only)
|
|
159
|
+
setFiles((prev) => moveNode(prev, sourceId, targetId, position));
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
<TreeNav
|
|
163
|
+
nodes={files}
|
|
164
|
+
draggable
|
|
165
|
+
onNodeMove={handleNodeMove}
|
|
166
|
+
/>
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
**Drop positions:**
|
|
170
|
+
- `"before"` — insert above the target node (thin blue line indicator)
|
|
171
|
+
- `"after"` — insert below the target node (thin blue line indicator)
|
|
172
|
+
- `"inside"` — drop into a folder (blue highlight on the folder)
|
|
173
|
+
|
|
174
|
+
**Built-in safety:**
|
|
175
|
+
- Cannot drop a node onto itself
|
|
176
|
+
- Cannot drop a node into its own descendants
|
|
177
|
+
- Folders auto-expand after 500ms when dragging over them
|
|
178
|
+
- Disabled nodes cannot be dragged
|
|
179
|
+
|
|
145
180
|
## Context Menu
|
|
146
181
|
|
|
147
182
|
Use `onNodeContextMenu` with the `ContextMenu` component to add right-click menus per node:
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@particle-academy/react-fancy",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "2.1.0",
|
|
4
4
|
"description": "React UI component library — React port of the fancy-flux Blade component library",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
@@ -17,6 +17,16 @@
|
|
|
17
17
|
"default": "./dist/index.cjs"
|
|
18
18
|
}
|
|
19
19
|
},
|
|
20
|
+
"./icons": {
|
|
21
|
+
"import": {
|
|
22
|
+
"types": "./dist/icons.d.ts",
|
|
23
|
+
"default": "./dist/icons.js"
|
|
24
|
+
},
|
|
25
|
+
"require": {
|
|
26
|
+
"types": "./dist/icons.d.cts",
|
|
27
|
+
"default": "./dist/icons.cjs"
|
|
28
|
+
}
|
|
29
|
+
},
|
|
20
30
|
"./styles.css": "./dist/styles.css"
|
|
21
31
|
},
|
|
22
32
|
"files": [
|
package/dist/styles.d.cts
DELETED
package/dist/styles.d.ts
DELETED