@edux-design/tree-select 0.0.1 → 0.1.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.
package/README.md CHANGED
@@ -1,50 +1,189 @@
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
+ ### `allowDelete` (boolean, default `false`)
138
+ Shows a delete action for each item and removes the node (plus descendants).
139
+
140
+ ### `useChevron` (boolean, default `false`)
141
+ Uses a chevron control for expand/collapse instead of the checkbox toggle.
142
+
143
+ ### `defaultExpanded` (`"all"` | number | string[] | Set<string | number>)
144
+ Defines the initial expansion state. Use `"all"` to expand every node with children, a number to expand up to that level (1 expands top-level nodes), or an array/set of ids to expand specific items.
145
+
146
+ ### `expanded` (`"all"` | number | string[] | Set<string | number>)
147
+ Controlled expansion state. When provided, the tree expansion is driven by this value.
148
+
149
+ ### `onExpandedChange` (function)
150
+ Called with a `Set` of expanded ids when the user toggles expansion in controlled mode.
151
+
152
+ ### `maxDepth` (number)
153
+ Limits how deep new items can be added. For example, `maxDepth={3}` allows at most 3 levels.
154
+
155
+ ### `addChildTooltip` (string)
156
+ Tooltip copy for the add-child button.
157
+
158
+ ### `addChildTooltipByLevel` (string[])
159
+ Tooltip copy for add-child, keyed by depth. Overrides `addChildTooltip` when provided.
160
+
161
+ ### `addSiblingTooltip` (string)
162
+ Tooltip copy for the add-sibling button.
163
+
164
+ ### `addSiblingTooltipByLevel` (string[])
165
+ Tooltip copy for add-sibling, keyed by depth. Overrides `addSiblingTooltip` when provided.
166
+
167
+ ### `deleteTooltip` (string)
168
+ Tooltip copy for the delete button.
169
+
170
+ ### `deleteTooltipByLevel` (string[])
171
+ Tooltip copy for delete, keyed by depth. Overrides `deleteTooltip` when provided.
172
+
173
+ ---
174
+
175
+ ## Behaviour details
176
+
177
+ - Nodes with children render an expand/collapse control.
178
+ - Leaf nodes do not render a checkbox/chevron toggle.
179
+ - Expansion only controls visibility of children.
180
+ - When `useChevron` is `false`, the toggle uses the Checkbox plus/indeterminate states.
181
+ - `defaultExpanded` only seeds the initial state; use `expanded` for controlled expansion.
182
+ - When `expanded` is provided, `onExpandedChange` is called with the next set of expanded ids.
183
+ - Deleting a node removes the entire subtree and clears any selected/expanded state for those ids.
184
+ - Drag-and-drop supports reordering within a level and moving items between levels.
185
+ - Drag handle alignment is set so child handles align under the parent toggle.
186
+
48
187
  ---
49
188
 
50
189
  ## Development
package/dist/index.d.mts CHANGED
@@ -1,23 +1,23 @@
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, allowDelete, useChevron, maxDepth, addChildTooltip, addSiblingTooltip, deleteTooltip, addChildTooltipByLevel, addSiblingTooltipByLevel, deleteTooltipByLevel, defaultExpanded, expanded, onExpandedChange, }: {
4
4
  data: any;
5
- control?: string;
6
- className: any;
7
- itemClassName: any;
8
- draggable?: boolean;
9
- onReorder: any;
10
5
  onDataChange: any;
6
+ allowDragAndDrop?: boolean;
7
+ allowMultiDrag?: boolean;
8
+ isEditable?: boolean;
9
+ allowDelete?: boolean;
10
+ useChevron?: boolean;
11
+ maxDepth: any;
12
+ addChildTooltip: any;
13
+ addSiblingTooltip: any;
14
+ deleteTooltip: any;
15
+ addChildTooltipByLevel: any;
16
+ addSiblingTooltipByLevel: any;
17
+ deleteTooltipByLevel: any;
18
+ defaultExpanded: any;
19
+ expanded: any;
11
20
  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;
21
21
  }): react_jsx_runtime.JSX.Element;
22
22
 
23
23
  export { TreeSelect };
package/dist/index.d.ts CHANGED
@@ -1,23 +1,23 @@
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, allowDelete, useChevron, maxDepth, addChildTooltip, addSiblingTooltip, deleteTooltip, addChildTooltipByLevel, addSiblingTooltipByLevel, deleteTooltipByLevel, defaultExpanded, expanded, onExpandedChange, }: {
4
4
  data: any;
5
- control?: string;
6
- className: any;
7
- itemClassName: any;
8
- draggable?: boolean;
9
- onReorder: any;
10
5
  onDataChange: any;
6
+ allowDragAndDrop?: boolean;
7
+ allowMultiDrag?: boolean;
8
+ isEditable?: boolean;
9
+ allowDelete?: boolean;
10
+ useChevron?: boolean;
11
+ maxDepth: any;
12
+ addChildTooltip: any;
13
+ addSiblingTooltip: any;
14
+ deleteTooltip: any;
15
+ addChildTooltipByLevel: any;
16
+ addSiblingTooltipByLevel: any;
17
+ deleteTooltipByLevel: any;
18
+ defaultExpanded: any;
19
+ expanded: any;
11
20
  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;
21
21
  }): react_jsx_runtime.JSX.Element;
22
22
 
23
23
  export { TreeSelect };