@edux-design/tree-select 0.0.1 → 0.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/README.md CHANGED
@@ -1,50 +1,162 @@
1
1
  # @edux-design/tree-select
2
2
 
3
- Tree-select component for hierarchical navigation and selection. Supports checkbox or chevron controls, drag-and-drop reordering, and add actions at any level.
3
+ TreeSelect renders hierarchical data with expand/collapse controls, optional inline editing, optional add-item actions, and drag-and-drop reordering. The component is controlled: you own the tree data and receive updates via callbacks.
4
4
 
5
5
  ---
6
6
 
7
7
  ## Installation
8
8
 
9
9
  ```bash
10
- pnpm add @edux-design/tree-select @edux-design/forms @edux-design/icons @edux-design/utils
10
+ pnpm add @edux-design/tree-select @edux-design/forms @edux-design/buttons @edux-design/icons @edux-design/tooltips @dnd-kit/core @dnd-kit/sortable
11
11
  # or
12
- npm install @edux-design/tree-select @edux-design/forms @edux-design/icons @edux-design/utils
12
+ npm install @edux-design/tree-select @edux-design/forms @edux-design/buttons @edux-design/icons @edux-design/tooltips @dnd-kit/core @dnd-kit/sortable
13
13
  ```
14
14
 
15
- Peer deps also include `react@^19.1.0`, `react-dom@^19.1.0`.
15
+ Peer deps include `react@^19.1.0` and `react-dom@^19.1.0`.
16
16
 
17
17
  ---
18
18
 
19
- ## Usage
19
+ ## Data shape
20
20
 
21
- ```jsx
22
- import { TreeSelect } from "@edux-design/tree-select";
21
+ Each node must have a stable `id`. Children are optional.
23
22
 
23
+ ```js
24
24
  const data = [
25
25
  {
26
26
  id: "docs",
27
27
  label: "Documentation",
28
- checked: true,
29
28
  children: [
30
29
  { id: "intro", label: "Introduction" },
31
- { id: "install", label: "Installation", indeterminate: true },
30
+ { id: "install", label: "Installation" },
32
31
  ],
33
32
  },
34
33
  ];
34
+ ```
35
+
36
+ - `id` is required and must be unique within the tree.
37
+ - `label` is displayed; when missing the `id` is used.
38
+ - `children` is an array of child nodes.
39
+
40
+ ---
41
+
42
+ ## Usage
43
+
44
+ ### Basic
45
+
46
+ ```jsx
47
+ import { TreeSelect } from "@edux-design/tree-select";
35
48
 
36
49
  export function Example() {
50
+ return <TreeSelect data={data} />;
51
+ }
52
+ ```
53
+
54
+ ### Drag and drop
55
+
56
+ ```jsx
57
+ export function DragExample() {
58
+ const [tree, setTree] = useState(data);
59
+
37
60
  return (
38
61
  <TreeSelect
39
- data={data}
40
- control="checkbox"
41
- defaultExpandedIds={["docs"]}
42
- onCheck={(node, nextChecked) => console.log(node, nextChecked)}
62
+ data={tree}
63
+ allowDragAndDrop
64
+ onDataChange={setTree}
43
65
  />
44
66
  );
45
67
  }
