2020-08-17 21:07:16 +01:00
|
|
|
import React from 'react'
|
2020-08-17 21:59:29 +01:00
|
|
|
import PropTypes from 'prop-types'
|
2020-03-25 03:08:43 +00:00
|
|
|
import ImmutablePureComponent from 'react-immutable-pure-component'
|
2020-04-23 07:13:29 +01:00
|
|
|
import ImmutablePropTypes from 'react-immutable-proptypes'
|
2020-02-22 23:26:23 +00:00
|
|
|
import Block from './block'
|
2020-02-21 00:57:29 +00:00
|
|
|
import ScrollableList from './scrollable_list'
|
|
|
|
import ListItem from './list_item'
|
2020-05-14 22:47:33 +01:00
|
|
|
import Dummy from './dummy'
|
2020-07-28 21:11:51 +01:00
|
|
|
import ListItemPlaceholder from './placeholder/list_item_placeholder'
|
2020-02-21 00:57:29 +00:00
|
|
|
|
2020-08-18 01:57:35 +01:00
|
|
|
class List extends ImmutablePureComponent {
|
2020-02-21 00:57:29 +00:00
|
|
|
|
|
|
|
render() {
|
2020-04-02 17:57:04 +01:00
|
|
|
const {
|
|
|
|
items,
|
|
|
|
scrollKey,
|
|
|
|
emptyMessage,
|
|
|
|
hasMore,
|
2020-04-07 02:53:23 +01:00
|
|
|
size,
|
2020-06-05 20:28:46 +01:00
|
|
|
onLoadMore,
|
|
|
|
showLoading,
|
2020-04-02 17:57:04 +01:00
|
|
|
} = this.props
|
2020-02-21 00:57:29 +00:00
|
|
|
|
2020-05-14 22:47:33 +01:00
|
|
|
const Wrapper = !!scrollKey ? ScrollableList : Dummy
|
2020-12-31 21:39:27 +00:00
|
|
|
const itemsSize = !!items ? Array.isArray(items) ? items.length : items.size : 0
|
2020-05-14 22:47:33 +01:00
|
|
|
|
2020-02-21 00:57:29 +00:00
|
|
|
return (
|
2020-02-22 23:26:23 +00:00
|
|
|
<Block>
|
2020-05-14 22:47:33 +01:00
|
|
|
<Wrapper
|
2020-04-02 17:57:04 +01:00
|
|
|
onLoadMore={onLoadMore}
|
|
|
|
hasMore={hasMore}
|
2020-02-21 00:57:29 +00:00
|
|
|
scrollKey={scrollKey}
|
|
|
|
emptyMessage={emptyMessage}
|
2020-06-05 20:28:46 +01:00
|
|
|
showLoading={showLoading}
|
2020-07-28 21:11:51 +01:00
|
|
|
placeholderComponent={ListItemPlaceholder}
|
2020-07-29 21:40:47 +01:00
|
|
|
placeholderCount={12}
|
2020-02-21 00:57:29 +00:00
|
|
|
>
|
|
|
|
{
|
2021-01-13 17:05:29 +00:00
|
|
|
!!items && itemsSize > 0 &&
|
2020-03-25 03:08:43 +00:00
|
|
|
items.map((item, i) => (
|
|
|
|
<ListItem
|
2020-04-07 02:53:23 +01:00
|
|
|
size={size}
|
2020-03-25 03:08:43 +00:00
|
|
|
key={`list-item-${i}`}
|
2020-12-31 21:39:27 +00:00
|
|
|
isLast={itemsSize - 1 === i}
|
2020-03-25 03:08:43 +00:00
|
|
|
{...item}
|
|
|
|
/>
|
|
|
|
))
|
2020-02-21 00:57:29 +00:00
|
|
|
}
|
2020-05-14 22:47:33 +01:00
|
|
|
</Wrapper>
|
2020-04-29 23:32:49 +01:00
|
|
|
</Block>
|
2020-02-21 00:57:29 +00:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2020-08-18 01:57:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
List.propTypes = {
|
|
|
|
items: PropTypes.oneOfType([
|
|
|
|
PropTypes.array,
|
|
|
|
ImmutablePropTypes.map,
|
|
|
|
ImmutablePropTypes.list,
|
|
|
|
]),
|
|
|
|
scrollKey: PropTypes.string,
|
|
|
|
emptyMessage: PropTypes.any,
|
|
|
|
size: PropTypes.oneOf([
|
|
|
|
'small',
|
|
|
|
'large'
|
|
|
|
]),
|
|
|
|
onLoadMore: PropTypes.func,
|
|
|
|
hasMore: PropTypes.bool,
|
|
|
|
showLoading: PropTypes.bool,
|
|
|
|
}
|
|
|
|
|
|
|
|
export default List
|