import * as React from 'react'; import uniqueId from 'lodash/uniqueId'; import Checkbox from '../checkbox/Checkbox'; import DraggableList from './DraggableList'; import DraggableListItem from './DraggableListItem'; import reorder, { ReorderListItem } from './draggable-list-utils/reorder'; import notes from './DraggableList.stories.md'; interface Props { isDraggableViaHandle?: boolean; } interface State { items: Array; listId: string; } class DraggableListExamples extends React.Component { state = { items: [], listId: '', }; componentDidMount() { this.setState({ items: this.getItems(10), listId: uniqueId(), }); } getItems = (count: number): Array => { return Array.from({ length: count }, (v, k) => k).map(k => ({ id: uniqueId('item_'), label: `item ${k}`, })); }; onDragEnd = (sourceIndex: number, destinationIndex: number) => { if (!destinationIndex) { return; } const items = reorder(this.state.items, sourceIndex, destinationIndex); this.setState({ items, }); }; render() { const { isDraggableViaHandle } = this.props; const { items, listId } = this.state; return ( {items.map((item: ReorderListItem, index) => ( ))} ); } } export const Example = () => ; export const ExampleIsDraggableViaHandle = () => ; export default { title: 'Components/DraggableList', component: DraggableList, parameters: { notes, }, };