-
Notifications
You must be signed in to change notification settings - Fork 37
/
LoadMorePaginationRow.js
93 lines (88 loc) · 2.52 KB
/
LoadMorePaginationRow.js
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
import React from 'react';
import PropTypes from 'prop-types';
import { FormattedMessage } from 'react-intl';
import PagingButton from './PagingButton';
import RowPositioner from './RowPositioner';
import CenteredContainer from './CenteredContainer';
const propTypes = {
dataEndReached: PropTypes.bool,
handleLoadMore: PropTypes.func,
id: PropTypes.string,
keyId: PropTypes.string,
loading: PropTypes.bool,
pageAmount: PropTypes.number,
pagingButtonLabel: PropTypes.node,
pagingButtonRef: PropTypes.object,
positionCache: PropTypes.object,
prevWidth: PropTypes.number,
rowHeightCache: PropTypes.object,
rowIndex: PropTypes.number,
sendMessage: PropTypes.func,
setFocusIndex: PropTypes.func,
staticBody: PropTypes.bool,
virtualize: PropTypes.bool,
width: PropTypes.number
};
const LoadMorePaginationRow = ({
dataEndReached,
handleLoadMore,
id,
keyId,
loading,
pageAmount,
pagingButtonLabel,
pagingButtonRef,
positionCache,
prevWidth,
rowHeightCache,
rowIndex,
sendMessage,
setFocusIndex,
staticBody,
virtualize,
width,
}) => {
if (dataEndReached) { return null; }
return (
<RowPositioner
key={`load-button-positioner-${rowIndex}-${keyId}`}
gridId={id}
heightCache={rowHeightCache}
positionCache={positionCache}
shouldPosition={!staticBody}
rowIndex={rowIndex}
>
{({ localRowIndex, position }) => (
<div
key={`${localRowIndex}-load-button`}
style={{ position: virtualize ? 'absolute' : 'relative', top: `${position}px`, marginTop: '1rem' }}
>
<CenteredContainer
width={width || prevWidth || undefined}
innerRef={pagingButtonRef}
visible
>
<FormattedMessage id="stripes-components.mcl.itemsRequestedMessage">
{ ([message]) => (
<PagingButton
onClick={() => {
setFocusIndex(rowIndex);
handleLoadMore(pageAmount, rowIndex);
}}
sendMessage={sendMessage}
loadingMessage={message}
disabled={loading}
pagingButtonLabel={pagingButtonLabel}
id={`${id || keyId}-clickable-paging-button`}
style={{ width: '75%' }}
/>
)}
</FormattedMessage>
</CenteredContainer>
</div>
)}
</RowPositioner>
);
};
LoadMorePaginationRow.propTypes = propTypes;
export default LoadMorePaginationRow;