Skip to content

ES-Space/es-drager-react

Folders and files

NameName
Last commit message
Last commit date

Latest commit

aff0ad3 ยท Mar 18, 2025

History

91 Commits
Feb 8, 2025
Feb 8, 2025
Dec 4, 2024
Mar 18, 2025
Mar 18, 2025
Feb 8, 2025
Dec 4, 2024
Jan 5, 2025
Jan 5, 2025
Feb 8, 2025
Dec 4, 2024
Feb 8, 2025
Jan 2, 2025

Repository files navigation

ES Drager

A lightweight React component for creating draggable, rotatable and scalable elements with connection capabilities.

โœจ Features

  • ๐ŸŽฏ 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

๐Ÿ“ฆ Installation

# npm
npm install @es-space/es-drager-react

# yarn
yarn add @es-space/es-drager-react

# pnpm
pnpm add @es-space/es-drager-react

๐Ÿš€ Usage

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>
  )
}

๐Ÿ“ Props

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

๐ŸŒฐ Examples

Basic Dragging

<Drager className="w-32 h-32 bg-blue-500">
  Basic draggable element
</Drager>

With Rotation

<Drager
  className="w-32 h-32 bg-blue-500"
  rotatable
>
  Rotatable element
</Drager>

With Scaling

<Drager
  className="w-32 h-32 bg-blue-500"
  scalable
  minScale={0.5}
  maxScale={2}
>
  Scalable element
</Drager>

With Connections

<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>

๐Ÿ”จ Development

# Install dependencies
bun install

# Start development
bun dev

# Build package
bun build

๐Ÿ“„ License

ES Drager is open source software licensed as MIT.