Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 

README.md

@dnd-block-tree/react

npm version

React adapter for dnd-block-tree — components, hooks, and @dnd-kit integration for building hierarchical drag-and-drop interfaces.

Installation

npm install @dnd-block-tree/core @dnd-block-tree/react @dnd-kit/core @dnd-kit/utilities

Requires @dnd-block-tree/core 2+, React 18+, and @dnd-kit/core 6+.

What's Included

  • ComponentsBlockTree, BlockTreeSSR, TreeRenderer, DropZone, DragOverlay
  • HooksuseBlockHistory, useLayoutAnimation, useVirtualTree, useConfiguredSensors
  • Collision BridgeadaptCollisionDetection to bridge core's CoreCollisionDetection to @dnd-kit's CollisionDetection
  • Re-exports — all types and utilities from @dnd-block-tree/core

Quick Example

import { BlockTree, type BaseBlock, type BlockRenderers } from '@dnd-block-tree/react'

interface MyBlock extends BaseBlock {
  type: 'section' | 'task'
  title: string
}

const renderers: BlockRenderers<MyBlock, ['section']> = {
  section: ({ block, children, isExpanded, onToggleExpand }) => (
    <div>
      <button onClick={onToggleExpand}>{isExpanded ? '▼' : '▶'} {block.title}</button>
      {isExpanded && <div className="ml-4">{children}</div>}
    </div>
  ),
  task: ({ block }) => <div>{block.title}</div>,
}

function App() {
  const [blocks, setBlocks] = useState<MyBlock[]>(initialBlocks)
  return (
    <BlockTree
      blocks={blocks}
      renderers={renderers}
      containerTypes={['section']}
      onChange={setBlocks}
    />
  )
}

Documentation

Full docs at blocktree.sandybridge.io.

License

MIT