项目作者: gaer87

项目描述 :
A simple React component implement 'swipe to delete' UI-pattern.
高级语言: JavaScript
项目地址: git://github.com/gaer87/react-swipe-to-delete-component.git
创建时间: 2017-01-02T14:49:30Z
项目社区:https://github.com/gaer87/react-swipe-to-delete-component

开源协议:MIT License

下载


React-swipe-to-delete-component

Code Climate
Coverage Status

A simple React component implement ‘swipe to delete’ UI-pattern.

Install

React-swipe-to-delete-component is available via npm.

  1. npm install react-swipe-to-delete-component

Usage

The React-swipe-to-delete-component wrap your a content component. It’s become swiped. If it’s swiped more certain percent than the swipe-to-delete-component will remove a component.

Example

You may see an example here.

  1. import React from 'react';
  2. import { render } from 'react-dom';
  3. // Import the react-swipe-to-delete-component
  4. import SwipeToDelete from 'react-swipe-to-delete-component';
  5. // Import styles of the react-swipe-to-delete-component
  6. import 'react-swipe-to-delete-component/dist/swipe-to-delete.css';
  7. const data = [
  8. {id: 1, text: 'End of summer reading list', date: '1.03.2016'},
  9. {id: 2, text: 'Somewhere in the middle 📸', date: '23.01.2017'},
  10. {id: 3, text: 'Good morning to 9M of you?!?! ❤️🙏🏻Feeling very grateful and giddy.', date: '12.01.2022'}
  11. ];
  12. const list = data.map(item => (
  13. <SwipeToDelete key={item.id}>
  14. <a className="list-group-item">
  15. <h4 className="list-group-item-heading">{item.date}</h4>
  16. <p className="list-group-item-text">{item.text}</p>
  17. </a>
  18. </SwipeToDelete>
  19. ));
  20. const app = (
  21. <div className="list-group">
  22. {list}
  23. </div>
  24. );
  25. render(app, document.getElementById('root'));

Props

  • tag - This is tag name of a root element. By default, it’s “div”. Optional.
  • classNameTag - This is classes of a root element. Optional.
  • background - This is a decoration component under a content component. By default, showed red element with trash icons. Optional.
  • deleteSwipe - This is a number. If a content component is swiped more this the number than a swipe-to-delete component will start a delete animation. By default, it’s equal “0.5”. Optional.
  • onDelete - This is a function. If a content component is deleted then it will be called. It receives custom props from a <SwipeToDelete ></SwipeToDelete> component. Optional.
  • onCancel - This is a function. If a content component isn’t deleted then it will be called. It receives custom props from a <SwipeToDelete ></SwipeToDelete> component. Optional.
  • onRight/onLeft - This is a function. If a content component is swiped then these functions is called. Optional.

Styles

The class js-content is content region, js-delete is delete region. Classes js-transition-delete-right and js-transition-delete-left are added on a content component when it’s swiped more than “deleteSwipe” options. Class js-transition-cancel is added when a content component swiped less than “deleteSwipe” options. Animations are made by CSS3 transition.

Changes

See the CHANGELOG.

Contributing

From opening a bug report to creating a pull request: every contribution is appreciated and welcome. If you’re planing to implement a new feature or change the api please create an issue first.

License

MIT