46
68
  ```
47
69
 
70
+ ### Multi-select drag
71
+
72
+ ```jsx
73
+ export function MultiDragExample() {
74
+ const [tree, setTree] = useState(data);
75
+
76
+ return (
77
+ <TreeSelect
78
+ data={tree}
79
+ allowDragAndDrop
80
+ allowMultiDrag
81
+ onDataChange={setTree}
82
+ />
83
+ );
84
+ }
85
+ ```
86
+
87
+ - Hold CMD (Mac) or CTRL (Windows) to select multiple adjacent siblings.
88
+ - Hold SHIFT to select a range of adjacent siblings.
89
+ - Multi-select only works within the same sibling group and must stay contiguous.
90
+
91
+ ### Editable labels and add actions
92
+
93
+ ```jsx
94
+ export function EditableExample() {
95
+ const [tree, setTree] = useState(data);
96
+
97
+ return (
98
+ <TreeSelect
99
+ data={tree}
100
+ isEditable
101
+ maxDepth={3}
102
+ addChildTooltip="Add a child item"
103
+ addSiblingTooltip="Add a sibling item"
104
+ onDataChange={setTree}
105
+ />
106
+ );
107
+ }
108
+ ```
109
+
110
+ ### Chevron toggle
111
+
112
+ ```jsx
113
+ export function ChevronExample() {
114
+ return <TreeSelect data={data} useChevron />;
115
+ }
116
+ ```
117
+
118
+ ---
119
+
120
+ ## Props
121
+
122
+ ### `data` (array, required)
123
+ Tree data to render. This component is controlled; updates are emitted through `onDataChange`.
124
+
125
+ ### `onDataChange` (function)
126
+ Called with the updated tree when edits, add actions, or drag-and-drop reordering occur.
127
+
128
+ ### `allowDragAndDrop` (boolean, default `false`)
129
+ Enables drag-and-drop. When `false`, drag handles are hidden and items cannot be reordered.
130
+
131
+ ### `allowMultiDrag` (boolean, default `false`)
132
+ Allows multi-select drag using CMD/CTRL or SHIFT. Selection is restricted to adjacent siblings.
133
+
134
+ ### `isEditable` (boolean, default `false`)
135
+ Enables inline label editing and add-item controls.
136
+
137
+ ### `useChevron` (boolean, default `false`)
138
+ Uses a chevron control for expand/collapse instead of the checkbox toggle.
139
+
140
+ ### `maxDepth` (number)
141
+ Limits how deep new items can be added. For example, `maxDepth={3}` allows at most 3 levels.
142
+
143
+ ### `addChildTooltip` (string)
144
+ Tooltip copy for the add-child button.
145
+
146
+ ### `addSiblingTooltip` (string)
147
+ Tooltip copy for the add-sibling button.
148
+
149
+ ---
150
+
151
+ ## Behaviour details
152
+
153
+ - Nodes with children render an expand/collapse control.
154
+ - Leaf nodes do not render a checkbox/chevron toggle.
155
+ - Expansion only controls visibility of children.
156
+ - When `useChevron` is `false`, the toggle uses the Checkbox plus/indeterminate states.
157
+ - Drag-and-drop supports reordering within a level and moving items between levels.
158
+ - Drag handle alignment is set so child handles align under the parent toggle.
159
+
48
160
  ---
49
161
 
50
162
  ## Development
package/dist/index.d.mts CHANGED
@@ -1,23 +1,15 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
2
 
3
- declare function TreeSelect({ data, control, className, itemClassName, draggable, onReorder, onDataChange, onExpandedChange, expandedIds, defaultExpandedIds, onCheck, onAdd, addLabel, showRootAdd, rootAddLabel, renderLabel, expandOnLabelClick, }: {
3
+ declare function TreeSelect({ data, onDataChange, allowDragAndDrop, allowMultiDrag, isEditable, useChevron, maxDepth, addChildTooltip, addSiblingTooltip, }: {
4
4
  data: any;
5
- control?: string;
6
- className: any;
7
- itemClassName: any;
8
- draggable?: boolean;
9
- onReorder: any;
10
5
  onDataChange: any;
11
- onExpandedChange: any;
12
- expandedIds: any;
13
- defaultExpandedIds?: any[];
14
- onCheck: any;
15
- onAdd: any;
16
- addLabel?: string;
17
- showRootAdd?: boolean;
18
- rootAddLabel?: string;
19
- renderLabel: any;
20
- expandOnLabelClick?: boolean;
6
+ allowDragAndDrop?: boolean;
7
+ allowMultiDrag?: boolean;
8
+ isEditable?: boolean;
9
+ useChevron?: boolean;
10
+ maxDepth: any;
11
+ addChildTooltip: any;
12
+ addSiblingTooltip: any;
21
13
  }): react_jsx_runtime.JSX.Element;
22
14
 
23
15
  export { TreeSelect };
package/dist/index.d.ts CHANGED
@@ -1,23 +1,15 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
2
 
3
- declare function TreeSelect({ data, control, className, itemClassName, draggable, onReorder, onDataChange, onExpandedChange, expandedIds, defaultExpandedIds, onCheck, onAdd, addLabel, showRootAdd, rootAddLabel, renderLabel, expandOnLabelClick, }: {
3
+ declare function TreeSelect({ data, onDataChange, allowDragAndDrop, allowMultiDrag, isEditable, useChevron, maxDepth, addChildTooltip, addSiblingTooltip, }: {
4
4
  data: any;
5
- control?: string;
6
- className: any;
7
- itemClassName: any;
8
- draggable?: boolean;
9
- onReorder: any;
10
5
  onDataChange: any;
11
- onExpandedChange: any;
12
- expandedIds: any;
13
- defaultExpandedIds?: any[];
14
- onCheck: any;
15
- onAdd: any;
16
- addLabel?: string;
17
- showRootAdd?: boolean;
18
- rootAddLabel?: string;
19
- renderLabel: any;
20
- expandOnLabelClick?: boolean;
6
+ allowDragAndDrop?: boolean;
7
+ allowMultiDrag?: boolean;
8
+ isEditable?: boolean;
9
+ useChevron?: boolean;
10
+ maxDepth: any;
11
+ addChildTooltip: any;
12
+ addSiblingTooltip: any;
21
13
  }): react_jsx_runtime.JSX.Element;
22
14
 
23
15
  export { TreeSelect };