1.0.5 • Published 2 years ago

antiy-ui v1.0.5

Weekly downloads
-
License
ISC
Repository
-
Last release
2 years ago

Chat-React

chat component for react. 中文文档

chat-react

Demonstration

chat-react

Usage

  • Install
npm install chat-react
  • Import
import Chat from 'chat-react';
  • usage
export default class MyChat extends Component {
  state = {
    inputValue: '',
    messages: [],
    timestamp: new Date().getTime()
  }
  setInputfoucs = () => {
    this.chat.refs.input.inputFocus();  //set input foucus
  }
  setScrollTop = () => {
    this.chat.refs.message.setScrollTop(1200);  //set scrollTop position
  }
  sendMessage = (v) => {
    const {value} = v;
    if (!value) return;
    const {messages = []} = this.state;
    messages.push(v);
    this.setState({messages, timestamp: new Date().getTime(), inputValue: ''});
  }
  render() {
    const {inputValue, messages, timestamp} = this.state;
    const userInfo = {
      avatar: "http://img.binlive.cn/6.png",
      userId: "59e454ea53107d66ceb0a598",
      name: 'ricky'
    };
    return (
      <Chat
        ref={el => this.chat = el}
        className="my-chat-box"
        dataSource={messages}
        userInfo={userInfo}
        value={inputValue}
        sendMessage={this.sendMessage}
        timestamp={timestamp}
        placeholder="write some thing..."
        messageListStyle={{width: '100%', height: window.outerHeight}}
      />
    );
  }
}

API

prop & functypedescription
userInfoobjectinfo of current user
valuestringthe message of input content
placeholderstringplaceholder for input box
emojianydefine content of the emoji
customEmoticonarraycustomized emoticon
textareaChange(value) => {}callback function when the content of input box changes. the first function parameter is current input value
selectEmoje(emojeInfo) => {}callback function after select a emoje. the first function parameter is selected emoje info
inputFocusfuncmethod of input child component, set input focus. this.chat.refs.input.inputFocus()
dataSourcearraydata content of message list
messageListStyleobjectmessage list container style,you need to set a fixed size height for it.
timestampnumbertimestamp to be set when dataSource changes
timeBetweennumberhow many time between show time prompts (unit: min, default: 5)
timeagoMaxnumbertime range of the show timeago (unit: hour, default: 24)
timeFormatstringcustom format time (yyyy-MM-dd hh:mm)
loadingboolis the dataSource loading
loadernodecustom loader
noDataboolwhether has no more data
scrollOptionsobjectthis param used iscroll.js's scrollbars parameter, iscroll.js Doc.
noDataElenodecustom dom node displayed when there is no more data
scrolltoUpperfunccallback function when the scroll bar of message list to the top
onScrollfunccallback function when the scroll bar change
avatarClickfunccallback function user to click the avatar
unreadCountChangefunccallback function when the unread message has change
setScrollTopfuncmethod of message child component, set scroll bar position. this.chat.refs.message.setScrollTop(1200)
the param description of component
  • userInfo you must to be define userId and avatar for this param, and you can also add some attributes if you need.
    userInfo = {
     avatar: 'http://example/avatar.jpg', //user avatar, required parameters
     userId: '5bf7cf25a069a537ffe7c324', //user id, required parameters
     name: 'rigcky',
     other: 'otherInfo'
    }
 - `emoji` if emoji param is **false**,  not show emoji. if you want to add more emoji, you can set this param is array content.
```javascript
// add more emoji
emoji = [
  {text: 'panda', content: '🐼'},
  {text: 'tiger', content: '🐯'},
  {text: 'pig', content: '🐷'}
]
  • customEmoticon customized emoticon, it is array type of this param.
    customEmoticon = [
     {text: 'smile', url: 'http://example/emoticon.png'},
     {text: 'angry', url: 'http://example/emoticon2.png'},
     {text: 'weep', url: 'data:image/png;base64,iVBORw0KGgoA...'}
    ]
 - `dataSource` data source of message list, the data format is as follows:
```javascript
const customEmoticon = [{
    timestamp: 1545925494422,
    userInfo: {
        avatar: "http://example/2.png",
        name: "游客1544365758856",
        userId: "1544365758856"
    },
    value: "hello~"
},  {
    timestamp: 1545925534218,
    userInfo: {
        avatar: "http://example/2.png",
        name: "游客1544365758856",
        userId: "1544365758856"
    },
    value: "😀",
    error: true //set error is true, this message will be show error icon
}]
  • messageListStyle message list container style, you need to set a fixed size height for it, make sure it's not pushed up, for example {width: '100%', height: 500}
  • timestamp this parameter needs to be set to the current timestamp when the data of dataSource param has changes.
  • timeFormat formatting times, such as display 2019-2-1 20:20 set to yyyy-MM-dd hh:mm.
1.0.0

2 years ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

0.0.30

3 years ago

0.0.31

3 years ago

0.0.32

3 years ago

0.0.33

3 years ago

0.1.0

3 years ago

0.1.1

3 years ago

0.0.28

3 years ago

0.0.29

3 years ago

0.0.20

3 years ago

0.0.21

3 years ago

0.0.22

3 years ago

0.0.23

3 years ago

0.0.24

3 years ago

0.0.25

3 years ago

0.0.15

3 years ago

0.0.16

3 years ago

0.0.17

3 years ago

0.0.18

3 years ago

0.0.19

3 years ago

0.0.10

3 years ago

0.0.11

3 years ago

0.0.12

3 years ago

0.0.13

3 years ago

0.0.14

3 years ago

0.0.26

3 years ago

0.0.9

3 years ago

0.0.27

3 years ago

0.0.8

3 years ago

0.0.5

3 years ago

0.0.7

3 years ago

0.0.6

3 years ago

0.0.3

3 years ago

0.0.4

3 years ago

0.0.2

3 years ago

0.0.1

3 years ago