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-styled-chat-widget

v1.0.1

Published

Flexibly styled chat-widget for your react apps. It was mainly created for integration with chat-bot messengers.

Downloads

40

Readme

React styled chat widget

npm version

Flexibly styled chat-widget for your react apps. It was mainly created for integration with chat-bot messengers.


Technical Documentation

Installing

npm

$ npm install react-styled-chat-widget styled-components

yarn

$ yarn add react-styled-chat-widget styled-components

As you have probably already noticed, this library uses styled-components to provide a nice development experience when it comes to customizing.

If you aren't using browserify/webpack, a UMD version of react-styled-chat-widget is available. This bundle is also what is loaded when installing from npm. It expects external React and ReactDOM.


Exports

The default export is <ChatWidget/>. There are additional types that you can use as well.

import ChatWidget from "react-styled-chat-widget";
import {Message, MessageSendHandler, SendClickHandler} from "react-styled-chat-widget";

Chat Widget usage

You can take a look at the DEMO story-book I made. Don't forget to use fullscreen mode there or close other windows, because component itself relies on the screen size a lot and storybook changes it in the runtime.

import React, {useCallback, useEffect, useState} from 'react';
import ChatWidget from "react-styled-chat-widget";
import {Message, MessageSendHandler, SendClickHandler} from "react-styled-chat-widget";
import Spinner from "../components/spinner";

const App = () => {
  const [messages, setMessages] = useState<Message[]>([]);
  const [loading, setLoading] = useState(true);
  
  useEffect(() => {
    // load some messages from history here using setMessages
    setLoading(false);
  }, []);


  // used to switch message delivery indicator
  const onMessageSend = useCallback<MessageSendHandler>((currentID, setDeliveryStatus) => {
    setDeliveryStatus();
  }, []);

  // called when user presses the send button
  const onSendClick = useCallback<SendClickHandler>((message: string) => {
    setMessages((messages) => {
      return [
        ...messages,
        {id: Math.floor(Math.random() * 10000), isPrimary: true, date: new Date(), sent: true, message, author: 'You'},
      ]
    })
  }, []);


  return (
    <ChatWidget
      defaultPosition={'bottomRight'}
      messages={messages} // required
      loading={loading} // required
      onMessageSend={onMessageSend} // required
      onSendClick={onSendClick} // required
      spinner={<Spinner/>} // required
    >
      // Header of the widget should be here :)
      <div>
        <p>Welcome to support window!</p>
        <hr/>
        <p>Here you can chat directly with moderators. They usually answer in a few hours.</p>
      </div>
    </ChatWidget>
  );
}

export default App;

Tiny Warning

It's my first ui component released on NPM. So, you may experience some bugs during development even though I didn't find any by myself :)


Chat Widget API

Below you will find all the properties that chat widget accepts. Pay attention to the ones that are marked as required! Without them widget won't work!

| Property | Type | Required | Default | Example/Description | |----------|--------|----------|---------|----------------------| | indent | number | no | window.innerWidth * 0.015 | Indent from screen borders for the button that opens widget | | size | number | no | window.innerWidth * 3 / 100 | Size of the opening button. Percent of the screen width | | minSize | number | no | 60 | Minimal size of the opening button. Specified in pixels | | mainContentWidth | number | no | 25 | Width of the whole widget specified in percents of it's corresponding property - screen Width | | mainContentHeight | number | no | 60 | Height of the whole widget specified in percents of it's corresponding property - screen Height | | chatOffset | number | no | 10 | When widget is opened, there is a space between it and button. | | messages | Messages[] | yes | - | Messages that should be passed according to Messages[] type | | loading | boolean | yes | - | When loading is true the spinner is shown | | onMessageSend | MessageSendHandler | yes | - | Interesting option. This function gets invoked when message appears on the screen, but let's say "has not been saved in your db yet". So, calling setDeliveryStatus which comes as a second argument you are able to toggle "delivery check mark" on.| | onSendClick | SendClickHandler | yes | - | Event handler that gets invoked when user smashes send button | | primary| color code | no | gray | Sets background color of widget | | secondary | color code | no | purple | Color of the stroke at the top of textarea | | defaultPosition | "topLeft" "topRight" "bottomLeft" "bottomRight" | no | "bottomRight" | Default position of the chat opening button | | isDraggable | boolean | no | true | Here it comes, draggable chat opening button. Yes, chat widget is draggable by it's button. You can turn it off by setting this property to false, otherwise users will play with this widget forever. Is it cool or not, idk, you decide :) | | spinner | JSX.Element | yes | - | Component that is shown while loading option is true | | primaryAuthorNameColor | color code | no | white | Author thumb color of sender | | secondaryAuthorNameColor | color code | no | black | Author thumb color of "moderator" | | primaryMessageBackground | color code | no | purple | BG of sender's messages | | secondaryMessageBackground | color code | no | white | BG of moderator's messages | | primaryMessageTextColor | color code | no | white | Text color for sender | | secondaryMessageTextColor | color code | no | black | Text color for moderator | | buttonBackground | color code | no | purple | BG of the opening button | | buttonTextColor | color code | no | white | Text color of the opening button | | placeHolder | string | no | What can I help you with? | Textarea placeholder | | greeting | string | no | Feel free to ask anything you want to! | Placeholder in case messages property is an empty array! | | sendButton | JSX.Element | no | Cool icon there | You can replace send button to your own component. All the event handlers will be binded automatically | | backgroundClassName | string | no | - | You can assign your custom classname in case you want to customize bg | | inputContainerClassName | string | no | - | Textarea container classname for customization | | buttonClassName | string | no | - | Opening button classname for customization purposes |

License

MIT