Skip to content

Commit 2e1dd30

Browse files
Merge pull request #50 from Detaysoft/next
Next version 0.8.0
2 parents 4f5d1e6 + e81b0ae commit 2e1dd30

7 files changed

Lines changed: 129 additions & 19 deletions

File tree

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,9 @@ import { MessageList } from 'react-chat-elements'
168168
| onDownload | none | function | message list item on download (file or photo) (message(object) is returned) |
169169
| onScroll | none | function | message list onScroll event |
170170
| onForwardClick | none | function | message list item onForwardClick event |
171+
| downButton | true | boolean | message list scroll to bottom button |
172+
| downButtonBadge | none | boolean | message list downButton badge content |
173+
| onDownButtonClick | none | function | message list onDownButtonClick |
171174

172175

173176
## ChatList Component

example/App.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,7 @@ export class App extends Component {
221221
<MessageList
222222
className='message-list'
223223
lockable={true}
224+
downButtonBadge={10}
224225
dataSource={this.state.messageList} />
225226

226227
<Input

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.7.2",
3+
"version": "0.8.0",
44
"description": "Reactjs chat components",
55
"author": "Avare Kodcu <abdurrahmaneker58@gmail.com>",
66
"main": "dist/main.js",

src/MessageList/MessageList.css

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,49 @@
11
.rce-container-mlist {
2+
position: relative;
3+
display: flex;
4+
}
5+
6+
.rce-mlist {
27
display: block;
38
overflow: auto;
9+
position: relative;
10+
flex: 1;
11+
}
12+
13+
.rce-mlist-down-button {
14+
position: absolute;
15+
right: 10px;
16+
bottom: 15px;
17+
width: 40px;
18+
height: 40px;
19+
background: #fff;
20+
box-shadow: 0 1px 1px 0 rgba(0,0,0,0.05), 0 2px 5px 0 rgba(0,0,0,0.1);
21+
border-radius: 100%;
22+
display: flex;
23+
justify-content: center;
24+
align-items: center;
25+
color: #333;
26+
cursor: pointer;
27+
transition: 200ms;
28+
}
29+
30+
.rce-mlist-down-button:hover {
31+
opacity: 0.7;
32+
}
33+
34+
.rce-mlist-down-button--badge {
35+
position: absolute;
36+
right: -5px;
37+
top: -5px;
38+
background: red;
39+
width: 20px;
40+
height: 20px;
41+
border-radius: 100%;
42+
font-size: 12px;
43+
display: flex;
44+
text-align: center;
45+
align-items: center;
46+
justify-content: center;
47+
color: #fff;
48+
font-weight: 700;
449
}

src/MessageList/MessageList.js

Lines changed: 72 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import './MessageList.css';
33

44
import MessageBox from '../MessageBox/MessageBox';
55

6+
import FaChevronDown from 'react-icons/lib/fa/chevron-down';
7+
68
const classNames = require('classnames');
79

810
export class MessageList extends Component {
@@ -11,16 +13,16 @@ export class MessageList extends Component {
1113
super(props);
1214
this.state = {
1315
scrollBottom: 0,
16+
downButton: false,
1417
};
1518
}
1619

17-
componentDidUpdate() {
20+
checkScroll() {
1821
var e = this.mlistRef;
1922
if (!e)
2023
return;
2124

22-
var bottom = this.getBottom(e);
23-
if (this.props.toBottomHeight === '100%' || bottom < this.props.toBottomHeight) {
25+
if (this.props.toBottomHeight === '100%' || this.state.scrollBottom < this.props.toBottomHeight) {
2426
// scroll to bottom
2527
e.scrollTop = e.scrollHeight;
2628
} else {
@@ -35,7 +37,7 @@ export class MessageList extends Component {
3537
return;
3638
this.setState({
3739
scrollBottom: this.getBottom(this.mlistRef),
38-
});
40+
}, this.checkScroll.bind(this));
3941
}
4042

4143
getBottom(e) {
@@ -73,23 +75,74 @@ export class MessageList extends Component {
7375
this.props.cmpRef(ref);
7476
}
7577

78+
onScroll(e) {
79+
var bottom = this.getBottom(e.target);
80+
this.state.scrollBottom = bottom;
81+
if (this.props.toBottomHeight === '100%' || bottom > this.props.toBottomHeight) {
82+
if (this.state.downButton !== true) {
83+
this.state.downButton = true;
84+
this.setState({
85+
downButton: true,
86+
scrollBottom: bottom,
87+
})
88+
}
89+
} else {
90+
if (this.state.downButton !== false) {
91+
this.state.downButton = false;
92+
this.setState({
93+
downButton: false,
94+
scrollBottom: bottom,
95+
})
96+
}
97+
}
98+
}
99+
100+
toBottom(e) {
101+
if(!this.mlistRef)
102+
return;
103+
this.mlistRef.scrollTop = this.mlistRef.scrollHeight;
104+
if (this.props.onDownButtonClick instanceof Function) {
105+
this.props.onDownButtonClick(e);
106+
}
107+
}
108+
76109
render() {
77110
return (
78111
<div
79-
ref={this.loadRef.bind(this)}
80-
onScroll={this.props.onScroll}
81112
className={classNames(['rce-container-mlist', this.props.className])}>
113+
<div
114+
ref={this.loadRef.bind(this)}
115+
onScroll={this.onScroll.bind(this)}
116+
className='rce-mlist'>
117+
{
118+
this.props.dataSource.map((x, i) => (
119+
<MessageBox
120+
key={i}
121+
{...x}
122+
onOpen={this.props.onOpen && ((e) => this.onOpen(x, i, e))}
123+
onDownload={this.props.onDownload && ((e) => this.onDownload(x, i, e))}
124+
onTitleClick={this.props.onDownload && ((e) => this.onTitleClick(x, i, e))}
125+
onForwardClick={this.props.onForwardClick && ((e) => this.onForwardClick(x, i, e))}
126+
onClick={this.props.onClick && ((e) => this.onClick(x, i, e))}/>
127+
))
128+
}
129+
</div>
82130
{
83-
this.props.dataSource.map((x, i) => (
84-
<MessageBox
85-
key={i}
86-
{...x}
87-
onOpen={this.props.onOpen && ((e) => this.onOpen(x, i, e))}
88-
onDownload={this.props.onDownload && ((e) => this.onDownload(x, i, e))}
89-
onTitleClick={this.props.onDownload && ((e) => this.onTitleClick(x, i, e))}
90-
onForwardClick={this.props.onForwardClick && ((e) => this.onForwardClick(x, i, e))}
91-
onClick={this.props.onClick && ((e) => this.onClick(x, i, e))}/>
92-
))
131+
this.props.downButton === true &&
132+
this.state.downButton &&
133+
this.props.toBottomHeight !== '100%' &&
134+
<div
135+
className='rce-mlist-down-button'
136+
onClick={this.toBottom.bind(this)}>
137+
<FaChevronDown/>
138+
{
139+
this.props.downButtonBadge &&
140+
<span
141+
className='rce-mlist-down-button--badge'>
142+
{this.props.downButtonBadge}
143+
</span>
144+
}
145+
</div>
93146
}
94147
</div>
95148
);
@@ -100,11 +153,14 @@ MessageList.defaultProps = {
100153
onClick: null,
101154
onTitleClick: null,
102155
onForwardClick: null,
156+
onDownButtonClick: null,
103157
onOpen: null,
104158
onDownload: null,
105159
dataSource: [],
106160
lockable: false,
107161
toBottomHeight: 300,
162+
downButton: true,
163+
downButtonBadge: null,
108164
};
109165

110166
export default MessageList;

src/MessageList/__tests__/MessageList.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@ describe('MessageList component', () => {
1010
expect(component.length).toBe(1);
1111
expect(toJson(component)).toMatchSnapshot();
1212
});
13-
});
13+
});

src/MessageList/__tests__/__snapshots__/MessageList.js.snap

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,10 @@
33
exports[`MessageList component should render without issues 1`] = `
44
<div
55
className="rce-container-mlist"
6-
/>
6+
>
7+
<div
8+
className="rce-mlist"
9+
onScroll={[Function]}
10+
/>
11+
</div>
712
`;

0 commit comments

Comments
 (0)