|
| 1 | +import DocPage from '@docs/doc-page'; |
| 2 | +import ComponentMapperBar from '@docs/component-mapper-bar'; |
| 3 | +import Alert from '@mui/material/Alert'; |
| 4 | + |
| 5 | +<DocPage> |
| 6 | + |
| 7 | +# Drag and Drop |
| 8 | + |
| 9 | +<ComponentMapperBar prefix="mui" github="https://github.com/data-driven-forms/editor/tree/main/packages/dnd" npm="https://www.npmjs.com/package/@data-driven-forms%2Fdnd" npmSvg="https://badge.fury.io/js/@data-driven-forms%2Fdnd.svg" /> |
| 10 | + |
| 11 | +<br /> |
| 12 | + |
| 13 | +<Alert severity="warning">This library is work-in-progress and in preview. API is unstable.</Alert> |
| 14 | + |
| 15 | +<br /> |
| 16 | + |
| 17 | +`@data-driven-forms/dnd` is a library providing drag and drop functionality for React components. This custom light-weight library currently supports mouse and touch input, is highly customisable and supports deep nesting of container elements. |
| 18 | + |
| 19 | +## Installation |
| 20 | + |
| 21 | +```bash |
| 22 | +npm install --save @data-driven-forms/dnd |
| 23 | +``` |
| 24 | +or |
| 25 | +```bash |
| 26 | +yarn add @data-driven-forms/dnd |
| 27 | +``` |
| 28 | + |
| 29 | +### API |
| 30 | + |
| 31 | +### dispatchContext |
| 32 | + |
| 33 | +An utility to create an context for `dispatch` function. |
| 34 | + |
| 35 | +### DropCursor |
| 36 | + |
| 37 | +A component handling moving cursor and selecting the correct place to move dragged element. |
| 38 | + |
| 39 | +### findTargetElement |
| 40 | + |
| 41 | +An utility function to go over all elements' positions stored in state and selecting the correct place. |
| 42 | + |
| 43 | +### pauseEvent |
| 44 | + |
| 45 | +An utility to stop an event from propagation and default action. |
| 46 | + |
| 47 | +### Provider |
| 48 | + |
| 49 | +A wrapper providing all neccessary components. |
| 50 | + |
| 51 | +### reducer |
| 52 | + |
| 53 | +A reducer providing the basic drag and drop functionality. |
| 54 | + |
| 55 | +### stateContext |
| 56 | + |
| 57 | +An utility to create an context for a drag and drop `state`. |
| 58 | + |
| 59 | +### useComponent |
| 60 | + |
| 61 | +*({ id: any }) => { ref, component }* |
| 62 | + |
| 63 | +A hook to connect a component to DnD state. Requires an id of the component. Returns a `ref` and the `component` object from the state. |
| 64 | + |
| 65 | +### useContainer |
| 66 | + |
| 67 | +*({ id?: any, isRoot?: boolean }) => { ref, container, id }* |
| 68 | + |
| 69 | +A hook to connect a container to DnD state. Requires an id of the container or a root in case the container is the root container. Returns a `ref`, `id` and the `container` object from the state. |
| 70 | + |
| 71 | +### useDispatch |
| 72 | + |
| 73 | +An utility to obtain a dispatch function for the DnD reducer. |
| 74 | + |
| 75 | +### useHandle |
| 76 | + |
| 77 | +*({component: string, sourceContainer?: string }) => { onClick, onMouseDown, onTouchStart }* |
| 78 | + |
| 79 | +A hook returning handle events for a component handle. Requires an `id` of the component. |
| 80 | + |
| 81 | +### useState |
| 82 | + |
| 83 | +An utility to obtain a state object for the DnD reducer. |
| 84 | + |
| 85 | +</DocPage> |
0 commit comments