Package Exports
- dnd-kit-tree
- dnd-kit-tree/dist/index.cjs.js
- dnd-kit-tree/dist/index.esm.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (dnd-kit-tree) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
dnd-kit-tree
A React-based project utilizing dnd-kit to create a customizable and interactive tree component for drag-and-drop
functionality.
Features
- Drag-and-drop support for tree nodes.
- Customizable node rendering.
- Lightweight and performant.
Demo


Installation
npm install dnd-kit-tree @dnd-kit/core @dnd-kit/sortable @dnd-kit/utilitiesExample
import { useState } from "react";
import { SortableTree, TreeItems } from "dnd-kit-tree";
type Data = {
label: string;
};
const MyComponent = () => {
const [value, setValue] = useState<TreeItems<Data>>([
{
id: "id-1",
data: { label: "Item 1" },
children: [
{
id: "id-2",
data: { label: "Item 2" },
children: [
{
id: "id-3",
children: [],
data: { label: "Item 3" },
},
],
},
],
},
{
id: "id-4",
children: [],
data: { label: "Item 4" },
},
{
id: "id-5",
children: [],
data: { label: "Item 5" },
},
]);
return (
<SortableTree
removable
collapsible
value={value}
onChange={setValue}
indentationWidth={25}
renderItemContent={(item) => <div>{item.data?.label}</div>}
/>
);
};Props
| Prop | Type | Default | Description |
|---|---|---|---|
value |
TreeItems<T> |
[] |
The tree data structure representing the nodes. |
onChange |
(items: TreeItems<T>) => void |
undefined |
Callback function triggered when the tree structure changes. |
removable |
boolean |
false |
Enables the ability to remove tree nodes. |
collapsible |
boolean |
false |
Enables the ability to collapse/expand tree nodes. |
indentationWidth |
number |
25 |
The width of indentation for child nodes in pixels. |
renderItemContent |
(item: TreeItem<T>) => React.ReactNode |
undefined |
Function to customize the rendering of tree node content. |
Contributing
Contributions are welcome! Please open an issue or submit a pull request.
License
This project is licensed under the MIT License.