Skip to content

Commit 49c5d66

Browse files
onOpen and onDownload added.
1 parent c607393 commit 49c5d66

9 files changed

Lines changed: 64 additions & 14 deletions

File tree

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@ import { MessageBox } from 'react-chat-elements'
7676
| text | none | string | message text |
7777
| data | {} | object | message data |
7878
| date | new Date() | Date | message date |
79+
| onClick | none | function | message on click (message(object) is returned) |
80+
| onOpen | none | function | message on open (file or photo) (message(object) is returned) |
81+
| onDownload | none | function | message on download (file or photo) (message(object) is returned) |
7982

8083

8184
## SystemMessage Component
@@ -127,6 +130,8 @@ import { MessageList } from 'react-chat-elements'
127130
| lockable | false | boolean | It locks to scroll position when the dataSource has been changed |
128131
| toBottomHeight | 300 | int or string(only '100%') | If the toBottomHeight property's value higher than bottom value of the scrollbar when the data source has been changed Scrollbar goes to bottom at the end of the page. If the toBottomHeight property's value has been set **'100%'**, scrollbar goes to bottom at the end of the page when the data source has been changed. |
129132
| onClick | none | function | message list item on click (message(object) is returned) |
133+
| onOpen | none | function | message list item on open (file or photo) (message(object) is returned) |
134+
| onDownload | none | function | message list item on download (file or photo) (message(object) is returned) |
130135

131136

132137
## ChatList Component

