diff --git a/tests-e2e/stories/use-drag-and-drop/primary.story.tsx b/tests-e2e/stories/use-drag-and-drop/primary.story.tsx index 1256d72..c31370a 100644 --- a/tests-e2e/stories/use-drag-and-drop/primary.story.tsx +++ b/tests-e2e/stories/use-drag-and-drop/primary.story.tsx @@ -36,7 +36,7 @@ export default function Example() { This block is draggable
diff --git a/tests-e2e/stories/use-drag-and-drop/swipes.m.css b/tests-e2e/stories/use-drag-and-drop/swipes.m.css new file mode 100644 index 0000000..0eb0b8c --- /dev/null +++ b/tests-e2e/stories/use-drag-and-drop/swipes.m.css @@ -0,0 +1,50 @@ +.list { + margin: 24px; + border-radius: 8px; + display: flex; + flex-direction: column; + background: #ddd; + padding: 8px; + overflow: hidden; +} + +.list .item + .item { + border-top: 1px solid #ddd; +} + +.item { + position: relative; + display: flex; +} + +.draggable { + flex-grow: 1; + padding: 0 12px; + display: flex; + align-items: center; + height: 64px; + background: #fff; + overflow: hidden; + z-index: 1; +} + +.draggable:hover { + cursor: grab; +} + +.draggable:active { + cursor: grabbing; +} + +.rubber { + position: absolute; + top: 0; + right: 0; + bottom: 0; + background: rgb(246, 75, 75); + color: #fff; + display: flex; + align-items: center; + justify-content: center; + overflow: hidden; +} diff --git a/tests-e2e/stories/use-drag-and-drop/swipes.story.tsx b/tests-e2e/stories/use-drag-and-drop/swipes.story.tsx new file mode 100644 index 0000000..2ba7305 --- /dev/null +++ b/tests-e2e/stories/use-drag-and-drop/swipes.story.tsx @@ -0,0 +1,93 @@ +import { type CSSProperties, type ReactNode, useRef, useState } from 'react'; +import { useDragAndDrop } from '@krutoo/utils/react'; +import styles from './swipes.m.css'; + +export const meta = { + category: 'React hooks/useDragAndDrop', + title: 'Swipes', +}; + +export default function Example() { + const [items, setItems] = useState(() => + Array(10) + .fill(0) + .map((zero, index) => ({ id: index })), + ); + + const deleteItem = (itemId: number) => { + setItems(prev => prev.filter(item => item.id !== itemId)); + }; + + return ( +