代码拉取完成,页面将自动刷新
Simple, lightweight and highly customizable dnd nested sortable React component based on React DnD
Supported to sort the tree, vertical list, horizontal list, table row and maybe more!
npm install --save react-sortly react-dnd react-dnd-html5-backend immutability-helper memoize-one
or
yarn add react-sortly react-dnd react-dnd-html5-backend immutability-helper memoize-one
Demo: https://lytc.github.io/react-sortly
API Documentation: https://lytc.github.io/react-sortly/api
import React from 'react';
import ReactDOM from 'react-dom';
import { DndProvider } from 'react-dnd';
import HTML5Backend from 'react-dnd-html5-backend';
import Sortly, { ContextProvider, useDrag, useDrop } from 'react-sortly';
const ItemRenderer = (props) => {
const { data: { name, depth } } = props;
const [, drag] = useDrag();
const [, drop] = useDrop();
return (
<div ref={drop}>
<div ref={drag} style={{ marginLeft: depth * 20 }}>{name}</div>
</div>
);
};
const MySortableTree = () => {
const [items, setItems] = React.useState([
{ id: 1, name: 'Priscilla Cormier', depth: 0 },
{ id: 2, name: 'Miss Erich Bartoletti', depth: 0 },
{ id: 3, name: 'Alison Friesen', depth: 1 },
{ id: 4, name: 'Bernita Mayert', depth: 2 },
{ id: 5, name: 'Garfield Berge', depth: 0 },
]);
const handleChange = (newItems) => {
setItems(newItems);
};
return (
<Sortly items={items} onChange={handleChange}>
{(props) => <ItemRenderer {...props} />}
</Sortly>
);
};
const App = () => (
<DndProvider backend={HTML5Backend}>
<ContextProvider>
<MySortableTree />
</ContextProvider>
</DndProvider>
);
const rootElement = document.getElementById('root');
ReactDOM.render(<App />, rootElement);
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。