import _, { concat, slice, reverse, map } from 'lodash'; import React, { useState } from 'react'; import { Meta, Story } from '@storybook/react'; import DragCaptureZone, { IDragCaptureZoneProps } from './DragCaptureZone'; export default { title: 'Utility/DragCaptureZone', component: DragCaptureZone, parameters: { docs: { description: { component: (DragCaptureZone as any).peek.description, }, }, }, args: DragCaptureZone.defaultProps, decorators: [ (Story) => (
), ], } as Meta; /* Interactive */ export const Interactive: Story = (args) => { const [events, setEvents] = useState>([]); const handleDragEnded = (coordinates: any) => { const newEndEvents = concat(events, { type: 'end', coordinates }); setEvents([...newEndEvents]); }; const handleDragStarted = (coordinates: any) => { const newStartEvents = concat(events, { type: 'start', coordinates }); setEvents([...newStartEvents]); }; const handleDragged = (coordinates: any) => { const lastEvent: any = _.last(events); const alreadyDragging = lastEvent.type === 'start'; const newDraggedEvents = concat( alreadyDragging ? events : slice(events, 0, -1), { type: 'drag', coordinates } ); setEvents([...newDraggedEvents]); }; return (
Go wild!
{reverse( map(events, ({ type, coordinates }, index) => (
{type}
{`dx: ${coordinates.dX}, dy: ${coordinates.dY}, px: ${coordinates.pageX}, py: ${coordinates.pageY}`}
)) )}
); };