@dhis2-ui/pagination 10.16.1 → 10.16.3-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. package/package.json +7 -6
  2. package/src/__fixtures__/index.js +46 -0
  3. package/src/__tests__/get-item-range.test.js +65 -0
  4. package/src/__tests__/page-controls.test.js +80 -0
  5. package/src/__tests__/page-select.test.js +40 -0
  6. package/src/__tests__/page-size-select.test.js +29 -0
  7. package/src/__tests__/page-summary.test.js +70 -0
  8. package/src/__tests__/pagination.test.js +212 -0
  9. package/src/get-default-page-summary-text.js +34 -0
  10. package/src/get-item-range.js +35 -0
  11. package/src/index.js +1 -0
  12. package/src/locales/ar/translations.json +10 -0
  13. package/src/locales/ar_IQ/translations.json +10 -0
  14. package/src/locales/bn/translations.json +10 -0
  15. package/src/locales/ckb/translations.json +10 -0
  16. package/src/locales/cs/translations.json +10 -0
  17. package/src/locales/da/translations.json +10 -0
  18. package/src/locales/en/translations.json +10 -0
  19. package/src/locales/es/translations.json +10 -0
  20. package/src/locales/es_419/translations.json +10 -0
  21. package/src/locales/fr/translations.json +10 -0
  22. package/src/locales/hi_IN/translations.json +10 -0
  23. package/src/locales/id/translations.json +10 -0
  24. package/src/locales/index.js +82 -0
  25. package/src/locales/km/translations.json +10 -0
  26. package/src/locales/lo/translations.json +10 -0
  27. package/src/locales/my/translations.json +10 -0
  28. package/src/locales/nb/translations.json +10 -0
  29. package/src/locales/nl/translations.json +10 -0
  30. package/src/locales/prs/translations.json +10 -0
  31. package/src/locales/ps/translations.json +10 -0
  32. package/src/locales/pt/translations.json +10 -0
  33. package/src/locales/pt_BR/translations.json +10 -0
  34. package/src/locales/ro/translations.json +10 -0
  35. package/src/locales/ru/translations.json +10 -0
  36. package/src/locales/sv/translations.json +10 -0
  37. package/src/locales/tet/translations.json +10 -0
  38. package/src/locales/tg/translations.json +10 -0
  39. package/src/locales/uk/translations.json +10 -0
  40. package/src/locales/ur/translations.json +10 -0
  41. package/src/locales/uz_Latn/translations.json +10 -0
  42. package/src/locales/uz_UZ_Cyrl/translations.json +10 -0
  43. package/src/locales/uz_UZ_Latn/translations.json +10 -0
  44. package/src/locales/vi/translations.json +10 -0
  45. package/src/locales/zh/translations.json +10 -0
  46. package/src/locales/zh_CN/translations.json +10 -0
  47. package/src/page-controls.js +83 -0
  48. package/src/page-select.js +62 -0
  49. package/src/page-size-select.js +64 -0
  50. package/src/page-summary.js +67 -0
  51. package/src/pagination.js +152 -0
  52. package/src/pagination.prod.stories.js +113 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dhis2-ui/pagination",
3
- "version": "10.16.1",
3
+ "version": "10.16.3-alpha.1",
4
4
  "description": "UI Pagination",
5
5
  "repository": {
6
6
  "type": "git",
@@ -34,16 +34,17 @@
34
34
  },
35
35
  "dependencies": {
36
36
  "@dhis2/prop-types": "^3.1.2",
37
- "@dhis2-ui/button": "10.16.1",
38
- "@dhis2-ui/select": "10.16.1",
39
- "@dhis2/ui-constants": "10.16.1",
40
- "@dhis2/ui-icons": "10.16.1",
37
+ "@dhis2-ui/button": "10.16.3-alpha.1",
38
+ "@dhis2-ui/select": "10.16.3-alpha.1",
39
+ "@dhis2/ui-constants": "10.16.3-alpha.1",
40
+ "@dhis2/ui-icons": "10.16.3-alpha.1",
41
41
  "classnames": "^2.3.1",
42
42
  "prop-types": "^15.7.2"
43
43
  },
44
44
  "files": [
45
45
  "build",
46
- "types"
46
+ "types",
47
+ "src"
47
48
  ],
48
49
  "devDependencies": {
49
50
  "@dhis2/d2-i18n": "^1.1.0",
@@ -0,0 +1,46 @@
1
+ export const atFirstPage = {
2
+ page: 1,
3
+ pageCount: 21,
4
+ total: 1035,
5
+ pageSize: 50,
6
+ }
7
+
8
+ export const atSecondPage = {
9
+ page: 2,
10
+ pageCount: 21,
11
+ total: 1035,
12
+ pageSize: 50,
13
+ }
14
+
15
+ export const atTenthPage = {
16
+ page: 10,
17
+ pageCount: 21,
18
+ total: 1035,
19
+ pageSize: 50,
20
+ }
21
+
22
+ export const atLastPage = {
23
+ page: 21,
24
+ pageCount: 21,
25
+ total: 1035,
26
+ pageSize: 50,
27
+ }
28
+
29
+ export const atPageBeforeLast = {
30
+ page: 20,
31
+ pageCount: 21,
32
+ total: 1035,
33
+ pageSize: 50,
34
+ }
35
+
36
+ export const noTotal = {
37
+ page: 3,
38
+ pageSize: 50,
39
+ isLastPage: false,
40
+ }
41
+
42
+ export const noTotalAtLastPage = {
43
+ page: 4,
44
+ pageSize: 50,
45
+ isLastPage: true,
46
+ }
@@ -0,0 +1,65 @@
1
+ import * as mockPagers from '../__fixtures__/index.js'
2
+ import { getItemRange } from '../get-item-range.js'
3
+
4
+ describe('getItemRange', () => {
5
+ it('calculates the firstItem and lastItem correctly', () => {
6
+ const { page, pageSize, total } = mockPagers.atTenthPage
7
+ const { firstItem, lastItem } = getItemRange({
8
+ page,
9
+ pageSize,
10
+ total,
11
+ })
12
+
13
+ expect(firstItem).toBe(451)
14
+ expect(lastItem).toBe(500)
15
+ })
16
+
17
+ it('returns 0 for firstItem and lastItem if the total is 0', () => {
18
+ const { firstItem, lastItem } = getItemRange({
19
+ page: 1,
20
+ pageSize: 50,
21
+ total: 0,
22
+ })
23
+
24
+ expect(firstItem).toBe(0)
25
+ expect(lastItem).toBe(0)
26
+ })
27
+
28
+ it('uses the total count as lastItem when the last page is reached', () => {
29
+ const { page, pageSize, total } = mockPagers.atLastPage
30
+ const { lastItem } = getItemRange({ page, pageSize, total })
31
+
32
+ expect(lastItem).toBe(total)
33
+ })
34
+
35
+ it('handles pagers without totals', () => {
36
+ const { firstItem, lastItem } = getItemRange({
37
+ page: 3,
38
+ pageSize: 50,
39
+ })
40
+
41
+ expect(firstItem).toBe(101)
42
+ expect(lastItem).toBe(150)
43
+ })
44
+
45
+ it('bases the lastItem on the pageLength for pagers without total when the last page is reached', () => {
46
+ const { lastItem } = getItemRange({
47
+ page: 3,
48
+ pageSize: 50,
49
+ pageLength: 21,
50
+ isLastPage: true,
51
+ })
52
+
53
+ expect(lastItem).toBe(121)
54
+ })
55
+
56
+ it('sets lastItem to NaN when on the last page and there is no total or pageLength', () => {
57
+ const { lastItem } = getItemRange({
58
+ page: 3,
59
+ pageSize: 50,
60
+ isLastPage: true,
61
+ })
62
+
63
+ expect(lastItem).toBe(NaN)
64
+ })
65
+ })
@@ -0,0 +1,80 @@
1
+ import { shallow } from 'enzyme'
2
+ import React from 'react'
3
+ import { PageControls } from '../page-controls.js'
4
+
5
+ describe('<PageControls />', () => {
6
+ const mockOnClick = jest.fn()
7
+ const props = {
8
+ dataTest: 'test',
9
+ onClick: mockOnClick,
10
+ nextPageText: 'Next',
11
+ previousPageText: 'Previous',
12
+ page: 10,
13
+ }
14
+
15
+ beforeEach(() => {
16
+ mockOnClick.mockClear()
17
+ })
18
+
19
+ it('renders without errors', () => {
20
+ shallow(<PageControls {...props} />)
21
+ })
22
+
23
+ it('enables all buttons on by default', () => {
24
+ const wrapper = shallow(<PageControls {...props} />)
25
+
26
+ expect(
27
+ wrapper.find('.button-previous').getElement().props.disabled
28
+ ).toBeFalsy()
29
+
30
+ expect(
31
+ wrapper.find('.button-next').getElement().props.disabled
32
+ ).toBeFalsy()
33
+ })
34
+
35
+ it('disables the previous page button when isPreviousDisabled is true', () => {
36
+ const wrapper = shallow(
37
+ <PageControls {...props} isPreviousDisabled={true} />
38
+ )
39
+
40
+ expect(
41
+ wrapper.find('.button-previous').getElement().props.disabled
42
+ ).toBe(true)
43
+
44
+ expect(
45
+ wrapper.find('.button-next').getElement().props.disabled
46
+ ).toBeFalsy()
47
+ })
48
+
49
+ it('disables the next page button when isNextDisabled is true', () => {
50
+ const wrapper = shallow(
51
+ <PageControls {...props} isNextDisabled={true} />
52
+ )
53
+
54
+ expect(
55
+ wrapper.find('.button-previous').getElement().props.disabled
56
+ ).toBeFalsy()
57
+
58
+ expect(wrapper.find('.button-next').getElement().props.disabled).toBe(
59
+ true
60
+ )
61
+ })
62
+
63
+ it('calls the onClick handler with the value for the next page when next is clicked', () => {
64
+ const wrapper = shallow(<PageControls {...props} />)
65
+
66
+ wrapper.find('.button-next').simulate('click')
67
+
68
+ expect(mockOnClick).toHaveBeenCalledTimes(1)
69
+ expect(mockOnClick).toHaveBeenCalledWith(11)
70
+ })
71
+
72
+ it('calls the onClick handler with the value for the previous page when previous is clicked', () => {
73
+ const wrapper = shallow(<PageControls {...props} />)
74
+
75
+ wrapper.find('.button-previous').simulate('click')
76
+
77
+ expect(mockOnClick).toHaveBeenCalledTimes(1)
78
+ expect(mockOnClick).toHaveBeenCalledWith(9)
79
+ })
80
+ })
@@ -0,0 +1,40 @@
1
+ import { SingleSelect } from '@dhis2-ui/select'
2
+ import { shallow } from 'enzyme'
3
+ import React from 'react'
4
+ import * as mockPagers from '../__fixtures__/index.js'
5
+ import { PageSelect, createAvailablePages } from '../page-select.js'
6
+
7
+ describe('<PageSelect />', () => {
8
+ const mockOnSelect = jest.fn()
9
+ const props = {
10
+ dataTest: 'test',
11
+ onChange: mockOnSelect,
12
+ pageSelectText: 'Page',
13
+ ...mockPagers.atTenthPage,
14
+ }
15
+
16
+ beforeEach(() => {
17
+ mockOnSelect.mockClear()
18
+ })
19
+
20
+ it('renders without errors', () => {
21
+ shallow(<PageSelect {...props} />)
22
+ })
23
+
24
+ it('calls the onSelect handler with the value of selected option', () => {
25
+ const wrapper = shallow(<PageSelect {...props} />)
26
+
27
+ wrapper.find(SingleSelect).simulate('change', { selected: '10' })
28
+
29
+ expect(mockOnSelect).toHaveBeenCalledTimes(1)
30
+ expect(mockOnSelect).toHaveBeenCalledWith(10)
31
+ })
32
+
33
+ describe('createAvailablePages helper', () => {
34
+ it('produces an array of strings starting with "1" and ending with the "lenght"', () => {
35
+ const expected = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']
36
+
37
+ expect(createAvailablePages(10)).toEqual(expected)
38
+ })
39
+ })
40
+ })
@@ -0,0 +1,29 @@
1
+ import { SingleSelect } from '@dhis2-ui/select'
2
+ import { shallow } from 'enzyme'
3
+ import React from 'react'
4
+ import * as mockPagers from '../__fixtures__/index.js'
5
+ import { PageSizeSelect } from '../page-size-select.js'
6
+
7
+ describe('<PageSizeSelect />', () => {
8
+ const mockOnSelect = jest.fn()
9
+ const props = {
10
+ dataTest: 'test',
11
+ onChange: mockOnSelect,
12
+ pageSizes: ['5', '10', '20', '30', '40', '50', '75', '100'],
13
+ pageSizeSelectText: 'Page size',
14
+ ...mockPagers.atTenthPage,
15
+ }
16
+
17
+ it('renders without errors', () => {
18
+ shallow(<PageSizeSelect {...props} />)
19
+ })
20
+
21
+ it('calls the onSelect handler with the value of selected option', () => {
22
+ const wrapper = shallow(<PageSizeSelect {...props} />)
23
+
24
+ wrapper.find(SingleSelect).simulate('change', { selected: '10' })
25
+
26
+ expect(mockOnSelect).toHaveBeenCalledTimes(1)
27
+ expect(mockOnSelect).toHaveBeenCalledWith(10)
28
+ })
29
+ })
@@ -0,0 +1,70 @@
1
+ import { shallow } from 'enzyme'
2
+ import React from 'react'
3
+ import { getDefaultPageSummaryText } from '../get-default-page-summary-text.js'
4
+ import { PageSummary } from '../page-summary.js'
5
+
6
+ describe('<PageSummary />', () => {
7
+ const props = {
8
+ dataTest: 'test',
9
+ pageSummaryText: getDefaultPageSummaryText,
10
+ }
11
+
12
+ it('renders without errors', () => {
13
+ shallow(
14
+ <PageSummary
15
+ {...props}
16
+ firstItem={51}
17
+ lastItem={100}
18
+ page={2}
19
+ pageCount={5}
20
+ total={224}
21
+ />
22
+ )
23
+ })
24
+
25
+ it('renders the correct message when both total and lastItem are provided', () => {
26
+ const wrapper = shallow(
27
+ <PageSummary
28
+ {...props}
29
+ firstItem={51}
30
+ lastItem={100}
31
+ page={2}
32
+ pageCount={5}
33
+ total={224}
34
+ />
35
+ )
36
+ const expectedString = 'Page 2 of 5, items 51-100 of 224'
37
+
38
+ expect(wrapper.find('span').text()).toBe(expectedString)
39
+ })
40
+
41
+ it('renders the correct message when only lastItem is provided', () => {
42
+ const wrapper = shallow(
43
+ <PageSummary
44
+ {...props}
45
+ firstItem={51}
46
+ lastItem={100}
47
+ page={2}
48
+ pageCount={5}
49
+ />
50
+ )
51
+ const expectedString = 'Page 2, items 51-100'
52
+
53
+ expect(wrapper.find('span').text()).toBe(expectedString)
54
+ })
55
+
56
+ it('renders the correct message when total is missing and lastItem is not a number', () => {
57
+ const wrapper = shallow(
58
+ <PageSummary
59
+ {...props}
60
+ firstItem={51}
61
+ lastItem={NaN}
62
+ page={2}
63
+ pageCount={5}
64
+ />
65
+ )
66
+ const expectedString = 'Page 2'
67
+
68
+ expect(wrapper.find('span').text()).toBe(expectedString)
69
+ })
70
+ })
@@ -0,0 +1,212 @@
1
+ import '@testing-library/dom'
2
+ import { render } from '@testing-library/react'
3
+ import React from 'react'
4
+ import * as mockPagers from '../__fixtures__/index.js'
5
+ import { Pagination } from '../pagination.js'
6
+
7
+ describe('<Pagination />', () => {
8
+ describe('Pagination with total and totalPages', () => {
9
+ const props = {
10
+ ...mockPagers.atTenthPage,
11
+ onPageChange: () => {},
12
+ onPageSizeChange: () => {},
13
+ }
14
+
15
+ it('renders without errors', () => {
16
+ render(<Pagination {...props} />)
17
+ })
18
+
19
+ it('renders a PageSelect and PageSizeSelect by default', () => {
20
+ const { getByTestId } = render(<Pagination {...props} />)
21
+
22
+ expect(
23
+ getByTestId('dhis2-uiwidgets-pagination-page-select')
24
+ ).toBeInTheDocument()
25
+ expect(
26
+ getByTestId('dhis2-uiwidgets-pagination-pagesize')
27
+ ).toBeInTheDocument()
28
+ })
29
+
30
+ it('renders without a PageSelect when hidePageSelect is true', () => {
31
+ const { getByTestId, queryByTestId } = render(
32
+ <Pagination {...props} hidePageSelect />
33
+ )
34
+
35
+ expect(
36
+ queryByTestId('dhis2-uiwidgets-pagination-page-select')
37
+ ).not.toBeInTheDocument()
38
+ expect(
39
+ getByTestId('dhis2-uiwidgets-pagination-pagesize')
40
+ ).toBeInTheDocument()
41
+ })
42
+
43
+ it('renders without a PageSelect when pageCount is not provided', () => {
44
+ const { getByTestId, queryByTestId } = render(
45
+ <Pagination {...props} pageCount={undefined} />
46
+ )
47
+
48
+ expect(
49
+ queryByTestId('dhis2-uiwidgets-pagination-page-select')
50
+ ).not.toBeInTheDocument()
51
+ expect(
52
+ getByTestId('dhis2-uiwidgets-pagination-pagesize')
53
+ ).toBeInTheDocument()
54
+ })
55
+
56
+ it('renders without a PageSelect when pageCount is 1', () => {
57
+ const { getByTestId, queryByTestId } = render(
58
+ <Pagination {...props} pageCount={1} />
59
+ )
60
+
61
+ expect(
62
+ queryByTestId('dhis2-uiwidgets-pagination-page-select')
63
+ ).not.toBeInTheDocument()
64
+ expect(
65
+ getByTestId('dhis2-uiwidgets-pagination-pagesize')
66
+ ).toBeInTheDocument()
67
+ })
68
+
69
+ it('renders without a PageSelect when pageCount is over 2000', () => {
70
+ const { getByTestId, queryByTestId } = render(
71
+ <Pagination {...props} pageCount={2001} />
72
+ )
73
+
74
+ expect(
75
+ queryByTestId('dhis2-uiwidgets-pagination-page-select')
76
+ ).not.toBeInTheDocument()
77
+ expect(
78
+ getByTestId('dhis2-uiwidgets-pagination-pagesize')
79
+ ).toBeInTheDocument()
80
+ })
81
+
82
+ it('renders without a PageSizeSelect when hidePageSizeSelect is true', () => {
83
+ const { getByTestId, queryByTestId } = render(
84
+ <Pagination {...props} hidePageSizeSelect />
85
+ )
86
+
87
+ expect(
88
+ queryByTestId('dhis2-uiwidgets-pagination-pagesize')
89
+ ).not.toBeInTheDocument()
90
+ expect(
91
+ getByTestId('dhis2-uiwidgets-pagination-page-select')
92
+ ).toBeInTheDocument()
93
+ })
94
+
95
+ it('renders without PageSelect and PageSizeSelect when both are true', () => {
96
+ const { queryByTestId } = render(
97
+ <Pagination {...props} hidePageSelect hidePageSizeSelect />
98
+ )
99
+
100
+ expect(
101
+ queryByTestId('dhis2-uiwidgets-pagination-pagesize')
102
+ ).not.toBeInTheDocument()
103
+ expect(
104
+ queryByTestId('dhis2-uiwidgets-pagination-page-select')
105
+ ).not.toBeInTheDocument()
106
+ })
107
+
108
+ it('enables all elements when disabled is falsy', () => {
109
+ const { getByTestId, getByRole } = render(<Pagination {...props} />)
110
+
111
+ expect(
112
+ getByTestId(
113
+ 'dhis2-uiwidgets-pagination-pagesize'
114
+ ).querySelector('.select .root')
115
+ ).not.toHaveClass('disabled')
116
+ expect(
117
+ getByTestId('dhis2-uiwidgets-pagination-summary').querySelector(
118
+ 'span'
119
+ )
120
+ ).not.toHaveClass('inactive')
121
+ expect(
122
+ getByTestId(
123
+ 'dhis2-uiwidgets-pagination-page-select'
124
+ ).querySelector('.select .root')
125
+ ).not.toHaveClass('disabled')
126
+ expect(getByRole('button', { name: 'Previous' })).not.toBeDisabled()
127
+ expect(getByRole('button', { name: 'Next' })).not.toBeDisabled()
128
+ })
129
+
130
+ it('disables all elements when disabled is true', () => {
131
+ const { getByTestId, getByRole } = render(
132
+ <Pagination {...props} disabled />
133
+ )
134
+
135
+ expect(
136
+ getByTestId(
137
+ 'dhis2-uiwidgets-pagination-pagesize'
138
+ ).querySelector('.select .root')
139
+ ).toHaveClass('disabled')
140
+ expect(
141
+ getByTestId('dhis2-uiwidgets-pagination-summary').querySelector(
142
+ 'span'
143
+ )
144
+ ).toHaveClass('inactive')
145
+ expect(
146
+ getByTestId(
147
+ 'dhis2-uiwidgets-pagination-page-select'
148
+ ).querySelector('.select .root')
149
+ ).toHaveClass('disabled')
150
+ expect(getByRole('button', { name: 'Previous' })).toBeDisabled()
151
+ expect(getByRole('button', { name: 'Next' })).toBeDisabled()
152
+ })
153
+
154
+ it('disables previous button when on the first page', () => {
155
+ const { getByRole } = render(
156
+ <Pagination
157
+ {...mockPagers.atFirstPage}
158
+ onPageChange={() => {}}
159
+ onPageSizeChange={() => {}}
160
+ />
161
+ )
162
+ expect(getByRole('button', { name: 'Previous' })).toBeDisabled()
163
+ expect(getByRole('button', { name: 'Next' })).not.toBeDisabled()
164
+ })
165
+
166
+ it('disables next button when on the last page', () => {
167
+ const { getByRole } = render(
168
+ <Pagination
169
+ {...mockPagers.atLastPage}
170
+ onPageChange={() => {}}
171
+ onPageSizeChange={() => {}}
172
+ />
173
+ )
174
+ expect(getByRole('button', { name: 'Previous' })).not.toBeDisabled()
175
+ expect(getByRole('button', { name: 'Next' })).toBeDisabled()
176
+ })
177
+ })
178
+
179
+ describe('Pagination without total and totalPages', () => {
180
+ const props = {
181
+ ...mockPagers.noTotal,
182
+ pageLength: mockPagers.noTotal.pageSize,
183
+ onPageChange: () => {},
184
+ onPageSizeChange: () => {},
185
+ }
186
+
187
+ it('renders without errors', () => {
188
+ render(<Pagination {...props} />)
189
+ })
190
+
191
+ it('renders with a PageSizeSelect but without a PageSelect', () => {
192
+ const { queryByTestId, getByTestId } = render(
193
+ <Pagination {...props} />
194
+ )
195
+
196
+ expect(
197
+ getByTestId('dhis2-uiwidgets-pagination-pagesize')
198
+ ).toBeInTheDocument()
199
+ expect(
200
+ queryByTestId('dhis2-uiwidgets-pagination-page-select')
201
+ ).not.toBeInTheDocument()
202
+ })
203
+
204
+ it('prevents forward navigation when on the last page', () => {
205
+ const { getByRole } = render(
206
+ <Pagination {...props} {...mockPagers.noTotalAtLastPage} />
207
+ )
208
+ expect(getByRole('button', { name: 'Previous' })).not.toBeDisabled()
209
+ expect(getByRole('button', { name: 'Next' })).toBeDisabled()
210
+ })
211
+ })
212
+ })
@@ -0,0 +1,34 @@
1
+ import i18n from './locales/index.js'
2
+
3
+ const isValidNumber = (input) => typeof input === 'number' && !isNaN(input)
4
+
5
+ export const getDefaultPageSummaryText = ({
6
+ firstItem,
7
+ lastItem,
8
+ page,
9
+ pageCount,
10
+ total,
11
+ }) => {
12
+ if (isValidNumber(total) && isValidNumber(lastItem)) {
13
+ return i18n.t(
14
+ 'Page {{page}} of {{pageCount}}, items {{firstItem}}-{{lastItem}} of {{total}}',
15
+ {
16
+ page,
17
+ pageCount,
18
+ firstItem,
19
+ lastItem,
20
+ total,
21
+ }
22
+ )
23
+ }
24
+
25
+ if (isValidNumber(lastItem)) {
26
+ return i18n.t('Page {{page}}, items {{firstItem}}-{{lastItem}}', {
27
+ page,
28
+ firstItem,
29
+ lastItem,
30
+ })
31
+ }
32
+
33
+ return i18n.t('Page {{page}}', { page })
34
+ }
@@ -0,0 +1,35 @@
1
+ export const getItemRange = ({
2
+ isLastPage,
3
+ page,
4
+ pageLength,
5
+ pageSize,
6
+ total,
7
+ }) => {
8
+ // page is 1-based
9
+ let firstItem = (page - 1) * pageSize + 1
10
+ let lastItem = firstItem + pageSize - 1
11
+
12
+ if (typeof total === 'number') {
13
+ if (total === 0) {
14
+ /*
15
+ * if no items are found, the pager total is 0
16
+ * and the first and last item should be be 0 too
17
+ */
18
+ firstItem = 0
19
+ lastItem = 0
20
+ } else if (lastItem > total) {
21
+ lastItem = total
22
+ }
23
+ }
24
+
25
+ if (typeof pageLength === 'number') {
26
+ lastItem = firstItem + pageLength - 1
27
+ }
28
+
29
+ if (isLastPage && isNaN(total) && isNaN(pageLength)) {
30
+ // impossible to accurately determine the last item
31
+ lastItem = NaN
32
+ }
33
+
34
+ return { firstItem, lastItem }
35
+ }
package/src/index.js ADDED
@@ -0,0 +1 @@
1
+ export { Pagination } from './pagination.js'
@@ -0,0 +1,10 @@
1
+ {
2
+ "Page {{page}} of {{pageCount}}, items {{firstItem}}-{{lastItem}} of {{total}}": "الصفحة {{page}} من {{pageCount}} ، العناصر {{firstItem}} - {{lastItem}} من {{total}}",
3
+ "Page {{page}}, items {{firstItem}}-{{lastItem}}": "الصفحة {{page}} ، العناصر {{firstItem}} - {{lastItem}}",
4
+ "Page {{page}}": "الصفحة {{page}}",
5
+ "Next": "التالي",
6
+ "Page": "الصفحة",
7
+ "Items per page": "عناصر لكل صفحة",
8
+ "Previous": "السابق",
9
+ "You are at page {{page}} showing items {{firstItem}}-{{lastItem}}, but there are {{pageCount}} pages and {{total}} items": "أنت في الصفحة {{page}} تستعرض العناصر {{firstItem}} - {{lastItem}} ، ولكن هناك {{pageCount}} صفحة و {{total}} عنصر"
10
+ }
@@ -0,0 +1,10 @@
1
+ {
2
+ "Page {{page}} of {{pageCount}}, items {{firstItem}}-{{lastItem}} of {{total}}": "",
3
+ "Page {{page}}, items {{firstItem}}-{{lastItem}}": "",
4
+ "Page {{page}}": "",
5
+ "Next": "التالي",
6
+ "Page": "",
7
+ "Items per page": "",
8
+ "Previous": "",
9
+ "You are at page {{page}} showing items {{firstItem}}-{{lastItem}}, but there are {{pageCount}} pages and {{total}} items": ""
10
+ }
@@ -0,0 +1,10 @@
1
+ {
2
+ "Page {{page}} of {{pageCount}}, items {{firstItem}}-{{lastItem}} of {{total}}": "",
3
+ "Page {{page}}, items {{firstItem}}-{{lastItem}}": "",
4
+ "Page {{page}}": "",
5
+ "Next": "",
6
+ "Page": "",
7
+ "Items per page": "",
8
+ "Previous": "পূর্ববর্তী",
9
+ "You are at page {{page}} showing items {{firstItem}}-{{lastItem}}, but there are {{pageCount}} pages and {{total}} items": ""
10
+ }