mirror of
https://github.com/FlipsideCrypto/DefinitelyTyped.git
synced 2026-02-06 10:56:53 +00:00
* [react-dragula] add types * use export = * type as declare module * use export = * fixes for tests * remove global variable * Update types/react-dragula/tsconfig.json Co-authored-by: Piotr Błażejewicz (Peter Blazejewicz) <peterblazejewicz@users.noreply.github.com> * Update types/react-dragula/react-dragula-tests.tsx Co-authored-by: Piotr Błażejewicz (Peter Blazejewicz) <peterblazejewicz@users.noreply.github.com> Co-authored-by: Piotr Błażejewicz (Peter Blazejewicz) <peterblazejewicz@users.noreply.github.com>
42 lines
1.2 KiB
TypeScript
42 lines
1.2 KiB
TypeScript
import React = require('react');
|
|
import reactDragula = require('react-dragula');
|
|
import { Drake } from 'dragula';
|
|
|
|
function DraggableItemss() {
|
|
const draggableContainer = React.useRef<HTMLDivElement>(null);
|
|
const [drake, setDrake] = React.useState<Drake | null>(null);
|
|
|
|
React.useEffect(() => {
|
|
if (draggableContainer.current) {
|
|
setDrake(
|
|
reactDragula([draggableContainer.current], {
|
|
moves: (_el, _container, handle) => {
|
|
if (!handle) {
|
|
return false;
|
|
}
|
|
|
|
return Boolean(handle.closest('.draggable'));
|
|
},
|
|
}),
|
|
);
|
|
}
|
|
}, [draggableContainer.current]);
|
|
|
|
React.useEffect(() => {
|
|
if (drake) {
|
|
drake.on('dragend', e => {
|
|
console.log('dragend');
|
|
});
|
|
}
|
|
}, [drake]);
|
|
|
|
return (
|
|
<div ref={draggableContainer}>
|
|
<div className="draggable">drag me 1</div>
|
|
<div>don't drag me</div>
|
|
<div className="draggable">drag me 2</div>
|
|
<div className="draggable">drag me 3</div>
|
|
</div>
|
|
);
|
|
}
|