• Stars
    star
    1,406
  • Rank 32,165 (Top 0.7 %)
  • Language
    TypeScript
  • License
    MIT License
  • Created almost 7 years ago
  • Updated 4 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Awesome chat widget for your React App

React Chat Widget

circle-ci npm

FEArmy

Features

  • Plain text message UI
  • Snippet style for links (only as responses for now)
  • Fully customizable
  • Easy to use

demonstration

Installation

npm

npm install --save react-chat-widget

yarn

yarn add react-chat-widget

Usage

1- Add the Widget component to your root component

import React from 'react';
import { Widget } from 'react-chat-widget';

import 'react-chat-widget/lib/styles.css';

function App() {
  return (
    <div className="App">
      <Widget />
    </div>
  );
}

export default App;

2- The only required prop you need to use is the handleNewUserMessage, which will receive the input from the user.

import React from 'react';
import { Widget } from 'react-chat-widget';

import 'react-chat-widget/lib/styles.css';

function App() {
  const handleNewUserMessage = (newMessage) => {
    console.log(`New message incoming! ${newMessage}`);
    // Now send the message throught the backend API
  };

  return (
    <div className="App">
      <Widget
        handleNewUserMessage={handleNewUserMessage}
      />
    </div>
  );
}

export default App;

3- Import the methods for you to add messages in the Widget. (See messages)

import React from 'react';
import { Widget, addResponseMessage } from 'react-chat-widget';

import 'react-chat-widget/lib/styles.css';

function App() {
  useEffect(() => {
    addResponseMessage('Welcome to this awesome chat!');
  }, []);

  const handleNewUserMessage = (newMessage) => {
    console.log(`New message incoming! ${newMessage}`);
    // Now send the message throught the backend API
    addResponseMessage(response);
  };

  return (
    <div className="App">
      <Widget
        handleNewUserMessage={handleNewUserMessage}
      />
    </div>
  );
}

export default App;

4- Customize the widget to match your app design! You can add both props to manage the title of the widget and the avatar it will use. Of course, feel free to change the styles the widget will have in the CSS

import React, { useEffect } from 'react';
import { Widget, addResponseMessage } from 'react-chat-widget';

import 'react-chat-widget/lib/styles.css';

import logo from './logo.svg';

function App() {
  useEffect(() => {
    addResponseMessage('Welcome to this **awesome** chat!');
  }, []);

  const handleNewUserMessage = (newMessage) => {
    console.log(`New message incoming! ${newMessage}`);
    // Now send the message throught the backend API
  };

    return (
      <div className="App">
        <Widget
          handleNewUserMessage={handleNewUserMessage}
          profileAvatar={logo}
          title="My new awesome title"
          subtitle="And my cool subtitle"
        />
      </div>
    );
}

export default App;

API

Props

prop type required default value description
handleNewUserMessage (...args: any[]) => any YES Function to handle the user input, will receive the full text message when submitted
title string NO 'Welcome' Title of the widget
subtitle string NO 'This is your chat subtitle' Subtitle of the widget
senderPlaceHolder string NO 'Type a message...' The placeholder of the message input
profileAvatar string NO The profile image that will be set on the responses
profileClientAvatar string NO The profile image that will be set on the client messages
titleAvatar string NO The picture image that will be shown next to the chat title
showCloseButton boolean NO false Show or hide the close button in full screen mode
fullScreenMode boolean NO false Allow the use of full screen in full desktop mode
autofocus boolean NO true Autofocus or not the user input
launcher (handleToggle) => ElementType NO Custom Launcher component to use instead of the default
handleQuickButtonClicked (...args: any[]) => any NO Function to handle the user clicking a quick button, will receive the 'value' when clicked.
showTimeStamp boolean NO true Show time stamp on messages
chatId string NO 'rcw-chat-container' Chat container id for a11y
handleToggle (...args: any[]) => any NO 'rcw-chat-container' Function to handle when the widget is toggled, will receive the toggle status
launcherOpenLabel string NO 'Open chat' Alt value for the laucher when closed
launcherCloseLabel string NO 'Close chat' Alt value for the laucher when open
launcherOpenImg string NO '' local or remote image url, if not provided it will show default image
launcherCloseImg string NO '' local or remote image url, if not provided it will show default image
sendButtonAlt string NO 'Send' Send button alt for a11y purposes
handleTextInputChange (event) => any NO Prop that triggers on input change
handleSubmit (event) => any NO Prop that triggers when a message is submitted, used for custom validation
resizable boolean NO false Prop that allows to resize the widget by dragging it's left border
emojis boolean NO false enable emoji picker
showBadge boolean NO true Prop that allows to show or hide the unread message badge

