@duongtdn/react-drag-component
v1.0.1
Published
React Drag component
Downloads
7
Readme
@interactivity/drag-component
Installation
npm install --save @interactivity/drag-component
Usage
example code
"use strict"
import React from "react";
import { DragContainer, DragHolder, DragItem } from "@interactivity/drag-component";
const DragPlayground = () => (
<DragContainer alignHolderSize = {true} onDragEnd = { status => console.log(status)}>
<h2> Drag Playground </h2>
<div className="flex-container flex-direction-row">
<div style = {{ flex: 1}} >
<DragHolder direction = "column"
id = "holder_1"
stretch
minHeight = {40}
>
<Draggable id = "red" mode = {mode}>
<div className = "red" style = {{height: '40px'}}> Drag me!</div>
</Draggable>
<Draggable id = "green" mode = {mode}>
<div className = "green" style = {{height: '40px'}}> Drag me!</div>
</Draggable>
</DragHolder>
</div>
<div style = {{ flex: 1}} >
<DragHolder direction = "column"
id = "holder_1"
stretch
minHeight = {40}
>
<Draggable id = "blue" mode = {mode}>
<div className = "blue" style = {{height: '40px'}}> Drag me!</div>
</Draggable>
</DragHolder>
</div>
</div>
</DragContainer>
);
DragContainer
Control the draggable zone
. It manages DragHolder
and DragItem
components
Props:
width:
optional
specify fixed width in pixel of the drag zoneheight:
optional
specify fixed height in pixel of the drag zonealignHolderSize:
default = false
all holder with same direction will be aligned in their main dimensionfixedHolderLength:
default = false
specify if all holders have their length (width or height depend on its direction) equal to total item lengthinitState:
optional
initial state of holders and itemsonDragEnd:
optional
callback that receive internal status of holders and items
DragHolder
Holder storing draggable items which operate in flow
mode.
Props:
id:
mandatory
ID of DragHolderdirection:
mandatory
growth direction of the holder when items are added, i.e.row
orcolumn
stretch:
optional
the holder width will be 100%. It overrides thealignHolderSize
. Note thatstretch
only work withdirection = row
and does not affect toheight
size:
optional
an object{width, height}
specifing fixed width or heigtht of the holderminWidth:
optional
specify minWidth of the holderminHeight:
optional
specify minHeight of the holder
Draggable
Wrap element in an draggable item
Props:
id:
mandatory
ID of Draggablemode:
default = flow
. Inflow
mode, drag item is only stay inside a holder, infree
mode, drag item can be drag anywhere