-
Notifications
You must be signed in to change notification settings - Fork 128
/
Copy pathConversationList.jsx
101 lines (91 loc) · 2.45 KB
/
ConversationList.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
import React, { useMemo } from "react";
import PropTypes from "prop-types";
import { allowedChildren } from "../utils";
import { prefix } from "../settings";
import PerfectScrollbar from "../Scroll";
import classNames from "classnames";
import Overlay from "../Overlay";
import Loader from "../Loader";
import Conversation from "../Conversation";
export const ConversationList = ({
children = [],
scrollable = true,
loading = false,
loadingMore = false,
onYReachEnd,
className = "",
...props
}) => {
const cName = `${prefix}-conversation-list`;
// Memoize, to avoid re-render each time when props (children) changed
const Tag = useMemo(
() => function Tag({ children }) {
// PerfectScrollbar for now cant be disabled, so render div instead of disabling it
// https://github.com/goldenyz/react-perfect-scrollbar/issues/107
if (scrollable === false || (scrollable === true && loading === true)) {
return (
<div>
{loading && (
<Overlay>
<Loader />
</Overlay>
)}
{children}
</div>
);
} else {
return (
<PerfectScrollbar
onYReachEnd={onYReachEnd}
options={{ suppressScrollX: true }}
>
{children}
</PerfectScrollbar>
);
}
},
[scrollable, loading, onYReachEnd]
);
return (
<div className={classNames(cName, className)} {...props}>
<Tag>
{React.Children.count(children) > 0 && (
<ul>
{React.Children.map(children, (item) => (
<li>{item}</li>
))}
</ul>
)}
</Tag>
{loadingMore && (
<div className={`${cName}__loading-more`}>
<Loader />
</div>
)}
</div>
);
};
ConversationList.propTypes = {
/**
* Primary content.
* Allowed components:
*
* * <Conversation />
*
*/
children: allowedChildren([Conversation]),
/** Init scrollbar flag. */
scrollable: PropTypes.bool,
/** Loading flag. */
loading: PropTypes.bool,
/** Loading more flag for infinity scroll. */
loadingMore: PropTypes.bool,
/**
* This is fired when the scrollbar reaches the end on the y axis.<br/>
* It can be used to load next conversations using the infinite scroll.
*/
onYReachEnd: PropTypes.func,
/** Additional classes. */
className: PropTypes.string,
};
export default ConversationList;