<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Abdur Rahman </title>
    <description>The latest articles on DEV Community by Abdur Rahman  (@abdurrahman720).</description>
    <link>https://dev.to/abdurrahman720</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1261210%2F736831c6-3040-4c7f-b923-754c506a1a66.jpeg</url>
      <title>DEV Community: Abdur Rahman </title>
      <link>https://dev.to/abdurrahman720</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/abdurrahman720"/>
    <language>en</language>
    <item>
      <title>Add swipe-able button in React</title>
      <dc:creator>Abdur Rahman </dc:creator>
      <pubDate>Thu, 29 Feb 2024 21:37:55 +0000</pubDate>
      <link>https://dev.to/abdurrahman720/add-swipe-able-button-in-react-58bj</link>
      <guid>https://dev.to/abdurrahman720/add-swipe-able-button-in-react-58bj</guid>
      <description>&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9wfjn4aye00qkpxd4dnj.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9wfjn4aye00qkpxd4dnj.gif" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;So I was struggling to find a right react component library for interactive button that can be swiped both in touch and mouse move.&lt;/p&gt;

&lt;p&gt;Although I got a blog and found one react library which is not maintained now and has no support for TypeScript.&lt;/p&gt;

&lt;p&gt;Inspired from the library , I polished the code , added latest React and TypeScript support and published as npm package.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Let’s explore the magic!&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;We need to install the library package first.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;code&gt;npm install react-swipeable-button&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;or&lt;/p&gt;

&lt;p&gt;&lt;code&gt;yarn add react-swipeable-button&lt;/code&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Now we need to import the ‘SwipeableButton’ component from the ‘react-swipeable-button’ package.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;To resize the button, we need to wrap it with a parent div and add CSS properties ( Here, we are using Tailwind).&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

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

function App() {

  const onSuccess = () =&amp;gt; {
    console.log("Successfully Swiped!");
  };

  return (
    &amp;lt;div className="w-[500px] h-[100px] bg-white"&amp;gt;
       &amp;lt;SwipeableButton
                  onSuccess={onSuccess} //callback function
                  text="Swipe me!" //string 
                  text_unlocked="yeee" //string
                  color="#16362d" //css hex color
                /&amp;gt;
    &amp;lt;/div&amp;gt;
  );
}

export default App;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;ul&gt;
&lt;li&gt;The props are optional but you need to use them for comprehensive customizations.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;To explore more about the package or for contribution, check the package link below.&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;
&lt;div class="crayons-card c-embed text-styles text-styles--secondary"&gt;
      &lt;div class="c-embed__cover"&gt;
        &lt;a href="https://www.npmjs.com/package/react-swipeable-button" class="c-link s:max-w-50 align-middle" rel="noopener noreferrer"&gt;
          &lt;img alt="" src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fstatic-production.npmjs.com%2F338e4905a2684ca96e08c7780fc68412.png" height="auto" class="m-0"&gt;
        &lt;/a&gt;
      &lt;/div&gt;
    &lt;div class="c-embed__body"&gt;
      &lt;h2 class="fs-xl lh-tight"&gt;
        &lt;a href="https://www.npmjs.com/package/react-swipeable-button" rel="noopener noreferrer" class="c-link"&gt;
          react-swipeable-button - npm
        &lt;/a&gt;
      &lt;/h2&gt;
        &lt;p class="truncate-at-3"&gt;
          A component to create swipeable button in react. Latest version: 1.0.11, last published: 4 months ago. Start using react-swipeable-button in your project by running `npm i react-swipeable-button`. There are no other projects in the npm registry using react-swipeable-button.
        &lt;/p&gt;
      &lt;div class="color-secondary fs-s flex items-center"&gt;
          &lt;img alt="favicon" class="c-embed__favicon m-0 mr-2 radius-0" src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fstatic-production.npmjs.com%2Fb0f1a8318363185cc2ea6a40ac23eeb2.png"&gt;
        npmjs.com
      &lt;/div&gt;
    &lt;/div&gt;
&lt;/div&gt;



</description>
      <category>react</category>
      <category>npm</category>
      <category>frontend</category>
      <category>tutorial</category>
    </item>
  </channel>
</rss>
