Skip to content

Commit

Permalink
Update typescript declarations
Browse files Browse the repository at this point in the history
  • Loading branch information
Marek Rozmus committed Apr 15, 2020
1 parent 413c89e commit 2951ff8
Show file tree
Hide file tree
Showing 4 changed files with 133 additions and 25 deletions.
1 change: 1 addition & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"version": "16.8"
}
},
"ignorePatterns": ["module.d.ts"],
"rules": {
"react-hooks/rules-of-hooks": "error",
"react-hooks/exhaustive-deps": "error",
Expand Down
16 changes: 10 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,23 +90,23 @@ or use function as children pattern if other container is needed (check animatio

### 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 @@ -116,13 +116,13 @@ 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:

Expand All @@ -143,7 +143,7 @@ Callback function that should be run when swipe is done beyond threshold.

#### actionAnimation

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

Animation type to be played swipe is done beyond threshold.

Expand All @@ -163,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 @@ -177,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
6 changes: 3 additions & 3 deletions examples/src/size-to-content/List.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useState } from 'react';
import React from 'react';
import {
SwipeableList,
SwipeableListItem
Expand All @@ -13,7 +13,7 @@ import { MailIcon, ReplyIcon, DeleteIcon } from '../../images/icons';
import styles from '../app.module.css';

const SizeToContentList = () => {
const [items] = useState([
const items = [
{ id: 1, text: 'First', description: 'first description' },
{ id: 2, text: 'Second', description: 'second description' },
{ id: 3, text: 'Third', description: 'third description' },
Expand All @@ -26,7 +26,7 @@ const SizeToContentList = () => {
{ id: 10, text: 'Tenth', description: 'tenth description' },
{ id: 11, text: 'Eleventh', description: 'eleventh description' },
{ id: 12, text: 'Twelfth', description: 'twelfth description' }
]);
];

const swipeRightOptions = () => ({
content: (
Expand Down
135 changes: 119 additions & 16 deletions src/module.d.ts
Original file line number Diff line number Diff line change
@@ -1,37 +1,140 @@
import * as React from 'react';
import { FunctionComponent, PureComponent, ReactNode } from 'react';

export enum ActionAnimations {
RETURN = 'RETURN',
REMOVE = 'REMOVE',
NONE = 'NONE'
/**
* Item returns to start position.
*/
RETURN,
/**
* Item moves out of the screen.
*/
REMOVE,
/**
* Item stays in place it was dragged to.
*/
NONE
}

export interface ISwipeableListProps {
scrollStartThreshold?: number;
swipeStartThreshold?: number;
threshold?: number;
}

export class SwipeableList extends React.Component<ISwipeableListProps> {}

interface ISwipeActionProps {
/**
* Callback function that should be run when swipe is done beyond threshold.
*/
action: () => void;
/**
* default: `RETURN`
*
* Animation type to be played swipe is done beyond threshold.
*/
actionAnimation?: ActionAnimations;
content: React.ReactNode;
/**
* Content that is revealed when swiping.
*/
content: ReactNode;
}

interface ISwipeableListItemProps {
/**
* default: `false`
*
* If set to `true` all defined swipe actions are blocked.
*/
blockSwipe?: boolean;
/**
* Data for defining left swipe action and rendering content after item is swiped.
*/
swipeLeft?: ISwipeActionProps;
/**
* Data for defining right swipe action and rendering content after item is swiped.
*/
swipeRight?: ISwipeActionProps;
/**
* 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.
*/
scrollStartThreshold?: 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.
*/
swipeStartThreshold?: 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.
*/
threshold?: number;
/**
* Fired after swipe has started (after drag gesture passes the `swipeStartThreshold` distance in pixels).
*/
onSwipeStart?: () => void;
/**
* Fired after swipe has ended.
*/
onSwipeEnd?: () => void;
/**
* Fired every time swipe progress changes. The reported `progress` value is always an integer in range 0 to 100 inclusive.
*/
onSwipeProgress?: (progress: number) => void;
}

export class SwipeableListItem extends React.Component<
ISwipeableListItemProps
> {}
interface IBaseSwipeableListProps {
/**
* 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.
*/
scrollStartThreshold?: 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.
*/
swipeStartThreshold?: 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.
*/
threshold?: number;
}

type SwipeableListChildren =
| ReactNode
| ((props: IBaseSwipeableListProps) => ReactNode);

interface ISwipeableListProps extends IBaseSwipeableListProps {
/**
* A function child can be used instead of a SwipeableListItem elements. This function is
* called with the SwipeableList props (scrollStartThreshold, swipeStartThreshold, threshold),
* which can be used to apply context specific props to a component.
* ```jsx
* <SwipeableList threshold={0.5}>
* {props => (
* <SwipeableListItme {...props} />
* )}
* </SwipeableList>
* ```
*/
children?: SwipeableListChildren;
}

export class SwipeableListItem extends PureComponent<ISwipeableListItemProps> {}

/**
* NOTE: A function child can be used instead of a SwipeableListItem elements.
*/
export const SwipeableList: FunctionComponent<ISwipeableListProps>;

0 comments on commit 2951ff8

Please sign in to comment.