Skip to content

Commit 7fcce4e

Browse files
ReplyMessage feature added.
1 parent 7f47e00 commit 7fcce4e

6 files changed

Lines changed: 172 additions & 0 deletions

File tree

README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,27 @@ import { MessageBox } from 'react-chat-elements'
149149
| copiableDate | false | boolean | message box date text copiable |
150150
| focus | false | boolean | used in message focus feature in MessageList component, makes style of the component focused |
151151
| onMessageFocused | none | function | makes focus value false after the message becomes focus |
152+
| reply | none | object | reply data |
153+
154+
## Reply Message Component
155+
156+
```javascript
157+
import { MessageBox } from 'react-chat-elements'
158+
159+
<MessageBox
160+
reply={{
161+
photoURL: 'https://facebook.github.io/react/img/logo.svg',
162+
title: 'elit magna',
163+
titleColor: '#8717ae',
164+
message: 'Aliqua amet incididunt id nostrud',
165+
}}
166+
onReplyMessageClick={() => console.log('reply clicked!')}
167+
position={'left'}
168+
type={'text'}
169+
text={'Tempor duis do voluptate enim duis velit veniam aute ullamco dolore duis irure.'}/>
170+
```
171+
172+
![reply-message](https://user-images.githubusercontent.com/15075759/80224625-9dbbeb00-8652-11ea-994f-022be0cffe30.png)
152173

153174

154175
## SystemMessage Component

example/App.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,12 @@ export class App extends Component {
9595
return {
9696
position: (this.token() >= 1 ? 'right' : 'left'),
9797
forwarded: true,
98+
reply: this.token() >= 1 ? ({
99+
photoURL: this.token() >= 1 ? `data:image/png;base64,${this.photo(150)}` : null,
100+
title: loremIpsum({ count: 2, units: 'words' }),
101+
titleColor: this.getRandomColor(),
102+
message: loremIpsum({ count: 1, units: 'sentences' }),
103+
}) : null,
98104
type: type,
99105
theme: 'white',
100106
view: 'list',
@@ -119,6 +125,9 @@ export class App extends Component {
119125
},
120126
status: status,
121127
date: +new Date(),
128+
onReplyMessageClick: () => {
129+
console.log('onReplyMessageClick');
130+
},
122131
avatar: `data:image/png;base64,${this.photo()}`,
123132
};
124133
case 'chat':

src/MessageBox/MessageBox.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import FileMessage from '../FileMessage/FileMessage';
66
import SystemMessage from '../SystemMessage/SystemMessage';
77
import LocationMessage from '../LocationMessage/LocationMessage';
88
import SpotifyMessage from '../SpotifyMessage/SpotifyMessage';
9+
import ReplyMessage from '../ReplyMessage/ReplyMessage';
910

1011
import Avatar from '../Avatar/Avatar';
1112

@@ -103,6 +104,16 @@ export class MessageBox extends Component {
103104
</div>
104105
}
105106

107+
{
108+
this.props.reply &&
109+
<ReplyMessage
110+
photoURL={this.props.reply.photoURL}
111+
title={this.props.reply.title}
112+
titleColor={this.props.reply.titleColor}
113+
message={this.props.reply.message}
114+
onClick={this.props.onReplyMessageClick}/>
115+
}
116+
106117
{
107118
this.props.type === 'text' &&
108119
<div className="rce-mbox-text">
@@ -242,6 +253,7 @@ MessageBox.defaultProps = {
242253
titleColor: null,
243254
onTitleClick: null,
244255
onForwardClick: null,
256+
onReplyMessageClick: null,
245257
date: new Date(),
246258
data: {},
247259
onClick: null,
@@ -250,6 +262,7 @@ MessageBox.defaultProps = {
250262
onLoad: null,
251263
onPhotoError: null,
252264
forwarded: false,
265+
reply: false,
253266
status: null,
254267
dateString: null,
255268
notch: true,

src/ReplyMessage/ReplyMessage.css

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
.rce-mbox-reply {
2+
position: relative;
3+
overflow: hidden;
4+
display: flex;
5+
margin-top: -3px;
6+
margin-bottom: 6px;
7+
margin-right: -6px;
8+
margin-left: -6px;
9+
border-radius: 5px;
10+
background: #ececec;
11+
padding: 0 5px;
12+
padding-right: 0;
13+
font-size: 12px;
14+
cursor: pointer;
15+
transition: 200ms;
16+
user-select: none;
17+
}
18+
19+
.rce-mbox-reply.rce-mbox-reply-border {
20+
border-left: 5px solid;
21+
}
22+
23+
.rce-mbox-reply:hover {
24+
opacity: 0.85;
25+
}
26+
27+
.rce-mbox-reply-left {
28+
display: flex;
29+
flex-direction: column;
30+
justify-content: space-between;
31+
padding: 3px 0;
32+
flex: 1;
33+
}
34+
35+
.rce-mbox-reply-owner {
36+
font-size: 13px;
37+
}
38+
39+
.rce-mbox-reply-message {
40+
color: #5a5a5a;
41+
overflow: hidden;
42+
white-space: nowrap;
43+
text-overflow: ellipsis;
44+
max-width: 150px;
45+
}
46+
47+
.rce-mbox-reply-right {
48+
width: 40px;
49+
height: 40px;
50+
}
51+
52+
.rce-mbox-reply-right img {
53+
width: 100%;
54+
}
55+
56+
.rce-mbox-reply-text {
57+
padding: 5px 0;
58+
width: 250px;
59+
margin-left: -6px;
60+
margin-right: -6px;
61+
}

src/ReplyMessage/ReplyMessage.js

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import React, { Component } from 'react';
2+
import './ReplyMessage.css';
3+
4+
const classNames = require('classnames');
5+
6+
export class ReplyMessage extends Component {
7+
constructor(props) {
8+
super(props);
9+
}
10+
11+
render() {
12+
const {
13+
photoURL,
14+
title,
15+
titleColor,
16+
message,
17+
onClick,
18+
} = this.props;
19+
20+
return (
21+
<div
22+
className={classNames("rce-mbox-reply", {
23+
'rce-mbox-reply-border': !!titleColor
24+
})}
25+
style={titleColor && { borderColor: titleColor }}
26+
onClick={onClick}>
27+
<div className="rce-mbox-reply-left">
28+
<div
29+
style={titleColor && { color: titleColor }}
30+
className="rce-mbox-reply-owner">
31+
{title || 'Unknown'}
32+
</div>
33+
<div className="rce-mbox-reply-message">
34+
{message || '...'}
35+
</div>
36+
</div>
37+
{
38+
photoURL &&
39+
<div className="rce-mbox-reply-right">
40+
<img src={photoURL} alt=""/>
41+
</div>
42+
}
43+
</div>
44+
);
45+
}
46+
}
47+
48+
ReplyMessage.defaultProps = {
49+
photoURL: null,
50+
title: null,
51+
titleColor: null,
52+
message: null,
53+
onClick: () => void(0),
54+
}
55+
56+
export default ReplyMessage;
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import React, { Component } from 'react';
2+
import { shallow } from 'enzyme';
3+
import toJson from 'enzyme-to-json';
4+
import ReplyMessage from '../ReplyMessage';
5+
6+
describe('ReplyMessage component', () => {
7+
it('should render without issues', () => {
8+
const component = shallow(<ReplyMessage />);
9+
expect(component.length).toBe(1);
10+
expect(toJson(component)).toMatchSnapshot();
11+
});
12+
});

0 commit comments

Comments
 (0)