Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v3.0 #172

Merged
merged 29 commits into from
Apr 17, 2020
Merged

v3.0 #172

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
4eb0ec3
Start v3.0
Mar 6, 2020
75cdd15
Merge branch '3.0' into react-update
Mar 6, 2020
c7dafee
- Add inital v1 Context configuration
Mar 16, 2020
c5003be
start redux store migration to TypeScript and migrate first components
Mar 20, 2020
d2194d1
delete unused context config
Mar 27, 2020
e9c8f66
Merge pull request #159 from Wolox/ts-redux
Mar 27, 2020
a8b969b
start typescript migration
Mar 31, 2020
213c6cb
- migrate all the components to typescript
Apr 2, 2020
1cf2853
- remove unnecessary packages for prop types and immutable
Apr 3, 2020
159f875
- change launcher on toggle function types
Apr 3, 2020
241d0c9
remove console log
Apr 3, 2020
04d2953
Merge pull request #163 from Wolox/ts-migration
Apr 3, 2020
e81dde1
bump version to 3.0
Apr 3, 2020
1e14526
- Add messages deletion
Apr 5, 2020
f66ea9d
New features
Apr 8, 2020
8d555a0
- add accesibility features according to #120
Apr 9, 2020
7e17444
- add missing id parameter for the dispatcher
Apr 13, 2020
ca7d977
Update Docs
Apr 13, 2020
841d3ce
- change action types return
Apr 13, 2020
d1feb13
add dependency on useEffect in Messages component
Apr 14, 2020
4705a23
Merge pull request #168 from Wolox/prs-features-refactor
Apr 14, 2020
9a88459
add types definitions for the exported functions and component
Apr 14, 2020
1459f46
add optional mark in handleQuickButton prop
Apr 15, 2020
26f6fe8
Update README.md
Apr 15, 2020
f247e99
Update README.md
Apr 15, 2020
404e07d
Update README.md
Apr 15, 2020
9a7b4de
add missing const in readme
Apr 15, 2020
5dd5677
Merge branch 'update-docs' of github.com:Wolox/react-chat-widget into…
Apr 15, 2020
8076feb
Merge pull request #169 from Wolox/update-docs
Apr 15, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
{
"presets": [
["env", {
["@babel/preset-env", {
"targets": {
"browsers": ["last 2 versions", "safari >= 7"]
}
}],
"react"
"@babel/preset-react",
"@babel/preset-typescript"
],
"plugins": [
"transform-class-properties",
"@babel/plugin-proposal-class-properties",
"@babel/plugin-proposal-object-rest-spread",
["module-resolver", {
"root": ["./src"],
"alias": {
"@config": "./src/config",
"@constants": "./src/constants.js",
"@assets": "./assets",
"@tests-mocks": "./mocks",
Expand Down
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
lib
dev
webpack.config*
9 changes: 7 additions & 2 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
/src
/dev
index.js
yarn.lock

assets

mocks
coverage

circle.yml
.babelrc
.eslintrc.js
.eslintignore
webpack.config.js
webpack.config*

package-lock.json
yarn.lock
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (c) 2017 Martín Callegari <[email protected]>
Copyright (c) 2020 Martín Callegari <[email protected]>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
172 changes: 99 additions & 73 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,19 +52,17 @@ yarn add react-chat-widget
1- Add the Widget component to your root component

```js
import React, { Component } from 'react';
import React from 'react';
import { Widget } from 'react-chat-widget';

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

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

export default App;
Expand All @@ -73,26 +71,24 @@ export default App;
2- The only required prop you need to use is the `handleNewUserMessage`, which will receive the input from the user.

```js
import React, { Component } from 'react';
import React from 'react';
import { Widget } from 'react-chat-widget';

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

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

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

export default App;
Expand All @@ -101,31 +97,29 @@ export default App;
3- Import the methods for you to add messages in the Widget. (See [messages](#messages))

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

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

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

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

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

export default App;
Expand All @@ -134,28 +128,28 @@ 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

```js
import React, { Component } from 'react';
import React from 'react';
import { Widget, addResponseMessage, addLinkSnippet, addUserMessage } from 'react-chat-widget';

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

import logo from './logo.svg';

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

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

render() {
return (
<div className="App">
<Widget
handleNewUserMessage={this.handleNewUserMessage}
handleNewUserMessage={handleNewUserMessage}
profileAvatar={logo}
title="My new awesome title"
subtitle="And my cool subtitle"
Expand All @@ -172,20 +166,25 @@ export default App;

#### Props

| |type|required|default value|description|
|prop|type|required|default value|description|
|---|--- |--- |--- |--- |
|**handleNewUserMessage**|PropTypes.func|YES| |Function to handle the user input, will receive the full text message when submitted|
|**title**|PropTypes.string|NO|'Welcome'|Title of the widget|
|**subtitle**|PropTypes.string|NO|'This is your chat subtitle'|Subtitle of the widget|
|**senderPlaceHolder**|PropTypes.string|NO|'Type a message...'|The placeholder of the message input|
|**profileAvatar**|PropTypes.string|NO| |The profile image that will be set on the responses|
|**titleAvatar**|PropTypes.string|NO| |The picture image that will be shown next to the chat title|
|**showCloseButton**|PropTypes.bool|NO|false|Show or hide the close button in full screen mode|
|**fullScreenMode**|PropTypes.bool|NO|false|Allow the use of full screen in full desktop mode|
|**badge**|PropTypes.number|NO|0|Display a notification badge on the launcher if the value is greater than 0|
|**autofocus**|PropTypes.bool|NO|true|Autofocus or not the user input|
|**launcher**|PropTypes.func|NO||Custom Launcher component to use instead of the default|
|**handleQuickButtonClicked**|PropTypes.func|NO||Function to handle the user clicking a quick button, will receive the 'value' when clicked.|
|**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|
|**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|
|**launcherOpenLabel**|string|NO|'Open chat'|Alt value for the laucher when closed|
|**launcherCloseLabel**|string|NO|'Close chat'|Alt value for the laucher when open|
|**sendButtonAlt**|string|NO|'Send'|Send button alt for a11y purposes|
|**handleTextInputChange**|(event) => any|NO| |Prop that triggers on input change|

#### Styles

Expand All @@ -207,22 +206,24 @@ That way, you can leave the JS clean and keep the styles within the CSS.

#### Messages

If you want to add new messages, you can use the following methods:
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
- text: string
- id: string (optional)
- Method to add a new message written as a response to a user input.

- **addUserMessage**
- params:
- text
- text: string
- 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. For now, you need to provide this method with a link object, which must be in the shape of:
- Method to add a link snippet. You need to provide this method with a link object, which must be in the shape of:
```js
{
title: 'My awesome link',
Expand All @@ -238,11 +239,12 @@ If you want to add new messages, you can use the following methods:
- 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 inse 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 the responses and user messages.**
**Markdown is supported for both the responses and user messages.**

#### Widget behavior

Expand All @@ -256,26 +258,50 @@ You can also control certain actions of the widget:
- 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 like:
You can use a custom component for the Launcher if you need one that's not the default, simply use the **launcher** prop:

```js
launcher={handleToggle => this.getCustomLauncher(handleToggle)}
```
import React from 'react';
import { Wdiget } from 'react-chat-widget';

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

For example, if you want to use a simple button to toggle the widget:
function MyApp() {
const getCustomLaucher = (handleToggle) =>
<button onClick={handleToggle}>This is my launcher component!</button>

```js
launcher={handleToggle => (
<button onClick={handleToggle}>Toggle</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](https://github.com/mcallegari10) and it was written by [Wolox](http://www.wolox.com.ar).
Expand Down
4 changes: 4 additions & 0 deletions custom.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
declare module "*.svg" {
const content: any;
export default content;
}
11 changes: 6 additions & 5 deletions dev/App.js → dev/App.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
import React, { Component } from 'react';
import { Widget, addResponseMessage, setQuickButtons, toggleMsgLoader } from '../index';

import { Widget, addResponseMessage, setQuickButtons, toggleMsgLoader, addLinkSnippet } from '../index';

export default class App extends Component {
componentDidMount() {
addResponseMessage('Welcome to this awesome chat!');
addLinkSnippet({ link: 'https://google.com', title: 'Google' });
}

handleNewUserMessage = (newMessage) => {
handleNewUserMessage = (newMessage: any) => {
toggleMsgLoader();
setTimeout(() => {
toggleMsgLoader();
toggleMsgLoader();
if (newMessage === 'fruits') {
setQuickButtons([ { label: 'Apple', value: 'apple' }, { label: 'Orange', value: 'orange' }, { label: 'Pear', value: 'pear' }, { label: 'Banana', value: 'banana' } ]);
} else {
Expand All @@ -18,7 +20,7 @@ export default class App extends Component {
}, 2000);
}

handleQuickButtonClicked = (e) => {
handleQuickButtonClicked = (e: any) => {
addResponseMessage('Selected ' + e);
setQuickButtons([]);
}
Expand All @@ -31,7 +33,6 @@ export default class App extends Component {
senderPlaceHolder="Escribe aquí ..."
handleNewUserMessage={this.handleNewUserMessage}
handleQuickButtonClicked={this.handleQuickButtonClicked}
badge={1}
/>
);
}
Expand Down
4 changes: 2 additions & 2 deletions dev/main.js → dev/main.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import ReactDOM from 'react-dom';
import * as React from 'react';
import * as ReactDOM from 'react-dom';

import App from './App';

Expand Down
Loading