Giter Club home page Giter Club logo

react-swipeable-list's Introduction

react-swipeable-list

A react component to render list with swipeable items.

DemoInstallationUsage


Actions Status codecov GitHub Release Date

React Swipeable List component

A react component to render list with swipeable items. Items can have one or more actions on left (leading) and right (trailing) swipe and different behaviour depending on props.

Demo

Check working example page

Edit react-swipeable-list

Installation

npm install react-swipeable-list
# or via yarn
yarn add react-swipeable-list

Usage

import {
  LeadingActions,
  SwipeableList,
  SwipeableListItem,
  SwipeAction,
  TrailingActions,
} from 'react-swipeable-list';
import 'react-swipeable-list/dist/styles.css';

const leadingActions = () => (
  <LeadingActions>
    <SwipeAction onClick={() => console.info('swipe action triggered')}>
      Action name
    </SwipeAction>
  </LeadingActions>
);

const trailingActions = () => (
  <TrailingActions>
    <SwipeAction
      destructive={true}
      onClick={() => console.info('swipe action triggered')}
    >
      Delete
    </SwipeAction>
  </TrailingActions>
);

<SwipeableList>
  <SwipeableListItem
    leadingActions={leadingActions()}
    trailingActions={trailingActions()}
  >
    Item content
  </SwipeableListItem>
</SwipeableList>;

SwipeableList Props

fullSwipe

Type: boolean (optional, default: false)

Changes behaviour of IOS list type. When true and swipe is done beyond threshold and released the action is triggered.

When set to false actions are only opened and they need to be clicked to trigger action.

destructiveCallbackDelay

Type: miliseconds (optional, default: 1000)

Time in miliseconds after which swipe action should be called for destructive swipe action (item deletion)

style

Type: object (optional, deafult: undefined)

Additional styles for list tag.

type

Type: ListType (ANDROID | IOS) (optional, deafult: ANDROID)

Changes behavior of swipeable items.

ANDROID

IOS

Tag

Type: string (optional, deafult: div)

HTML tag that is used to create this component.

scrollStartThreshold

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 (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 (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.

It can be set for the whole list or for every item. See threshold for SwipeableListItem. Value from the SwipeableListItem takes precedence.

SwipeableListItem Props

blockSwipe

Type: boolean (optional, default: false)

If set to true all defined swipe actions are blocked.

onSwipeStart

Type: () => void

Fired after swipe has started (after drag gesture passes the swipeStartThreshold distance in pixels).

onSwipeEnd

Type: () => void

Fired after swipe has ended.

onSwipeProgress

Type: (progress: number) => void

Fired every time swipe progress changes. The reported progress value is always an integer in range 0 to 100 inclusive.

scrollStartThreshold

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

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.

threshold

Type: number (default: 0.5)

How far swipe needs to be done to trigger 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.

SwipeAction Props

destructive

Type: boolean (optional, default: false)

If set to true then remove animation is played and callback is called after destructiveCallbackDelay.

onClick

Type: function (required)

Callback function that should be call after swipe action is triggered.

Tag

Type: string (optional, deafult: span)

HTML tag that is used to create this component.

react-swipeable-list's People

Contributors

marekrozmus avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.