Styles

To change the styles you need the widget to have, simply override the CSS classes wrapping them within the containers and add your own style to them! All classes are prefixed with rcw- so they don't override your other classes in case you are not hasing them. To override, you can do, for expample:

.rcw-conversation-container > .rcw-header {
  background-color: red;
}

.rcw-message > .rcw-response {
  background-color: black;
  color: white;
}

That way, you can leave the JS clean and keep the styles within the CSS.

Messages

As of v3.0, messages now have an optional ID that can be added on creation.If you want to add new messages, you can use the following methods:

  • addResponseMessage

    • params:
      • text: string (supports markdown)
      • id: string (optional)
    • Method to add a new message written as a response to a user input.
  • addUserMessage

    • params:
      • text: string (supports markdown)
      • id: string (optional)
    • This method will add a new message written as a user. Keep in mind it will not trigger the prop handleNewUserMessage()
  • addLinkSnippet

    • params:
      • link
    • Method to add a link snippet. You need to provide this method with a link object, which must be in the shape of:
      {
        title: 'My awesome link',
        link: 'https://github.com/Wolox/react-chat-widget',
        target: '_blank'
      }
    • By default, target value is _blank which will open the link in a new window.
  • renderCustomComponent

    • params:
      • component: Component to be render,
      • props: props the component needs,
      • showAvatar: boolean, default value: false; the component will be rendered with the avatar like the messages
    • Method to render a custom component inside the messages container. With this method, you can add whatever component you need the widget to have.
  • setQuickButtons

    • params:
      • buttons: An array of objects with the keys label and value

Markdown is supported for both the responses and user messages.

Widget behavior

You can also control certain actions of the widget:

  • toggleWidget

    • params: No params expected
    • This method is to toggle the widget at will without the need to trigger the click event on the launcher
  • toggleInputDisabled

    • params: No params expected
    • Method to toggle the availability of the message input for the user to write on
  • toggleMsgLoader

    • Toggles the message loader that shows as a "typing..." style.
  • deleteMessages*

    • params:
      • count: messages to delete counting from last to first
      • id: message id to delete
    • Delete messages that either have an id you previously set with the addResponseMessage or delete based on position or both of them. For example deleteMessages(2, 'myId') will delete the message that has the id myId and the previous message.
  • markAllAsRead

    • Marks all response messages as read. The user messages doesn't have the read/unread property.
  • setBadgeCount

    • params:
      • count: number
    • As of v3.0, the badge prop is being changed to be managed from within the Widget. This method is manually set the badge number.

Widget components

Custom Launcher

You can use a custom component for the Launcher if you need one that's not the default, simply use the launcher prop:

import React from 'react';
import { Widget } from 'react-chat-widget';

...

function MyApp() {
  const getCustomLauncher = (handleToggle) =>
    <button onClick={handleToggle}>This is my launcher component!</button>

  return (
    <Widget
      ...
      launcher={handleToggle => getCustomLauncher(handleToggle)}
    />
  )
}

getCustomLauncher() is a method that will return the Launcher component as seen in the example. By default, the function passed by that prop, will receive the handleToggle parameter which is the method that will toggle the widget.

About

This project is maintained by Martín Callegari and it was written by Wolox.

Wolox

More Repositories

1

wolox-ci

Groovy
198
star
2

carthage_cache

A tool that allows to cache Carthage/Build folder in Amazon S3.
Ruby
174
star
3

tech-guides

Guides and standards for the techs we love using at Wolox
Shell
146
star
4

express-js-bootstrap

Kickoff for ExpressJS applications.
JavaScript
77
star
5

redux-recompose

A Redux utility belt for reducers and actions. Inspired by acdlite/recompose.
JavaScript
70
star
6

wor-authentication

Gem to add authentication to your application using JWT, with expirable, renewable and customizable tokens!
Ruby
62
star
7

async-requests

Ruby
57
star
8

ReactiveArray

An array class implemented in Swift that can be observed using ReactiveCocoa's Signals
Swift
53
star
9

dictum

Create automatic documentation of your Rails API endpoints through your tests
Ruby
53
star
10

firestore-service

JavaScript
28
star
11

ios-style-guide

Wolox's iOS style guide
26
star
12

WLXBluetoothDevice

A block-based wrapper of CoreBluetooth
Objective-C
26
star
13

frontend-bootstrap

JavaScript
24
star
14

react-bootstrap

JavaScript
23
star
15

dictum.js

Create automatic documentation of your NodeJS API endpoints
JavaScript
23
star
16

wor-paginate

Ruby
22
star
17

