@rast999/drag-and-drop
TypeScript icon, indicating that this package has built-in type declarations

1.0.4 • Public • Published

Drag and drop react

This package is an abstraction over HTML Drag and drop functionality. See standard. This is an internal package and it's not intended to be used by anyone except me since APIs can change anytime.

Sample usage

<div>
    // This is our Droppable container, only required prop is `handleDrop`
    <Droppable<{ src: string; description: string }>
        allowedTypes={['application/custom', 'files']}
        handleDrop={(data) => {
            if (data.items && data.items.length > 0) {
                setSrc(data.items[0]);
            }
        }}
        handleEnter={(data) => {
            data.dropzone?.classList.add('dragging');
        }}
        handleLeave={(data) => {
            data.dropzone?.classList.remove('dragging');
        }}
        className="dragzone"
    >
        <img height="300" src={src.src} alt={src.description} />
        <h3>{src.description}</h3>
    </Droppable>

    // And here are our draggable elements
    <div>
        {images.map((i) => (
            <Draggable
                type="application/custom"
                data={i}
                key={i.src}
                style={{
                    padding: '5px',
                    backgroundColor: 'red',
                    cursor: 'pointer',
                }}
                handleDragStart={(data) => {
                    data.target && (data.target.style.backgroundColor = 'blue');
                }}
                handleDragEnd={(data) => {
                    data.target && (data.target.style.backgroundColor = 'red');
                }}
            >
                <img src={i.src} height="75" alt={i.description} />
                <p>{i.description}</p>
            </Draggable>
        ))}
    </div>
</div>

Readme

Keywords

none

Package Sidebar

Install

npm i @rast999/drag-and-drop

Weekly Downloads

0

Version

1.0.4

License

MIT

Unpacked Size

14.2 kB

Total Files

10

Last publish

Collaborators

  • rast999