2.1.0 • Published 2 years ago

react-swipe-to-delete-ios v2.1.0

Weekly downloads
345
License
MIT
Repository
github
Last release
2 years ago

react-swipe-to-delete-ios

Version

A simple React component to reproduce the way iOS deletes an item in a list. 0 dependency. Demo

GIF Demo

Config very much insipred by this post

Installation

npm i --save react-swipe-to-delete-ios
yarn add react-swipe-to-delete-ios

Usage

import React from 'react'
import SwipeToDelete from 'react-swipe-to-delete-ios'

...

<SwipeToDelete
  onDelete={handleDelete} // required
  // optional
  height={50} // default
  transitionDuration={250} // default
  deleteWidth={75} // default
  deleteThreshold={75} // default
  showDeleteAction={true} //default
  deleteColor="rgba(252, 58, 48, 1.00)" // default
  deleteText="Delete" // default
  deleteComponent={<DeleteComponent/>} // not default
  disabled={false} // default
  id="swiper-1" // not default
  className="my-swiper" // not default
  rtl={false} // default
  onDeleteConfirm={(onSuccess, onCancel) => {
    // not default - default is null
    if (window.confirm("Do you really want to delete this item ?")) {
      onSuccess();
    } else {
      onCancel();
    }
  }}
>
  {children}
</SwipeToDelete>

Props

PropTypeDefault
onDeletefunctionrequired
onDeleteConfirmfunctionnull
heightnumber50
transitionDurationnumber (ms)250
deleteWidthnumber (px)75
deleteThresholdnumber (%)75
showDeleteActionbooltrue
deleteColorstring"rgba(252, 58, 48, 1.00)"
deleteTextstring"Delete" (deleteText or deleteComponent)
deleteComponentnodenull (deleteText or deleteComponent)
disabledboolfalse
rtlboolfalse
idstring''
classNamestring''

Component structure

Knowing the Component structure might help you customise with your own CSS.

<div id={id} className={`rstdi${deleting ? " deleting" : ""} ${className}`}>
  <div className={`delete${deleting ? " deleting" : ""}`}>
    <button>Delete</button>
  </div>
  <div className={`content${deleting ? " deleting" : ""}${!touching ? " transition" : ""}`}>
    {children}
  </div>
</div>

Changelog

v2

rewrite the whole library:

  • remove styled-components - 0 dependency
  • rewrite in Hooks
  • height is now optional
  • update README
  • onDeleteConfirm is now in production
  • new props className and id
  • React > 16.18 (with Hooks) as peerDependencies
2.0.3

2 years ago

2.0.5

2 years ago

2.0.4

2 years ago

2.0.7

2 years ago

2.0.6

2 years ago

2.0.73

2 years ago

2.0.74

2 years ago

2.0.71

2 years ago

2.0.72

2 years ago

2.1.0

2 years ago

2.0.1

2 years ago

2.0.0

2 years ago

1.0.11

3 years ago

1.0.10

3 years ago

1.0.8

4 years ago

1.0.7

4 years ago

1.0.6

4 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago