New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@carlos8a/react-whatsapp-floating-button

Package Overview
Dependencies
Maintainers
0
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@carlos8a/react-whatsapp-floating-button

A react component to add a floating whatsapp button to your project

  • 1.1.5
  • latest
  • Source
  • npm
  • Socket score

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

⚛️⚡ WhatsApp Floating Button Component for React

NPM Version npm bundle size GitHub License

WhatsApp Floating Button GIF

Description

This React component offers an elegant WhatsApp floating button, serving as a bridge to the official WhatsApp application. It simulates a WhatsApp chat interface, allowing users to initiate conversations directly from your website. Upon clicking "submit," users are redirected to WhatsApp with their message pre-filled, ready to continue the conversation. Ideal for enhancing customer support and engagement, this component simplifies the transition from web inquiries to WhatsApp communication using WhatsApp's API.

Screenshots

The WhatsApp Floating Button Component supports both light and dark modes, ensuring it can integrate seamlessly with your application's theme. Below are the mockups for each mode:

Light ModeDark Mode
Light ModeDark Mode

Toggle between the modes to provide a consistent user experience regardless of your app's theme.

Installation

Install the component using your preferred package manager:

npm

npm install @carlos8a/react-whatsapp-floating-button

pnpm

pnpm install @carlos8a/react-whatsapp-floating-button

Yarn

yarn add @carlos8a/react-whatsapp-floating-button

Usage Example

Below is a basic example demonstrating how to integrate the WhatsApp floating button into your app:

import { FloatingWhatsApp } from '@carlos8a/react-whatsapp-floating-button';

const App = () => {
  return (
    <div>
      <FloatingWhatsApp
        phoneNumber='5215540000000' // Required
        accountName='Carlos Ochoa' // Optional
        avatar='/images/avatar.webp' // Optional
        initialMessageByServer='Hi there! How can I assist you?' // Optional
        initialMessageByClient='Hello! I found your contact on your website. I would like to chat with you about...' // Optional
        statusMessage='Available' // Optional
        startChatText='Start chat with us' // Optional
        tooltipText='Need help? Click to chat!' // Optional
        allowEsc={true} // Optional
        // Explore all available props below
      />
    </div>
  );
};

export default App;

Available Props

PropTypeRequiredDescriptionDefault
phoneNumberStringYesPhone number in international format5215540000000
accountNameStringNoAccount usernameAccount Name
onClickFunctionNoCallback fired on click-
onSubmitFunctionNoCallback fired on submit with the event passed-
onCloseFunctionNoCallback fired on close-
onLoopDoneFunctionNoCallback called when notification loop is done-
onNotificationFunctionNoCallback fired when a notification is triggered-
avatarStringNoPath to change user avatar using static assetsUI Face
statusMessageStringNoText displayed below the account usernameTypically replies within 1 hour
initialMessageByServerStringNoFirst message visitors receiveHello there! How can we help?
initialMessageByClientStringNoMessage that the user will send to your WhatsAppHello!, I got your contact from your website. I would like to chat with you about...
startChatTextStringNoText displayed inside the "Start Chat" buttonStart chat with us
tooltipTextString | nullNoText that will appear in the tooltip, adjacent to the WhatsApp buttonnull
messageDelayNumberNoDelay before displaying initialMessageByServer (seconds)2
notificationBooleanNoEnables notifications (disabled after user opens the chat box)false
notificationDelayNumberNoDelay between notifications (seconds)60
notificationLoopNumberNoNumber of times notifications loop0
notificationStyleCSSPropertiesNoInline style for notification{}
notificationClassNameStringNoCSS class for notification indicatorfloating-whatsapp-notification
allowClickAwayBooleanNoAllows chat box to close when clicking outsidefalse
allowEscBooleanNoAllows chat box to close when pressing Escape keyfalse
darkModeBooleanNoEnables dark stylefalse
classNameStringNoCSS class for the main wrapping Divfloating-whatsapp
buttonClassNameStringNoCSS class for the buttonfloating-whatsapp-button
styleCSSPropertiesNoInline style for the main wrapping Div{}
buttonStyleCSSPropertiesNoInline style for the button{}
chatboxHeightNumberNoChat box height320
chatboxClassNameStringNoCSS class for the chat boxfloating-whatsapp-chatbox
chatboxStyleCSSPropertiesNoInline style for the chat box{}

Development and Testing Files

The following files are intended solely for development and testing purposes and do not form part of the component's distribution:

  • <root>/index.html (used to test the component)
  • <root>/src/**/* (excluding <root>/src/lib/**/* which is the component)
  • <root>/public/ (used to test the component)
  • <root>/preparePublish.js (prepares the component for npm publishing)

Building and Testing the Package

Note: For anyone that just want to get and use the component, the Installation and Usage Example sections have got all you need 👍🏻.

This section is for developers who want to modify the component. Follow the steps outlined below to rebuild and test your changes locally.

Prerequisites

Make sure you have Node.js (version 18 or higher) installed on your system. This project employs pnpm for efficient dependency management. If you don't have pnpm, install it with the following command:

npm install -g pnpm

Setting Up the Development Environment

  1. Clone the Repository: Get a copy of the project onto your local machine by cloning the GitHub repository.

    git clone https://github.com/CarlosUlisesOchoa/react-whatsapp-floating-button.git
    cd react-whatsapp-floating-button
    
  2. Install Dependencies: Use pnpm to install all the necessary dependencies. This ensures your environment is equipped with everything needed for building and testing the component.

    pnpm install
    

Running a Local Development Server

You will be able to modify and see real-time changes due we are using Vite to dev and deploy.

You can run:

pnpm run dev

Now you will be able to start enhancing or customizing this beautiful but always improveable component 😁.

Rebuilding the Library

Execute the following command to build the library:

pnpm run build:lib

This script performs a series of tasks:

  • Clears the dist directory for a clean build.
  • Adjusts TypeScript configurations for the build.
  • Compiles the library using Vite into the dist folder, which will contain the production-ready code.
  • Resets TypeScript configurations after the build.

That's it. Now you can take a look at the dist directory where you'll find the bundled code.

Acknowledgements

  • Special thanks to @awran5 for the react-floating-whatsapp component, which served as a base for this enhanced version.
  • Gratitude to @darwinva97 for the PR contributing improvements in accessibility and SEO through aria-hidden attribute modifications.

License

MIT License © 2024

Keywords

FAQs

Package last updated on 07 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