npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-whatsapp-button-floating

v1.0.3

Published

A TypeScript library for creating a customizable WhatsApp floating chat button in React.

Downloads

210

Readme

React WhatsApp Floating Button TypeScript Component

demo.gif

Overview

The React WhatsApp Floating Button is a customizable React component designed to provide an interactive floating chat button. It features a pop-up chat interface with dynamic messages, customizable appearance, and a list of contacts that can be expanded using an accordion.

Key Features

  • Customizable button text, icons, and colors
  • Dynamic typewriter effect for chat messages
  • Expandable contact list with an accordion
  • Configurable button size and position

Installation

To use the React WhatsApp Floating Button, ensure you have the following peer dependencies installed:

yarn add react react-dom

Then, install the component:

yarn add react-whatsapp-button-floating

Usage

Basic Setup

Here’s an example of how to use the React WhatsApp Floating Button in a Vite React project:

import React from "react";
import WhatsappFloatingButton from "react-whatsapp-button-floating";
import SendIcon from "@mui/icons-material/Send";
import WhatsappIcon from "@/assets/icon/whatsapp.svg";

const dataList = [
    {
        label: 'Customer Service',
        contact: [
            { name: 'Aldera Bin Riza', number: '08123456789' },
            { name: 'Ayub Bin Faz', number: '08123456789' }
        ]
    },
    {
        label: 'Product Manager',
        contact: [
            { name: 'Kai bin Faz', number: '08123456789' },
            { name: 'Ayub Bin Faz', number: '08123456789' }
        ]
    },
    {
        label: 'Product Support',
        contact: [
            { name: 'Kai bin Faz', number: '08123456789' },
            { name: 'Ayub Bin Faz', number: '08123456789' }
        ]
    }
];

const text = ['Hi there 👋', 'How can we help you?'];

export const ExampleView = () => {
    return (
        <div>
            <WhatsappFloatingButton
                buttonText="Help"
                textsChat={text}
                speedTyping={100}
                sendIcon={<SendIcon alt="Send" className="w-4 h-4 hover:opacity-80"/>}
                buttonIcon={<WhatsappIcon alt="WhatsApp" className="w-full h-full hover:opacity-80"/>}
                buttonPosition={{ bottom: 24, right: 24 }}
                paperBorderRadius="8px"
                paperBackgroundColor="#f9f9f9"
                buttonBackgroundColor="#0E5BF0"
                buttonColor="#f9f9f9"
                dataList={dataList}
            />
        </div>
    );
}

Props

The WhatsappFloatingButton component accepts the following props:

| Prop Name | Type | Default Value | Description | |--------------------------|-------------------------------------------|------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------| | buttonText | string | 'Chat' | The text displayed inside the floating button if no buttonIcon is provided. | | buttonIcon | ReactNode | null | A React node (e.g., an icon) to display inside the button. If provided, it will override the buttonText. | | sendIcon | ReactNode | null | A React node (e.g., an icon) to display next to each contact option in the accordion list. | | buttonPosition | { bottom: number; right: number; } | { bottom: 16, right: 16 } | Position of the button on the screen (distance from the bottom and right edges). | | paperBackgroundColor | string | '#ffffff' | Background color of the chat interface (pop-up window). | | buttonBackgroundColor | string | '#0E5BF0' | Background color of the floating button. | | buttonColor | string | '#0E5BF0' | Text color of the floating button. | | paperBorderRadius | string | '12px' | Border radius of the chat interface (pop-up window). | | buttonSize | number | 56 | Diameter of the floating button (in pixels). | | dataList | DataInterface[] | [] | Array of data objects for the accordion, where each object contains a label and a list of contacts. | | textsChat | string[] | ["How we can help you?", "Give me a question"] | Array of strings to display as typewriter messages in the chat. | | speedTyping | number | 100 | Typing speed for the typewriter effect (in milliseconds per character). | | title | string | 'Chat with us' | Title displayed at the top of the chat interface (pop-up window). |

Example Breakdown

  1. buttonText: If no buttonIcon is provided, this text is shown in the button. The default is "Chat".

  2. buttonIcon: If you prefer to use an icon, pass it as a ReactNode. This overrides buttonText.

  3. sendIcon: You can add an icon next to each contact in the accordion list using this prop.

  4. buttonPosition: Define the position of the button relative to the screen’s bottom and right edges. By default, it's positioned 16 pixels from both edges.

  5. paperBackgroundColor & paperBorderRadius: Customize the appearance of the chat interface, including its background color and border radius.

  6. buttonBackgroundColor, buttonColor, and buttonSize: These props allow you to customize the button's background color, text color, and size.

  7. dataList: This is an array of objects, each containing a label and a contact array. The contacts are displayed in an accordion format, allowing users to expand and view contact information.

  8. textsChat: An array of strings that are displayed sequentially in the chat window using a typewriter effect. Customize the messages to suit your needs.

  9. speedTyping: Adjust the typing speed of the typewriter effect. The default is set to 100ms per character.

  10. title: Sets the title of the chat interface.

Additional Customization

Styling

The WhatsappFloatingButton component uses inline styles to provide basic customization options. However, if you need more extensive customization, you can override these styles with custom CSS or extend the component.

Accordion Component

The Accordion component used within WhatsappFloatingButton is designed to display contact lists. It receives the following props:

  • bgColor: Background color of the accordion header.
  • textColor: Text color of the accordion header.
  • dataList: The same dataList prop passed to WhatsappFloatingButton containing labels and contacts.
  • sendIcon: The icon displayed next to each contact.

Typewriter Component

The Typewriter component handles the dynamic display of text within the chat interface. It takes in the following props:

  • text: The string to display.
  • onComplete: A callback function triggered after the typing animation is complete.
  • speed: The typing speed (ms per character).

Conclusion

The React WhatsApp Floating Button is a versatile and highly customizable tool for integrating a floating chat button into your React applications. It can be styled and configured to meet various design needs and provides a dynamic user experience with its typewriter effect and expandable contact list. Use it to enhance your website’s interactivity and improve customer engagement.