wolmo-bootstrap-react-native

Bootstrap generator for React Native projects
JavaScript
20
star
18

wolmo-core-ios

Wolmo - Wolox Mobile SDK core library for iOS
Swift
17
star
19

wor-push-notifications-aws

Ruby
16
star
20

wor-prof

Wor-prof (Wprof) is a gem for Ruby On Rails which its only purpose is to measure a RoR app's performance through a profile with different times of response.
Ruby
15
star
21

arg-localities

Get localities by province for Argentina
Shell
13
star
22

wor-requests

Make external requests in you service objects, with easy logging and error handling!
Ruby
12
star
23

aws-deploy-script-frontend

JavaScript
12
star
24

frontend-cookbook

Reusable components and features design and created by Wolox
TypeScript
11
star
25

rails-bootstrap

A Ruby on Rails base project with Wolox standard defaults
Ruby
11
star
26

wolmo-cookbook-android

Wolmo Cookbook - Recipes for common cases done with Wolmo
Kotlin
9
star
27

fictium

A gem with the power to generate documentation from your tests
Ruby
9
star
28

WLXWebViewReloader

An extension to WKWebView that reloads the web view when the source changes.
Objective-C
8
star
29

react-native-renavigate

React native navigation made easy using redux 💫
JavaScript
8
star
30

codestats

Self-hosted open source app to control metrics of your code
Ruby
7
star
31

wolmo-core-android

Wolmo Core - Wolox Mobile SDK core module for Android
Kotlin
7
star
32

express-wolox-logger

JavaScript
6
star
33

terraform-base-infra

HCL
6
star
34

netcore-bootstrap

Kickoff for NetCore applications using EntityFramework.
C#
6
star
35

node-typescript-bootstrap

TypeScript
6
star
36

ios-base-project

A base iOS project with all the minimum dependencies already configured.
Swift
6
star
37

project-health-checker

JavaScript
5
star
38

assigner

A script to pick a random reviewer and assign it to a pull request
Ruby
5
star
39

equalizer

CSS
5
star
40

wor-batchifier

Ruby
5
star
41

angular-bootstrap

TypeScript
4
star
42

warp

WARP - Seamless mobile assets management
Python
4
star
43

eslint-config-wolox-node

JavaScript
4
star
44

wolmo-reactive-core-ios

Swift
4
star
45

eslint-config-wolox-react

JavaScript
3
star
46

cookbook-ios

Swift
3
star
47

cypress-bootstrap

TypeScript
3
star
48

eslint-config-wolox

Wolox eslint standard
JavaScript
3
star
49

wolmo-networking-android

Wolmo Networking - Wolox Mobile SDK networking module for Android
Java
3
star
50

collection-view-example

An iOS project that shows how to use UICollectionView to make re-utilizable components. It also shows how to structure an app using the MVVM pattern.
Objective-C
2
star
51

java-bootstrap

Java
2
star
52

wolmo-maps-android

Wolmo Maps - Wolox Mobile SDK maps module for Android
Java
2
star
53

wolmo-testing-android

Kotlin
2
star
54

node-graphql-bootstrap

JavaScript
2
star
55

elasticsearch-rails-demo

Ruby
2
star
56

automation-test-angular

TypeScript
2
star
57

aws-lambdas-bootstrap

JavaScript
2
star
58

WoloxAndroidBootstrap

Wolox's base template for new Android projects.
Kotlin
2
star
59

android-bootstrap-mvvm

Kotlin
2
star
60

github-organization-manager-react

CSS
2
star
61

simple-crud

Ruby
2
star
62

fastlane-mobile

Ruby
2
star
63

wdio-appium-bootstrap

JavaScript
2
star
64

localization-culture-core

This project allows localization for NetCore using .json files instead of .resx.
C#
2
star
65

silk-paper-node

JavaScript
1
star
66

jira-training-cloner-rails

Ruby
1
star
67

java-meetup-2019

Java
1
star
68

graphql-inspector-wolox-node

JavaScript
1
star
69

react-app-rewire-wolox

JavaScript
1
star
70

react-conduit

Ruby
1
star
71

angularjs-bootstrap

JavaScript
1
star
72

eslint-config-wolox-react-native

JavaScript
1
star
73

layout

SCSS
1
star
74

github-organization-manager

project to manage github repos
JavaScript
1
star
75

infrastructure-provisioning

HTML
1
star
76

angular-conduit

TypeScript
1
star
77

wolox-frontend-templates

HTML
1
star
78

github-organization-manager-node

JavaScript
1
star
79

express-wolox-schema-validator-node

JavaScript
1
star
80

python-bootstrap

1
star