import React, { useState } from 'react'; import { Story, Meta } from '@storybook/react'; import DraggableList, { IDraggableListProps } from './DraggableList'; import CheckboxLabeled from '../CheckboxLabeled/CheckboxLabeled'; export default { title: 'Controls/DraggableList', component: DraggableList, parameters: { docs: { description: { component: DraggableList.peek.description, }, }, }, } as Meta; /* Basic */ export const Basic: Story = (args) => { const [items, setItems] = useState([ 'Item One', 'Item Two', 'Item Three', 'Item Four', 'Item Five', ]); const handleDrop = ({ oldIndex, newIndex, }: { oldIndex: number; newIndex: number; }) => { const updatedItems = items.filter( (column: string, index: number) => index !== oldIndex ); updatedItems.splice(newIndex, 0, items[oldIndex]); console.info(updatedItems); setItems(updatedItems); }; return ( {items.map((text: string) => ( {text} ))} ); }; /* No Drag Handle */ export const NoDragHandle: Story = (args) => { const [items, setItems] = useState([ 'Item One', 'Item Two', 'Item Three', 'Item Four', 'Item Five', ]); const handleDrop = ({ oldIndex, newIndex, }: { oldIndex: number; newIndex: number; }) => { const updatedItems = items.filter( (column: string, index: number) => index !== oldIndex ); updatedItems.splice(newIndex, 0, items[oldIndex]); setItems(updatedItems); }; return ( {items.map((text: string) => ( {text} ))} ); }; /* With Children */ export const WithChildren: Story = (args) => { const [items, setItems] = useState([ 'Item One', 'Item Two', 'Item Three', 'Item Four', 'Item Five', ]); const handleDrop = ({ oldIndex, newIndex, }: { oldIndex: number; newIndex: number; }) => { const updatedItems = items.filter( (column: string, index: number) => index !== oldIndex ); updatedItems.splice(newIndex, 0, items[oldIndex]); setItems(updatedItems); }; return ( {items.map((text: string) => (
))}
); };