Skip to content

Commit b940b2a

Browse files
MessageBox notch and avatar property added. (#37)
* MessageBox notch property added. * MessageBox avatar property added. * README.MD update 'notch' * renderAvatar prop added. * renderAddCmp prop added. MessageBox max-width style deleted.
1 parent b823d38 commit b940b2a

4 files changed

Lines changed: 38 additions & 5 deletions

File tree

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,9 @@ import { MessageBox } from 'react-chat-elements'
110110
| onForwardClick | none | function | message forward on click event |
111111
| forwarded | none | boolean | message forward icon |
112112
| statu | none | string | message statu info (waiting, sent, received, read) |
113+
| notch | true | boolean | message box notch |
114+
| avatar | none | url | message box avatar url |
115+
| renderAddCmp | none | function (component) | adding custom components to message box |
113116

114117

115118
## SystemMessage Component

example/App.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ export class App extends Component {
9696
view: 'list',
9797
title: loremIpsum({ count: 2, units: 'words' }),
9898
titleColor: this.getRandomColor(),
99-
text: type === 'spotify' ? 'spotify:user:spotify:playlist:3rgsDhGHZxZ9sB9DQWQfuf' : loremIpsum({ count: 1, units: 'sentences' }),
99+
text: type === 'spotify' ? 'spotify:track:7wGoVu4Dady5GV0Sv4UIsx' : loremIpsum({ count: 1, units: 'sentences' }),
100100
data: {
101101
uri: `data:image/png;base64,${this.photo(150)}`,
102102
status: {
@@ -111,6 +111,7 @@ export class App extends Component {
111111
statu: statu,
112112
date: new Date(),
113113
dateString: moment(new Date()).format('HH:mm'),
114+
avatar: `data:image/png;base64,${this.photo()}`,
114115
};
115116
case 'chat':
116117
return {

src/MessageBox/MessageBox.css

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@
6262
padding: 6px 9px 8px 9px;
6363
float: left;
6464
min-width: 140px;
65-
max-width: 70%;
6665
}
6766

6867
.rce-mbox-body {
@@ -117,6 +116,10 @@
117116
padding-bottom: 3px;
118117
}
119118

119+
.rce-mbox.rce-mbox--clear-notch {
120+
border-radius: 5px 5px 5px 5px !important;
121+
}
122+
120123
.rce-mbox-right-notch {
121124
position: absolute;
122125
right: -14px;
@@ -144,6 +147,8 @@
144147
color: #4f81a1;
145148
user-select: none;
146149
cursor: pointer;
150+
display: flex;
151+
align-items: center;
147152
}
148153

149154
.rce-mbox-title:hover {
@@ -158,3 +163,7 @@
158163
margin-left: 3px;
159164
font-size: 15px;
160165
}
166+
167+
.rce-mbox-title > .rce-avatar-container {
168+
margin-right: 5px;
169+
}

src/MessageBox/MessageBox.js

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import SystemMessage from '../SystemMessage/SystemMessage';
77
import LocationMessage from '../LocationMessage/LocationMessage';
88
import SpotifyMessage from '../SpotifyMessage/SpotifyMessage';
99

10+
import Avatar from '../Avatar/Avatar';
11+
1012
import FaForward from 'react-icons/lib/fa/mail-forward';
1113
import FaReply from 'react-icons/lib/fa/mail-reply';
1214

@@ -27,6 +29,10 @@ export class MessageBox extends Component {
2729
<div
2830
className={classNames('rce-container-mbox', this.props.className)}
2931
onClick={this.props.onClick}>
32+
{
33+
this.props.renderAddCmp instanceof Function &&
34+
this.props.renderAddCmp()
35+
}
3036
{
3137
this.props.type === 'system' ?
3238
<SystemMessage
@@ -36,6 +42,7 @@ export class MessageBox extends Component {
3642
className={classNames(
3743
positionCls,
3844
{'rce-mbox--clear-padding': thatAbsoluteTime},
45+
{'rce-mbox--clear-notch': !this.props.notch}
3946
)}>
4047
<div className='rce-mbox-body'>
4148
{
@@ -52,14 +59,22 @@ export class MessageBox extends Component {
5259
}
5360

5461
{
55-
this.props.title &&
62+
(this.props.title || this.props.avatar) &&
5663
<p
5764
style={this.props.titleColor && { color: this.props.titleColor }}
5865
onClick={this.props.onTitleClick}
5966
className={classNames('rce-mbox-title', {
6067
'rce-mbox-title--clear': this.props.type === 'text',
6168
})}>
62-
{this.props.title}
69+
{
70+
this.props.avatar &&
71+
<Avatar
72+
src={this.props.avatar}/>
73+
}
74+
{
75+
this.props.title &&
76+
<span>{this.props.title}</span>
77+
}
6378
</p>
6479
}
6580

@@ -149,7 +164,8 @@ export class MessageBox extends Component {
149164
</div>
150165

151166
{
152-
this.props.position === 'right' ?
167+
this.props.notch &&
168+
(this.props.position === 'right' ?
153169
<svg className="rce-mbox-right-notch" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20">
154170
<path d="M0 0v20L20 0" />
155171
</svg>
@@ -166,6 +182,7 @@ export class MessageBox extends Component {
166182
<path d="M20 0v20L0 0" filter="url(#filter1)" />
167183
</svg>
168184
</div>
185+
)
169186
}
170187
</div>
171188
}
@@ -190,6 +207,9 @@ MessageBox.defaultProps = {
190207
forwarded: false,
191208
statu: null,
192209
dateString: null,
210+
notch: true,
211+
avatar: null,
212+
renderAddCmp: null,
193213
};
194214

195215

0 commit comments

Comments
 (0)