A lightweight React component for creating draggable, rotatable and scalable elements with connection capabilities.
- 🎯 Drag & drop with constraints
- 🔄 Rotation support
- ⚖️ Scale with mouse wheel
- 🔗 Connection points with bezier curves
- 📏 Snap to grid & alignment guides
- 🎨 Tailwind CSS styling
- 🎮 Rich interaction events
# npm
npm install @es-space/es-drager-react
# yarn
yarn add @es-space/es-drager-react
# pnpm
pnpm add @es-space/es-drager-react
import { Drager } from '@es-space/es-drager-react'
function App() {
return (
<Drager
className="w-32 h-32 bg-blue-500"
rotatable
scalable
onDrag={pos => console.log(pos)}
>
Drag me!
</Drager>
)
}
Prop | Type | Default | Description |
---|---|---|---|
id | string | auto-generated | Unique identifier for the drager |
className | string | - | CSS class names |
style | CSSProperties | - | Inline styles |
rotatable | boolean | false | Enable rotation |
scalable | boolean | false | Enable scaling |
minScale | number | 0.5 | Minimum scale value |
maxScale | number | 2 | Maximum scale value |
showGuides | boolean | false | Show alignment guides |
snapToElements | boolean | false | Enable snapping to other elements |
snapThreshold | number | 5 | Snapping threshold in pixels |
connectable | boolean | false | Enable connection points |
limit | Object | - | Movement constraints |
onDrag | function | - | Drag event handler |
onRotate | function | - | Rotation event handler |
onScale | function | - | Scale event handler |
onConnect | function | - | Connection event handler |
<Drager className="w-32 h-32 bg-blue-500">
Basic draggable element
</Drager>
<Drager
className="w-32 h-32 bg-blue-500"
rotatable
>
Rotatable element
</Drager>
<Drager
className="w-32 h-32 bg-blue-500"
scalable
minScale={0.5}
maxScale={2}
>
Scalable element
</Drager>
<Drager
id="drager1"
className="w-32 h-32 bg-blue-500"
connectable
onConnect={(sourceId, sourceAnchor, targetId, targetAnchor) => {
console.log('Connected:', { sourceId, sourceAnchor, targetId, targetAnchor })
}}
>
Connectable element
</Drager>
# Install dependencies
bun install
# Start development
bun dev
# Build package
bun build
ES Drager is open source software licensed as MIT.