1.0.13 • Published 5 months ago

giri-chat-component v1.0.13

Weekly downloads
-
License
ISC
Repository
github
Last release
5 months ago

giri-chat-component

NPM package contains a chat component which shows the sent and receives messages on the page in a sequece. and also functionallity to send the message

install Package

Using npm:

$ npm install giri-chat-component

Using yarn:

$ yarn add giri-chat-component

Once the package is installed, you can import the library using import approach:

import ChatComponent from 'giri-chat-component';

Complete code

import React, {useState} from 'react';
import ChatComponent from 'giri-chat-component';

const App = () => {
  //state for chat history updation
  const [chatHistory, setChatHistory] = useState([
    {
      type: 'RECEIVED',
      message: 'Hellow',
      timestamp: new Date(),
    },
  ]);

  //function to trigger receive message by default after 1 sec of sending the message
  const onAutoReceive = () => {
    setTimeout(() => {
      const newChat = {
        type: 'RECEIVED',
        message: 'Received message',
        timestamp: new Date(),
      };
      setChatHistory(prevHistory => [...prevHistory, newChat]);
    }, 1000);
  };

  return (
    <ChatComponent
      headerTitle={'Chating with Giri'}
      headerContainerStyle={{
        backgroundColor: 'black',
      }}
      headerTitleStyle={{
        color: 'white',
      }}
      chatHistory={chatHistory}
      onMessageSend={message => {
        const newChat = {
          type: 'SENT',
          message: message,
          timestamp: new Date(),
        };
        setChatHistory([...chatHistory, newChat]);
        onAutoReceive();
      }}
    />
  );
};

export default App;

                

Information about the Interfaces

//chatHistory
interface ChatHistoryInterface {
  type: MessageType;
  message: string;
  timestamp: Date;
}

//Chat component props

interface ChatComponentInterface {
  chatHistory: ChatHistoryInterface[];
  onMessageSend: (userMessage: string) => void;
  headerContainerStyle: StyleSheet;
  headerTitleStyle: StyleSheet;
  headerTitle: string;
}

Page screenshot

1.0.13

5 months ago

1.0.12

5 months ago

1.0.11

5 months ago

1.0.10

5 months ago

1.0.9

5 months ago

1.0.8

5 months ago

1.0.7

5 months ago

1.0.6

5 months ago

1.0.5

5 months ago

1.0.4

5 months ago

1.0.3

5 months ago

1.0.2

5 months ago

1.0.1

5 months ago

1.0.0

5 months ago