Socket
Socket
Sign inDemoInstall

react-swipeable-button

Package Overview
Dependencies
Maintainers
0
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-swipeable-button

A component to create swipeable button in react


Version published
Weekly downloads
229
decreased by-22.64%
Maintainers
0
Weekly downloads
 
Created
Source

react-swipeable-button

NPM licenseinstall sizenpm bundle sizenpm downloads

A npm pacakge for Swipeable button in react

Changes:

v1.2.0

  • Added buttonReset method to handle resetting the button's swipe state programmatically.
  • Added buttonComplete method to handle completing the button's swipe state programmatically.

Check all the changes in the Release Notes

Installs

npm install react-swipeable-button

or

yarn add react-swipeable-button

Demo

react-swipeable-button

Usage

General Usage
import { SwipeableButton } from "react-swipeable-button";

function App() {
  const onSuccess = () => {
    console.log("Successfully Swiped!");
  };

  const onFailure = () => {
    console.log("Failed to Swipe!");
  };

  return (
    <SwipeableButton
      onSuccess={onSuccess}
      onFailure={onFailure}
      text="Swipe me!"
      text_unlocked="yeee"
      sliderColor="#16362d"
      sliderTextColor="#fff"
      sliderIconColor="#fff"
      background_color="#eee"
      borderRadius={30}
      circle
      autoWidth
      disabled={false}
      name="react-swipeable-button"
    />
  );
}

export default App;
With Ref : buttonReset and buttonComplete methods
import { useRef } from "react";
import { SwipeableButton } from "react-swipeable-button";

function App() {

  const swipeableButtonRef = useRef<SwipeableButton | null>(null); // Create a ref for the component

  const handleReset = () => {
    swipeableButtonRef.current?.buttonReset(); // Call the reset method
  };

  const handleComplete = () => {
    swipeableButtonRef.current?.buttonComplete(); // Call the complete method
  };
  return (
      <SwipeableButton
        text="Swipe me!"
        text_unlocked="yeee"
        color="16362d"
        sliderTextColor="#fff"
        sliderIconColor="#fff"
        background_color="#eee"
        circle
        name="react-swipeable-button"
        ref={swipeableButtonRef} // Expose the ref to the component
      />
      //example usage of the reset and complete methods
      <button onClick={handleReset}>Reset</button>
      <button onClick={handleComplete}>Complete</button>
    </div>
  );
}

export default App;

Props

PropTypeDefaultDescription
nameString"react-swipeable-button"Unique ID, in case of using several components on one page
textString"SWIPE"The text that will be displayed on the swipe button
text_unlockedString"UNLOCKED!"The text that will displayed if swiping is successful
color (Depricated)String"#333"Depricated, use sliderColor instead
sliderColorString"#16362d"The color of the slider
sliderTextColorString"#fff"The color of the text
sliderIconColorString"#fff"The color of the icon
background_colorString"#eee"The background color of the container
borderRadiusNumber30The border radius of the container lets you control the roundness of the corners (ignored if circle is false)
noAnimateBooleanfalseDisable css transition
widthNumber300Width of element (ignored if autoWidth is true)
heightNumber50Height of element
autoWidthBooleanfalsetakes 100% width of parent div
circleBooleantrueAll parts of component will be with border-radius and rounded handler
disabledBooleanfalseDisable interaction with component
onSuccessFunction (optional)nullThe function that will be called when a swipe is successful
onFailureFunction (optional)nullThe function that will be called when a swipe is failed

Contribution

Contributing on this project is always welcome! Just fork, update, push to your respective branch and make a pull request after testing. Make sure to open an issue before contribute.

License

MIT © Abdur Rahman

Keywords

FAQs

Package last updated on 15 Oct 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc