Newer
Older
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
import React, { Fragment } from 'react'
import styled from 'styled-components'
import { TextField } from '@pubsweet/ui'
import { th } from '@pubsweet/ui-toolkit'
import { IconButton, Label, Text } from './'
const PaginationComponent = ({
page = 1,
toLast,
toFirst,
hasMore = true,
nextPage,
prevPage,
maxItems = 23,
itemsPerPage = 10,
changeItemsPerPage = () => {},
}) => (
<Root>
<Text mr={1} secondary>
Showing
</Text>
<TextInput onChange={changeItemsPerPage} value={itemsPerPage} />
<Chevrons
hide={page === 0}
icon="chevrons-left"
iconSize={2}
onClick={toFirst}
/>
<Chevrons
hide={page === 0}
icon="chevron-left"
iconSize={2}
onClick={prevPage}
/>
<Label>{`${page * itemsPerPage + 1} to ${
hasMore ? itemsPerPage * (page + 1) : maxItems
}`}</Label>
<Chevrons
hide={!hasMore}
icon="chevron-right"
iconSize={2}
onClick={nextPage}
/>
<Chevrons
hide={!hasMore}
icon="chevrons-right"
iconSize={2}
onClick={toLast}
/>
</Root>
)
export const Pagination = ({ paginatedItems, children, ...props }) => (
<Fragment>
<PaginationComponent {...props} />
{typeof children === 'function' && children(paginatedItems, props)}
</Fragment>
)
export default PaginationComponent
// #region styles
const Root = styled.div`
align-items: center;
display: flex;
justify-content: center;
`
const TextInput = styled(TextField)`
margin: 0;
width: calc(${th('gridUnit')} * 5);
height: calc(${th('gridUnit')} * 4);
& input {
text-align: center;
vertical-align: middle;
}
`
const Chevrons = styled(IconButton)`
cursor: ${({ hide }) => (hide ? 'auto' : 'pointer')};
opacity: ${({ hide }) => (hide ? 0 : 1)};
`
// #endregion