Skip to content

Fixes for issues #133 and #141 #144

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Apr 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"env": {
"browser": true,
"es6": true,
"node": true,
"jest": true
},
Expand All @@ -16,8 +17,13 @@
"version": "16.8"
}
},
"ignorePatterns": ["module.d.ts"],
"rules": {
"react-hooks/rules-of-hooks": "error",
"react-hooks/exhaustive-deps": "error"
"react-hooks/exhaustive-deps": "error",
"react/jsx-sort-props": [
"error",
{ "callbacksLast": true, "shorthandFirst": true }
]
}
}
62 changes: 56 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
[![Greenkeeper badge](https://badges.greenkeeper.io/sandstreamdev/react-swipeable-list.svg)](https://greenkeeper.io/)
[![codecov](https://codecov.io/gh/sandstreamdev/react-swipeable-list/branch/master/graph/badge.svg)](https://codecov.io/gh/sandstreamdev/react-swipeable-list)
![GitHub Release Date](https://img.shields.io/github/release-date/sandstreamdev/react-swipeable-list)
[![All Contributors](https://img.shields.io/badge/all_contributors-9-orange.svg?style=flat-square)](#contributors)
[![All Contributors](https://img.shields.io/badge/all_contributors-11-orange.svg?style=flat-square)](#contributors)

## React Swipeable List component

Expand Down Expand Up @@ -60,27 +60,53 @@ import '@sandstreamdev/react-swipeable-list/dist/styles.css';
</SwipeableList>
```

or use function as children pattern if other container is needed (check animation example)

```jsx
<SwipeableList>
{props => (
<TransitionGroup>
<CSSTransition>
<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')
}}
{...props}
>
<div>Item name</div>
</SwipeableListItem>
</CSSTransition>
</TransitionGroup>
)}
</SwipeableList>
```

## SwipeableList Props

### scrollStartThreshold

Type: `number` (default: `10`)
Type: `number` (optional, 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.

### swipeStartThreshold

Type: `number` (default: `10`)
Type: `number` (optional, 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.

### threshold

Type: `number` (default: `0.5`)
Type: `number` (optional, 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.

Expand All @@ -90,23 +116,43 @@ It can be set for the whole list or for every item. See `threshold` for `Swipeab

### blockSwipe

Type: `boolean` (default: `false`)
Type: `boolean` (optional, default: `false`)

If set to `true` all defined swipe actions are blocked.

### swipeLeft

Type: `Object`
Type: `Object` (optional)

Data for defining left swipe action and rendering content after item is swiped. The object requires following structure:

```js
{
action, // required: swipe action (function)
actionAnimation, // optional: type of animation
content, // required: HTML or React component
}
```

#### action

Type: `function` (required)

Callback function that should be run when swipe is done beyond threshold.


#### actionAnimation

Type: `ActionAnimations (RETURN | REMOVE | NONE)` (optional, default: `RETURN`)

Animation type to be played swipe is done beyond threshold.

#### content

Type: `Anything that can be rendered` (required)

Content that is revealed when swiping.

### swipeRight

Type: `Object`
Expand All @@ -117,6 +163,8 @@ Same as `swipeLeft` but to right. :wink:

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 `SwipeableList`. Value from the `SwipeableListItem` takes precedence.

### swipeStartThreshold
Expand All @@ -131,6 +179,8 @@ It can be set for the whole list or for every item. See `swipeStartThreshold` fo

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 `SwipeableList`. Value from the `SwipeableListItem` takes precedence.

### onSwipeStart
Expand Down
12 changes: 10 additions & 2 deletions examples/.eslintrc
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"env": {
"browser": true
"browser": true,
"es6": true
},
"extends": ["plugin:prettier/recommended", "plugin:react/recommended"],
"parser": "babel-eslint",
Expand All @@ -13,6 +14,13 @@
"rules": {
"no-undef": "error",
"react-hooks/rules-of-hooks": "error",
"react-hooks/exhaustive-deps": "error"
"react-hooks/exhaustive-deps": "error",
"react/jsx-sort-props": [
"error",
{
"callbacksLast": true,
"shorthandFirst": true
}
]
}
}
52 changes: 45 additions & 7 deletions examples/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion examples/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@
"@sandstreamdev/react-swipeable-list": "0.4.1",
"@sandstreamdev/std": "0.13.0",
"react": "^16.13.0",
"react-dom": "^16.13.0"
"react-dom": "^16.13.0",
"react-transition-group": "4.3.0",
"uuid": "7.0.3"
}
}
Loading