1.0.1 • Published 6 years ago

react-chat-awesome v1.0.1

Weekly downloads
2
License
MIT
Repository
github
Last release
6 years ago

react-chat-awesome

Fully configurable and customizable chat component for your React applications.

Advantages

  • 100% Customizable
  • Props for styles customization
  • Lightweight (only react and prop-types as deps)
  • Message validation included
  • Backend agnostic
  • In active development

Comming in new versions:

  • emoji picker
  • sending files and images

Demo Coming soon...

Table of Contents

Installation

The package can be installed via NPM:

npm install react-chat-awesome --save

Or YARN:

yarn add react-chat-awesome --save

Example

import React, { Component } from 'react'
import { ChatAwesome } from 'react-chat-awesome'

export default class App extends Component {
  constructor(props) {
    super(props);

    this.state = {
      history: []
    }

    this.sender = { id: 1 };
    this.receiver = { id: 2, imageUrl: 'path/to/source' };

    this.onSendMessageClick = this.onSendMessageClick.bind(this);
  }

  onSendMessageClick(msgText) {
    this.setState({ history: [...this.state.history, {
      id: +new Date(),
      msg: {
        type: 'text',
        text: msgText
      },
      userID: this.sender.id
    }]})
  }

  render() {
    return (
      <div>
        <ChatAwesome
          history={ this.state.history }
          sender={ this.sender }
          receiver={ this.receiver }
          onSendMessageClick={ this.onSendMessageClick }
        />
      </div>
    );
  }
}

API

ChatAwesome is the only component you need to import. * - required prop

ChatAwesome props:

proptypedescription
*senderobjectperson who interacts with the UI and types the message.
*receiverobjectperson who receives the messages and send responses to sender
historymessage[]array of messages
onSendMessageClickfunctioncallback function, executes when user send the message
onMessageChangefunctioncallback function, executes when user type something
onChatClosefunctioncallback on close button click
onChatOpenfunctioncallback on open button click
isOpenbooleanprogramatically close/open chat (default false)
showReceiverImageOnMessagebooleanset if image should be displayed near each receiver message
sendMessageIconstringurl for alternative icon
wrapperStylesobject
headerStylesobjectstyles for chat header
sendButtonStylesobjectstyles for send button(not icon)
bodyStylesobjectstyles for messages wrapper
footerStylesobjectstyles for wrapper of the input field and chat button
inputStylesobjectstyles for input field
closedChatStylesobjectstyles for closed chat button
headerNameStylesobjectstyles for receiver name at the header

Interfaces

Sender

{
  id: number | string; // required
}

Receiver

{
  id: number | string; // required 
  imageUrl: string;
}

Message

{
  id: number | string;
  userID: number | string;
  msg: {
    type: string;
    text: string;
  }
}