Skip to content

Commit 8ac79b5

Browse files
Next release 0.5.2 (#33)
* custom dateString prop added. * version upgrade v0.5.2
1 parent f9f1619 commit 8ac79b5

5 files changed

Lines changed: 16 additions & 3 deletions

File tree

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ import { ChatItem } from 'react-chat-elements'
5858
| title | none | string | ChatItem title |
5959
| subtitle | none | string | ChatItem subtitle |
6060
| date | none | date | ChatItem date |
61+
| dateString | none | string | ChatItem represents dateString or moment(date).fromNow() |
6162
| unread | 0 | int | ChatItem unread count |
6263
| onClick | none | function | ChatItem on click |
6364
| onContextMenu | none | function | ChatItem on context menu |
@@ -101,6 +102,7 @@ import { MessageBox } from 'react-chat-elements'
101102
| titleColor | none | string(color) | message title color |
102103
| data | {} | object | message data |
103104
| date | new Date() | Date | message date |
105+
| dateString | none | string | message represents dateString or moment(date).fromNow() |
104106
| onClick | none | function | message on click (message(object) is returned) |
105107
| onOpen | none | function | message on open (file or photo) (message(object) is returned) |
106108
| onDownload | none | function | message on download (file or photo) (message(object) is returned) |

example/App.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import FaClose from 'react-icons/lib/fa/close';
2020

2121
const loremIpsum = require('lorem-ipsum');
2222
const Identicon = require('identicon.js')
23+
const moment = require('moment');
2324

2425
export class App extends Component {
2526

@@ -108,6 +109,7 @@ export class App extends Component {
108109
},
109110
statu: statu,
110111
date: new Date(),
112+
dateString: moment(new Date()).format('HH:mm'),
111113
};
112114
case 'chat':
113115
return {
@@ -120,6 +122,7 @@ export class App extends Component {
120122
date: new Date(),
121123
subtitle: loremIpsum({ count: 1, units: 'sentences' }),
122124
unread: parseInt(Math.random() * 10 % 3),
125+
dateString: moment(new Date()).format('HH:mm'),
123126
};
124127
}
125128
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-chat-elements",
3-
"version": "0.5.1",
3+
"version": "0.5.2",
44
"description": "Reactjs chat components",
55
"author": "Avare Kodcu <abdurrahmaneker58@gmail.com>",
66
"main": "dist/main.js",

src/ChatItem/ChatItem.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,10 @@ export class ChatItem extends Component {
3838
{
3939
this.props.date &&
4040
!isNaN(this.props.date) &&
41-
moment(this.props.date).fromNow()
41+
(
42+
this.props.dateString ||
43+
moment(this.props.date).fromNow()
44+
)
4245
}
4346
</div>
4447
</div>
@@ -73,6 +76,7 @@ ChatItem.defaultProps = {
7376
unread: 0,
7477
statusColor: null,
7578
statusText: null,
79+
dateString: null,
7680
}
7781

7882
export default ChatItem;

src/MessageBox/MessageBox.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,10 @@ export class MessageBox extends Component {
104104
{
105105
this.props.date &&
106106
!isNaN(this.props.date) &&
107-
moment(this.props.date).fromNow()
107+
(
108+
this.props.dateString ||
109+
moment(this.props.date).fromNow()
110+
)
108111
}
109112
{
110113
this.props.statu &&
@@ -173,6 +176,7 @@ MessageBox.defaultProps = {
173176
onDownload: null,
174177
forwarded: false,
175178
statu: null,
179+
dateString: null,
176180
};
177181

178182

0 commit comments

Comments
 (0)