A control to render list with swipeable items. Items can have action on left and right swipe. Swipe action triggering can be configured.
Check working example page or experiment on:
npm install @sandstreamdev/react-swipeable-list
# or via yarn
yarn add @sandstreamdev/react-swipeable-list
import { SwipeableList, SwipeableListItem } from '@sandstreamdev/react-swipeable-list';
import '@sandstreamdev/react-swipeable-list/dist/styles.css';
<SwipeableList>
<SwipeableListItem
swipeLeft={{
content: <div>Revealed content during swipe</div>,
action: () => console.info('swipe action triggered')
}}
swipeRight={{
content: <div>Revealed content during swipe</div>,
action: () => console.info('swipe action triggered')
}}
onSwipeProgress={progress => console.info(`Swipe progress: ${progress}%`)}
>
<div>Item name</div>
</SwipeableListItem>
</SwipeableList>
Type: number
(default: 10
)
How far in pixels scroll needs to be done to block swiping. After scrolling is started and goes beyond the threshold, swiping is blocked.
It can be set for the whole list or for every item. See scrollStartThreshold
for SwipeableListItem
. Value from the SwipeableListItem
takes precedence.
Type: number
(default: 10
)
How far in pixels swipe needs to be done to start swiping on list item. After a swipe is started and goes beyond the threshold, scrolling is blocked.
It can be set for the whole list or for every item. See swipeStartThreshold
for SwipeableListItem
. Value from the SwipeableListItem
takes precedence.
Type: number
(default: 0.5
)
How far swipe needs to be done to trigger attached action. 0.5
means that item needs to be swiped to half of its width, 0.25
- one-quarter of width.
It can be set for the whole list or for every item. See threshold
for SwipeableListItem
. Value from the SwipeableListItem
takes precedence.
Type: boolean
(default: false
)
If set to true
all defined swipe actions are blocked.
Type: Object
Data for defining left swipe action and rendering content after item is swiped. The object requires following structure:
{
action, // required: swipe action (function)
content, // required: HTML or React component
}
Type: Object
Same as swipeLeft
but to right.
Type: number
(default: 10
)
It can be set for the whole list or for every item. See scrollStartThreshold
for SwipeableList
. Value from the SwipeableListItem
takes precedence.
Type: number
(default: 10
)
How far in pixels swipe needs to be done to start swiping on list item. After a swipe is started and goes beyond the threshold, scrolling is blocked.
It can be set for the whole list or for every item. See swipeStartThreshold
for SwipeableList
. Value from the SwipeableListItem
takes precedence.
Type: number
(default: 0.5
)
It can be set for the whole list or for every item. See threshold
for SwipeableList
. Value from the SwipeableListItem
takes precedence.
Type: () => void
Fired after swipe has started (after drag gesture passes the swipeStartThreshold
distance in pixels).
Type: () => void
Fired after swipe has ended.
Type: (progress: number) => void
Fired every time swipe progress changes. The reported progress
value is always an integer in range 0 to 100 inclusive.
Author: sandstreamdev
Live Demo: https://sandstreamdev.github.io/react-swipeable-list/
GitHub: https://github.com/sandstreamdev/react-swipeable-list
#reactjs #javascript