example/App.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,12 @@ export class App extends Component {
158158
className='right-panel'>
159159
<MessageList
160160
className='message-list'
161+
onDownload={() => {
162+
debugger;
163+
}}
164+
onOpen={() => {
165+
debugger;
166+
}}
161167
lockable={true}
162168
dataSource={this.state.messageList} />
163169
<Input
@@ -175,9 +181,7 @@ export class App extends Component {
175181
buttonProps={{
176182
text: 'Boşu Boşuna'
177183
}}
178-
onSelect={(i) => {
179-
console.log(`${i}'nci nesne seçildi`)
180-
}}
184+
onSelect={this.addMessage.bind(this)}
181185
animationPosition='southeast'/>
182186
}/>
183187
</div>

src/FileMessage/FileMessage.js

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,17 @@ const ProgressBar = require('react-progressbar.js');
88
const Circle = ProgressBar.Circle;
99

1010
export class FileMessage extends Component {
11+
12+
onClick() {
13+
if (!this.props.data.status)
14+
return;
15+
16+
if (!this.props.data.status.download && this.props.onDownload instanceof Function)
17+
this.props.onDownload();
18+
else if (this.props.data.status.download && this.props.onOpen instanceof Function)
19+
this.props.onOpen();
20+
}
21+
1122
render() {
1223
var progressOptions = {
1324
strokeWidth: 5,
@@ -25,14 +36,14 @@ export class FileMessage extends Component {
2536
circle.setText(value);
2637
}
2738
};
28-
39+
2940
return (
30-
<button className="rce-mbox-file">
41+
<button className="rce-mbox-file" onClick={this.onClick.bind(this)}>
3142
<div className="rce-mbox-file--icon">
3243
<FaFile
3344
color='#aaa'/>
3445
<div className="rce-mbox-file--size">
35-
1024mB
46+
{this.props.data.size}
3647
</div>
3748
</div>
3849
<div className="rce-mbox-file--text">
@@ -41,12 +52,14 @@ export class FileMessage extends Component {
4152
<div className="rce-mbox-file--buttons">
4253
{
4354
this.props.data.status &&
55+
!this.props.data.status.download &&
4456
!this.props.data.status.click &&
4557
<FaCloudDownload
4658
color='#aaa'/>
4759
}
4860
{
4961
this.props.data.status &&
62+
typeof this.props.data.status.loading === 'number' &&
5063
this.props.data.status.loading !== 0 &&
5164
<Circle
5265
progress={this.props.data.status.loading}
@@ -67,7 +80,10 @@ export class FileMessage extends Component {
6780
FileMessage.defaultProps = {
6881
text: '',
6982
data: {},
83+
onClick: null,
84+
onDownload: null,
85+
onOpen: null,
7086
};
7187

7288

73-
export default FileMessage;
89+
export default FileMessage;

src/FileMessage/__tests__/__snapshots__/FileMessage.js.snap

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
exports[`FileMessage component should render without issues 1`] = `
44
<button
55
className="rce-mbox-file"
6+
onClick={[Function]}
67
>
78
<div
89
className="rce-mbox-file--icon"
@@ -12,9 +13,7 @@ exports[`FileMessage component should render without issues 1`] = `
1213
/>
1314
<div
1415
className="rce-mbox-file--size"
15-
>
16-
1024mB
17-
</div>
16+
/>
1817
</div>
1918
<div
2019
className="rce-mbox-file--text"

src/MessageBox/MessageBox.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,16 @@ export class MessageBox extends Component {
2828
{
2929
this.props.type === 'photo' &&
3030
<PhotoMessage
31+
onOpen={this.props.onOpen}
32+
onDownload={this.props.onDownload}
3133
data={this.props.data}
3234
text={this.props.text}/>
3335
}
3436
{
3537
this.props.type === 'file' &&
3638
<FileMessage
39+
onOpen={this.props.onOpen}
40+
onDownload={this.props.onDownload}
3741
data={this.props.data}
3842
text={this.props.text}/>
3943
}
@@ -74,6 +78,8 @@ MessageBox.defaultProps = {
7478
date: new Date(),
7579
data: {},
7680
onClick: null,
81+
onOpen: null,
82+
onDownload: null,
7783
};
7884

7985

src/MessageList/MessageList.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,16 @@ export class MessageList extends Component {
3737
return e.scrollHeight - e.scrollTop - e.offsetHeight;
3838
}
3939

40+
onOpen(item, i) {
41+
if (this.props.onOpen instanceof Function)
42+
this.props.onOpen(item, i);
43+
}
44+
45+
onDownload(item, i) {
46+
if (this.props.onDownload instanceof Function)
47+
this.props.onDownload(item, i);
48+
}
49+
4050
onClick(item, i) {
4151
if (this.props.onClick instanceof Function)
4252
this.props.onClick(item, i);
@@ -52,6 +62,8 @@ export class MessageList extends Component {
5262
<MessageBox
5363
key={i}
5464
{...x}
65+
onOpen={() => this.onOpen(x, i)}
66+
onDownload={() => this.onDownload(x, i)}
5567
onClick={() => this.onClick(x, i)} />
5668
))
5769
}
@@ -62,6 +74,8 @@ export class MessageList extends Component {
6274

6375
MessageList.defaultProps = {
6476
onClick: null,
77+
onOpen: null,
78+
onDownload: null,
6579
dataSource: [],
6680
lockable: false,
6781
toBottomHeight: 300,

src/PhotoMessage/PhotoMessage.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,4 +61,4 @@
6161

6262
.rce-mbox-photo--download:active {
6363
opacity: .3;
64-
}
64+
}

src/PhotoMessage/PhotoMessage.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,19 +29,21 @@ export class PhotoMessage extends Component {
2929
return (
3030
<div className="rce-mbox-photo">
3131
<div className="rce-mbox-photo--img">
32-
<img src={this.props.data.uri} alt={this.props.data.alt}/>
32+
<img src={this.props.data.uri} alt={this.props.data.alt} onClick={this.props.onOpen}/>
3333
{
3434
this.props.data.status &&
3535
!this.props.data.status.download &&
3636
<div className="rce-mbox-photo--img__block">
3737
{
3838
!this.props.data.status.click &&
3939
<button
40+
onClick={this.props.onDownload}
4041
className="rce-mbox-photo--img__block-item rce-mbox-photo--download">
4142
<FaCloudDownload/>
4243
</button>
4344
}
4445
{
46+
typeof this.props.data.status.loading === 'number' &&
4547
this.props.data.status.loading !== 0 &&
4648
<Circle
4749
progress={this.props.data.status.loading}
@@ -67,7 +69,9 @@ export class PhotoMessage extends Component {
6769
PhotoMessage.defaultProps = {
6870
text: '',
6971
data: {},
72+
onDownload: null,
73+
onOpen: null,
7074
};
7175

7276

73-
export default PhotoMessage;
77+
export default PhotoMessage;

src/PhotoMessage/__tests__/__snapshots__/PhotoMessage.js.snap

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ exports[`PhotoMessage component should render without issues 1`] = `
77
<div
88
className="rce-mbox-photo--img"
99
>
10-
<img />
10+
<img
11+
onClick={null}
12+
/>
1113
</div>
1214
<div
1315
className="rce-mbox-text"

0 commit comments

Comments
 (0)