From f0c465c21cdd246de2a1c9304725c7e152ea64c5 Mon Sep 17 00:00:00 2001 From: Avare Kodcu Date: Mon, 23 Oct 2017 13:43:14 +0300 Subject: [PATCH] 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. --- README.md | 3 +++ example/App.js | 3 ++- src/MessageBox/MessageBox.css | 11 ++++++++++- src/MessageBox/MessageBox.js | 26 +++++++++++++++++++++++--- 4 files changed, 38 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 9b3ced94..19f66b09 100644 --- a/README.md +++ b/README.md @@ -110,6 +110,9 @@ import { MessageBox } from 'react-chat-elements' | onForwardClick | none | function | message forward on click event | | forwarded | none | boolean | message forward icon | | statu | none | string | message statu info (waiting, sent, received, read) | +| notch | true | boolean | message box notch | +| avatar | none | url | message box avatar url | +| renderAddCmp | none | function (component) | adding custom components to message box | ## SystemMessage Component diff --git a/example/App.js b/example/App.js index 22b21c57..58f01394 100644 --- a/example/App.js +++ b/example/App.js @@ -96,7 +96,7 @@ export class App extends Component { view: 'list', title: loremIpsum({ count: 2, units: 'words' }), titleColor: this.getRandomColor(), - text: type === 'spotify' ? 'spotify:user:spotify:playlist:3rgsDhGHZxZ9sB9DQWQfuf' : loremIpsum({ count: 1, units: 'sentences' }), + text: type === 'spotify' ? 'spotify:track:7wGoVu4Dady5GV0Sv4UIsx' : loremIpsum({ count: 1, units: 'sentences' }), data: { uri: `data:image/png;base64,${this.photo(150)}`, status: { @@ -111,6 +111,7 @@ export class App extends Component { statu: statu, date: new Date(), dateString: moment(new Date()).format('HH:mm'), + avatar: `data:image/png;base64,${this.photo()}`, }; case 'chat': return { diff --git a/src/MessageBox/MessageBox.css b/src/MessageBox/MessageBox.css index c0d9c015..b58600bd 100644 --- a/src/MessageBox/MessageBox.css +++ b/src/MessageBox/MessageBox.css @@ -62,7 +62,6 @@ padding: 6px 9px 8px 9px; float: left; min-width: 140px; - max-width: 70%; } .rce-mbox-body { @@ -117,6 +116,10 @@ padding-bottom: 3px; } +.rce-mbox.rce-mbox--clear-notch { + border-radius: 5px 5px 5px 5px !important; +} + .rce-mbox-right-notch { position: absolute; right: -14px; @@ -144,6 +147,8 @@ color: #4f81a1; user-select: none; cursor: pointer; + display: flex; + align-items: center; } .rce-mbox-title:hover { @@ -158,3 +163,7 @@ margin-left: 3px; font-size: 15px; } + +.rce-mbox-title > .rce-avatar-container { + margin-right: 5px; +} diff --git a/src/MessageBox/MessageBox.js b/src/MessageBox/MessageBox.js index 516c139e..9d6588f8 100644 --- a/src/MessageBox/MessageBox.js +++ b/src/MessageBox/MessageBox.js @@ -7,6 +7,8 @@ import SystemMessage from '../SystemMessage/SystemMessage'; import LocationMessage from '../LocationMessage/LocationMessage'; import SpotifyMessage from '../SpotifyMessage/SpotifyMessage'; +import Avatar from '../Avatar/Avatar'; + import FaForward from 'react-icons/lib/fa/mail-forward'; import FaReply from 'react-icons/lib/fa/mail-reply'; @@ -27,6 +29,10 @@ export class MessageBox extends Component {
+ { + this.props.renderAddCmp instanceof Function && + this.props.renderAddCmp() + } { this.props.type === 'system' ?
{ @@ -52,14 +59,22 @@ export class MessageBox extends Component { } { - this.props.title && + (this.props.title || this.props.avatar) &&

- {this.props.title} + { + this.props.avatar && + + } + { + this.props.title && + {this.props.title} + }

} @@ -149,7 +164,8 @@ export class MessageBox extends Component {
{ - this.props.position === 'right' ? + this.props.notch && + (this.props.position === 'right' ? @@ -166,6 +182,7 @@ export class MessageBox extends Component {
+ ) } } @@ -190,6 +207,9 @@ MessageBox.defaultProps = { forwarded: false, statu: null, dateString: null, + notch: true, + avatar: null, + renderAddCmp: null, };