šŸš€ Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more →
Socket
Sign inDemoInstall
Socket

react-swipeable-button

Package Overview
Dependencies
Maintainers
0
Versions
25
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

1.6.1
Source
npm
Version published
Weekly downloads
251
-13.75%
Maintainers
0
Weekly downloads
Ā 
Created
Source

react-swipeable-button

NPM licenseinstall sizenpm bundle sizenpm downloads

A npm package for Swipeable button in react

react-swipeable-button

react-swipeable-button

Changes:

v1.6.0

Improvements

  • Shimmer Effect enhancement: Enhanced the visibility of the shimmer effect

Fixes

  • Removed transition effect as it was causing slide delay
  • Disabled animation when the button is disabled

v1.5.2

Fixes

  • Minor Text Visibility fix: Enhanced the visibility of the text when the button is unlocked especially when the text is long.

v1.5.1

Fixes

  • Text Shimmer Visibility: Enhanced the shimmer effect to handle scenarios where the textColor is white or gray, ensuring better visibility and contrast.

v1.5.0

New Features

  • Shimmer Animation: Introduced a shimmer effect for both the button and its text, providing a more engaging visual appearance.

Improvements

  • Long Text Visibility: Enhanced the display logic for long text, ensuring better visibility and alignment in the button UI.

  • Documentation Update: Added troubleshooting tips and best practices to handle long text scenarios effectively.

Migration Notes

  • The shimmer animation is applied by default. It can be disabled by passing noAnimate prop.
  • Existing button functionality remains unaffected, ensuring full backward compatibility.

Check all the changes in the Release Notes

Installs

npm install react-swipeable-button

or

yarn add 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}
      noAnimate={false} //default is false
      text="Swipe me!"
      text_unlocked="yeee"
      sliderTextColor="#fff" //default is #fff
      sliderIconColor="#fff" //default is #fff
      background_color="#eee" //default is #eee
      ...otherProps (check props section for more details)
      name="react-swipeable-button"
    />
  );
}

export default App;

Using ReactNode insead of text

<SwipeableButton
  onSuccess={onSuccess}
  onFailure={onFailure}
  buttonChildren={
    <p style={{ color: "green", textAlign: "center" }}>Click me</p> // instead of text
  }
  buttonChildrenUnlocked={
    <p style={{ color: "red", textAlign: "center" }}>Unlocked!</p> // using instead of text_unlocked
  }
  sliderColor="#16362d"
  sliderTextColor="#fff"
  sliderIconColor="#fff"
  background_color="#eee"
  borderRadius={30}
  circle
  autoWidth
  disabled={false}
  name="react-swipeable-button"
/>

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;

Troubleshooting

  • If you face trouble with long text, try to increase the width
<SwipeableButton
  text="A long text that doesn't fit in the middle" //long text
  width={500} // increase the width (default is 300)
  ...otherProps
/>
  • using buttonChildren and buttonChildrenUnlocked props can be an alternative too though it needs more work ; check props section for more details

Props

PropTypeDefaultDescription
nameString"react-swipeable-button"Unique ID, in case of using several components on one page
buttonChildrenReactNodeNoneWe can pass any react component as children to the button instead of text
buttonChildrenUnlockedReactNodeNoneWe can pass any react component as children to the button instead of text_unlocked when the button is unlocked (buttonChildren is mandatory when buttonChildrenUnlocked is passed)
textString"SWIPE"The text that will be displayed on the swipe button (will be overridden by buttonChildren)
text_unlockedString"UNLOCKED!"The text that will displayed if swiping is successful (will be overridden by buttonChildrenUnlocked)
color (Depricated)String"#333"Depricated, use sliderColor instead
sliderColorString"#16362d"The color of the slider
sliderTextColorString"#fff"The color of the Slider Text
textColorString"#000"The color of the Text (without slider)
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 animation
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

react swipeable button

FAQs

Package last updated on 18 Jan 2025

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