playbook_ui 14.25.0.pre.rc.0 → 14.25.0.pre.rc.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.
- checksums.yaml +4 -4
- data/app/pb_kits/playbook/pb_advanced_table/Components/RegularTableView.tsx +4 -1
- data/app/pb_kits/playbook/pb_advanced_table/Components/TableHeaderCell.tsx +1 -2
- data/app/pb_kits/playbook/pb_advanced_table/advanced_table.test.jsx +56 -0
- data/app/pb_kits/playbook/pb_advanced_table/docs/_advanced_table_padding_control.jsx +60 -0
- data/app/pb_kits/playbook/pb_advanced_table/docs/_advanced_table_padding_control.md +3 -0
- data/app/pb_kits/playbook/pb_advanced_table/docs/_advanced_table_padding_control_per_row.jsx +57 -0
- data/app/pb_kits/playbook/pb_advanced_table/docs/_advanced_table_padding_control_per_row.md +1 -0
- data/app/pb_kits/playbook/pb_advanced_table/docs/example.yml +2 -0
- data/app/pb_kits/playbook/pb_advanced_table/docs/index.js +3 -1
- data/app/pb_kits/playbook/pb_pagination/_pagination.test.jsx +212 -0
- data/app/pb_kits/playbook/pb_pagination/_pagination.tsx +8 -1
- data/app/pb_kits/playbook/pb_pagination/docs/_pagination_external_control.jsx +112 -0
- data/app/pb_kits/playbook/pb_pagination/docs/_pagination_external_control_react.md +3 -0
- data/app/pb_kits/playbook/pb_pagination/docs/example.yml +1 -0
- data/app/pb_kits/playbook/pb_pagination/docs/index.js +1 -0
- data/dist/chunks/{_weekday_stacked-CJIFKKe7.js → _weekday_stacked-CitcNYFp.js} +1 -1
- data/dist/chunks/vendor.js +1 -1
- data/dist/menu.yml +1 -1
- data/dist/playbook-doc.js +1 -1
- data/lib/playbook/version.rb +1 -1
- metadata +10 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f40a6c3f571115d04deb79b25929f5db0e7d3574b3e8621748c799c197478e6e
|
4
|
+
data.tar.gz: 149c9509d0200a66d3f0523e57a2d75ed6254b90ad54e8b98a7c8ed8fbb21faa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 25afeb9d1bb9418e5e2e4ce343d8899bd2a546f9e2e67384359b1315db270d674044c6f6ef0997bc19978f40f8000afc335fee6d446331905d426799a435cb99
|
7
|
+
data.tar.gz: 0baf6140f040646b25171d0150fe074c54af0a3bd276eab0ea925c8eb99ca0ad5a061c836100f16bf6699f4de3d86d37d91d654267cedde5ad6a7ba1702be98e
|
@@ -58,7 +58,9 @@ const TableCellRenderer = ({
|
|
58
58
|
// Find the “owning” colDefinition by accessor. Needed for multi column logic
|
59
59
|
const colDef = findColumnDefByAccessor(columnDefinitions ?? [], column.id)
|
60
60
|
const cellAlignment = colDef?.columnStyling?.cellAlignment ?? "right"
|
61
|
-
|
61
|
+
const paddingValue = colDef?.columnStyling?.cellPadding ?? customRowStyle?.cellPadding
|
62
|
+
const paddingClass = paddingValue ? `p_${paddingValue}` : undefined
|
63
|
+
|
62
64
|
return (
|
63
65
|
<td
|
64
66
|
align={cellAlignment}
|
@@ -68,6 +70,7 @@ const TableCellRenderer = ({
|
|
68
70
|
isPinnedLeft && 'pinned-left',
|
69
71
|
stickyLeftColumn && stickyLeftColumn.length > 0 && isPinnedLeft && 'sticky-left',
|
70
72
|
isLastCell && 'last-cell',
|
73
|
+
paddingClass
|
71
74
|
)}
|
72
75
|
key={`${cell.id}-data`}
|
73
76
|
style={{
|
@@ -113,7 +113,6 @@ export const TableHeaderCell = ({
|
|
113
113
|
return visibleSiblings.at(-1) === header.column;
|
114
114
|
})();
|
115
115
|
|
116
|
-
|
117
116
|
const cellClassName = classnames(
|
118
117
|
"table-header-cells",
|
119
118
|
`${showActionsBar && isActionBarVisible && "header-cells-with-actions"}`,
|
@@ -122,7 +121,7 @@ const cellClassName = classnames(
|
|
122
121
|
{ "pinned-left": responsive === "scroll" && isPinnedLeft },
|
123
122
|
isLastHeaderCell ? "last-header-cell" : "",
|
124
123
|
stickyLeftColumn && stickyLeftColumn.length > 0 && isPinnedLeft ? 'sticky-left' : "",
|
125
|
-
|
124
|
+
colDef?.columnStyling?.headerPadding && `p_${colDef?.columnStyling?.headerPadding}`
|
126
125
|
);
|
127
126
|
|
128
127
|
const cellId = `${loading ?
|
@@ -651,6 +651,36 @@ test("columnStyling.cellAlignment sets each <td> align attribute as expected", (
|
|
651
651
|
expect(firstEnrollmentCell).toHaveAttribute("align", "left");
|
652
652
|
});
|
653
653
|
|
654
|
+
test("columnStyling.cellPadding sets cell padding", () => {
|
655
|
+
const styledColumnDefs = [
|
656
|
+
{
|
657
|
+
accessor: "year",
|
658
|
+
label: "Year",
|
659
|
+
cellAccessors: ["quarter", "month", "day"],
|
660
|
+
},
|
661
|
+
{
|
662
|
+
accessor: "newEnrollments",
|
663
|
+
label: "New Enrollments",
|
664
|
+
columnStyling: { cellPadding: "none" },
|
665
|
+
},
|
666
|
+
{
|
667
|
+
accessor: "scheduledMeetings",
|
668
|
+
label: "Scheduled Meetings",
|
669
|
+
},
|
670
|
+
];
|
671
|
+
|
672
|
+
render(
|
673
|
+
<AdvancedTable
|
674
|
+
columnDefinitions={styledColumnDefs}
|
675
|
+
data={{ testid: testId }}
|
676
|
+
tableData={MOCK_DATA}
|
677
|
+
/>
|
678
|
+
);
|
679
|
+
|
680
|
+
const firstEnrollmentCell = screen.getAllByText("20")[0].closest("td");
|
681
|
+
expect(firstEnrollmentCell).toHaveClass('p_none')
|
682
|
+
});
|
683
|
+
|
654
684
|
test("renders virtualized table rows and header", () => {
|
655
685
|
render(
|
656
686
|
<AdvancedTable
|
@@ -694,6 +724,32 @@ test("rowStyling prop works as expected", () => {
|
|
694
724
|
expect(row1).toHaveStyle({backgroundColor: colors.white, color: colors.black})
|
695
725
|
})
|
696
726
|
|
727
|
+
test("rowStyling prop to allow padding control", () => {
|
728
|
+
const rowStyling = [
|
729
|
+
{
|
730
|
+
rowId: "1",
|
731
|
+
cellPadding: "lg"
|
732
|
+
},
|
733
|
+
];
|
734
|
+
|
735
|
+
render(
|
736
|
+
<AdvancedTable
|
737
|
+
columnDefinitions={columnDefinitions}
|
738
|
+
data={{ testid: testId }}
|
739
|
+
rowStyling={rowStyling}
|
740
|
+
tableData={MOCK_DATA_WITH_ID}
|
741
|
+
/>
|
742
|
+
)
|
743
|
+
|
744
|
+
const kit = screen.getByTestId(testId)
|
745
|
+
const tableBody = kit.querySelector('tbody')
|
746
|
+
const row1 = tableBody.querySelector('tr:nth-child(1)')
|
747
|
+
const cells = row1.querySelectorAll("td");
|
748
|
+
cells.forEach((cell) => {
|
749
|
+
expect(cell.classList.contains("p_lg")).toBe(true);
|
750
|
+
});
|
751
|
+
})
|
752
|
+
|
697
753
|
test("Sort icon renders with enableSort on individual columns", () => {
|
698
754
|
render(
|
699
755
|
<AdvancedTable
|
@@ -0,0 +1,60 @@
|
|
1
|
+
import React from "react"
|
2
|
+
import AdvancedTable from '../_advanced_table'
|
3
|
+
import Background from '../../pb_background/_background'
|
4
|
+
import MOCK_DATA from "./advanced_table_mock_data_with_id.json"
|
5
|
+
|
6
|
+
const AdvancedTablePaddingControl = (props) => {
|
7
|
+
const columnDefinitions = [
|
8
|
+
{
|
9
|
+
accessor: "year",
|
10
|
+
label: "Year",
|
11
|
+
cellAccessors: ["quarter", "month", "day"],
|
12
|
+
},
|
13
|
+
{
|
14
|
+
accessor: "newEnrollments",
|
15
|
+
label: "New Enrollments",
|
16
|
+
columnStyling:{cellPadding: "none"},
|
17
|
+
customRenderer: (row, value) => (
|
18
|
+
<Background
|
19
|
+
backgroundColor={row.original.newEnrollments > 20 ? "success_secondary" : "warning_secondary"}
|
20
|
+
padding="xs"
|
21
|
+
>
|
22
|
+
{value}
|
23
|
+
</Background>
|
24
|
+
),
|
25
|
+
|
26
|
+
},
|
27
|
+
{
|
28
|
+
accessor: "scheduledMeetings",
|
29
|
+
label: "Scheduled Meetings",
|
30
|
+
},
|
31
|
+
{
|
32
|
+
accessor: "attendanceRate",
|
33
|
+
label: "Attendance Rate",
|
34
|
+
},
|
35
|
+
{
|
36
|
+
accessor: "completedClasses",
|
37
|
+
label: "Completed Classes",
|
38
|
+
},
|
39
|
+
{
|
40
|
+
accessor: "classCompletionRate",
|
41
|
+
label: "Class Completion Rate",
|
42
|
+
},
|
43
|
+
{
|
44
|
+
accessor: "graduatedStudents",
|
45
|
+
label: "Graduated Students",
|
46
|
+
},
|
47
|
+
]
|
48
|
+
|
49
|
+
return (
|
50
|
+
<div>
|
51
|
+
<AdvancedTable
|
52
|
+
columnDefinitions={columnDefinitions}
|
53
|
+
tableData={MOCK_DATA}
|
54
|
+
{...props}
|
55
|
+
/>
|
56
|
+
</div>
|
57
|
+
)
|
58
|
+
}
|
59
|
+
|
60
|
+
export default AdvancedTablePaddingControl
|
@@ -0,0 +1,3 @@
|
|
1
|
+
`columnStyling` can also be used to control padding on all cells in a given column via the use of the `cellPadding` key/value pair. `cellPadding` lets you use 'xxs', 'xs', 'sm', 'md', 'lg', 'xl' and 'none'.
|
2
|
+
|
3
|
+
This control can be used in conjunction with the `customRenderer` item within each columnDefinition to achieve custom background colors for individual cells as seen here.
|
@@ -0,0 +1,57 @@
|
|
1
|
+
import React from "react"
|
2
|
+
import AdvancedTable from '../_advanced_table'
|
3
|
+
import MOCK_DATA from "./advanced_table_mock_data_with_id.json"
|
4
|
+
|
5
|
+
const AdvancedTablePaddingControlPerRow = (props) => {
|
6
|
+
const columnDefinitions = [
|
7
|
+
{
|
8
|
+
accessor: "year",
|
9
|
+
label: "Year",
|
10
|
+
cellAccessors: ["quarter", "month", "day"],
|
11
|
+
},
|
12
|
+
{
|
13
|
+
accessor: "newEnrollments",
|
14
|
+
label: "New Enrollments",
|
15
|
+
},
|
16
|
+
{
|
17
|
+
accessor: "scheduledMeetings",
|
18
|
+
label: "Scheduled Meetings",
|
19
|
+
},
|
20
|
+
{
|
21
|
+
accessor: "attendanceRate",
|
22
|
+
label: "Attendance Rate",
|
23
|
+
},
|
24
|
+
{
|
25
|
+
accessor: "completedClasses",
|
26
|
+
label: "Completed Classes",
|
27
|
+
},
|
28
|
+
{
|
29
|
+
accessor: "classCompletionRate",
|
30
|
+
label: "Class Completion Rate",
|
31
|
+
},
|
32
|
+
{
|
33
|
+
accessor: "graduatedStudents",
|
34
|
+
label: "Graduated Students",
|
35
|
+
},
|
36
|
+
]
|
37
|
+
|
38
|
+
const rowStyling = [
|
39
|
+
{
|
40
|
+
rowId: "1",
|
41
|
+
cellPadding:"md"
|
42
|
+
},
|
43
|
+
];
|
44
|
+
|
45
|
+
return (
|
46
|
+
<div>
|
47
|
+
<AdvancedTable
|
48
|
+
columnDefinitions={columnDefinitions}
|
49
|
+
rowStyling={rowStyling}
|
50
|
+
tableData={MOCK_DATA}
|
51
|
+
{...props}
|
52
|
+
/>
|
53
|
+
</div>
|
54
|
+
)
|
55
|
+
}
|
56
|
+
|
57
|
+
export default AdvancedTablePaddingControlPerRow
|
@@ -0,0 +1 @@
|
|
1
|
+
`rowStyling` can also be used to control padding on all cells in a given row via the use of the `cellPadding` key/value pair as shown here. `cellPadding` lets you use 'xxs', 'xs', 'sm', 'md', 'lg', 'xl' and 'none'.
|
@@ -68,8 +68,10 @@ examples:
|
|
68
68
|
- advanced_table_column_visibility_multi: Column Visibility Control with Multi-Header Columns
|
69
69
|
- advanced_table_scrollbar_none: Advanced Table Scrollbar None
|
70
70
|
- advanced_table_row_styling: Row Styling
|
71
|
+
- advanced_table_padding_control_per_row: Padding Control using Row Styling
|
71
72
|
- advanced_table_column_styling: Column Styling
|
72
73
|
- advanced_table_column_styling_column_headers: Column Styling with Multiple Headers
|
74
|
+
- advanced_table_padding_control: Padding Control using Column Styling
|
73
75
|
- advanced_table_column_border_color: Column Group Border Color
|
74
76
|
- advanced_table_fullscreen: Fullscreen
|
75
77
|
- advanced_table_infinite_scroll: Infinite Scroll
|
@@ -43,4 +43,6 @@ export {default as AdvancedTableWithCustomHeader} from './_advanced_table_with_c
|
|
43
43
|
export { default as AdvancedTableCustomSort } from './_advanced_table_custom_sort.jsx'
|
44
44
|
export { default as AdvancedTableWithCustomHeaderMultiHeader } from './_advanced_table_with_custom_header_multi_header.jsx'
|
45
45
|
export { default as AdvancedTableSortPerColumn } from './_advanced_table_sort_per_column.jsx'
|
46
|
-
export { default as AdvancedTableSortPerColumnForMultiColumn } from './_advanced_table_sort_per_column_for_multi_column.jsx'
|
46
|
+
export { default as AdvancedTableSortPerColumnForMultiColumn } from './_advanced_table_sort_per_column_for_multi_column.jsx'
|
47
|
+
export { default as AdvancedTablePaddingControl } from './_advanced_table_padding_control.jsx'
|
48
|
+
export { default as AdvancedTablePaddingControlPerRow } from './_advanced_table_padding_control_per_row.jsx'
|
@@ -0,0 +1,212 @@
|
|
1
|
+
import React from 'react'
|
2
|
+
import { ensureAccessible, renderKit, render, fireEvent, screen } from '../utilities/test-utils'
|
3
|
+
import Pagination from './_pagination'
|
4
|
+
|
5
|
+
const defaultProps = {
|
6
|
+
data: { testid: 'pagination-test' },
|
7
|
+
total: 10,
|
8
|
+
current: 1,
|
9
|
+
range: 5,
|
10
|
+
}
|
11
|
+
|
12
|
+
describe('Pagination Component', () => {
|
13
|
+
test('returns namespaced class name', () => {
|
14
|
+
const kit = renderKit(Pagination, defaultProps)
|
15
|
+
expect(kit).toBeInTheDocument()
|
16
|
+
expect(kit).toHaveClass('pb_paginate')
|
17
|
+
})
|
18
|
+
|
19
|
+
it("should be accessible", async () => {
|
20
|
+
ensureAccessible(Pagination, defaultProps)
|
21
|
+
})
|
22
|
+
|
23
|
+
test('renders with default props', () => {
|
24
|
+
render(<Pagination {...defaultProps} />)
|
25
|
+
|
26
|
+
const pagination = screen.getByTestId('pagination-test')
|
27
|
+
expect(pagination).toBeInTheDocument()
|
28
|
+
expect(pagination).toHaveClass('pb_paginate')
|
29
|
+
})
|
30
|
+
|
31
|
+
test('renders pagination buttons correctly', () => {
|
32
|
+
render(<Pagination {...defaultProps} />)
|
33
|
+
|
34
|
+
expect(screen.getByText('1')).toBeInTheDocument()
|
35
|
+
expect(screen.getByText('2')).toBeInTheDocument()
|
36
|
+
expect(screen.getByText('3')).toBeInTheDocument()
|
37
|
+
expect(screen.getByText('4')).toBeInTheDocument()
|
38
|
+
expect(screen.getByText('5')).toBeInTheDocument()
|
39
|
+
|
40
|
+
// Check for navigation arrows by looking for the li elements with specific classes
|
41
|
+
const leftArrow = document.querySelector('.pagination-left')
|
42
|
+
const rightArrow = document.querySelector('.pagination-right')
|
43
|
+
expect(leftArrow).toBeInTheDocument()
|
44
|
+
expect(rightArrow).toBeInTheDocument()
|
45
|
+
})
|
46
|
+
|
47
|
+
test('highlights current page as active', () => {
|
48
|
+
render(<Pagination {...defaultProps}
|
49
|
+
current={3}
|
50
|
+
/>)
|
51
|
+
|
52
|
+
const activePage = screen.getByText('3')
|
53
|
+
expect(activePage).toHaveClass('active')
|
54
|
+
})
|
55
|
+
|
56
|
+
test('calls onChange when page is clicked', () => {
|
57
|
+
const mockOnChange = jest.fn()
|
58
|
+
render(<Pagination {...defaultProps}
|
59
|
+
onChange={mockOnChange}
|
60
|
+
/>)
|
61
|
+
|
62
|
+
const pageButton = screen.getByText('3')
|
63
|
+
fireEvent.click(pageButton)
|
64
|
+
|
65
|
+
expect(mockOnChange).toHaveBeenCalledWith(3)
|
66
|
+
})
|
67
|
+
|
68
|
+
test('disables left arrow on first page', () => {
|
69
|
+
render(<Pagination {...defaultProps}
|
70
|
+
current={1}
|
71
|
+
/>)
|
72
|
+
|
73
|
+
const leftArrow = document.querySelector('.pagination-left')
|
74
|
+
expect(leftArrow).toHaveClass('disabled')
|
75
|
+
})
|
76
|
+
|
77
|
+
test('disables right arrow on last page', () => {
|
78
|
+
render(<Pagination {...defaultProps}
|
79
|
+
current={10}
|
80
|
+
/>)
|
81
|
+
|
82
|
+
const rightArrow = document.querySelector('.pagination-right')
|
83
|
+
expect(rightArrow).toHaveClass('disabled')
|
84
|
+
})
|
85
|
+
|
86
|
+
test('does not render when total is 1 or less', () => {
|
87
|
+
const { container } = render(<Pagination {...defaultProps}
|
88
|
+
total={1}
|
89
|
+
/>)
|
90
|
+
|
91
|
+
expect(container.firstChild).toBeNull()
|
92
|
+
})
|
93
|
+
|
94
|
+
test('renders with custom className', () => {
|
95
|
+
render(<Pagination {...defaultProps}
|
96
|
+
className="custom-class"
|
97
|
+
/>)
|
98
|
+
|
99
|
+
const pagination = screen.getByTestId('pagination-test')
|
100
|
+
expect(pagination).toHaveClass('custom-class')
|
101
|
+
})
|
102
|
+
|
103
|
+
test('renders with custom id', () => {
|
104
|
+
render(<Pagination {...defaultProps}
|
105
|
+
id="custom-id"
|
106
|
+
/>)
|
107
|
+
|
108
|
+
const pagination = screen.getByTestId('pagination-test')
|
109
|
+
expect(pagination).toHaveAttribute('id', 'custom-id')
|
110
|
+
})
|
111
|
+
|
112
|
+
test('renders with custom range', () => {
|
113
|
+
render(<Pagination {...defaultProps}
|
114
|
+
range={3}
|
115
|
+
/>)
|
116
|
+
|
117
|
+
expect(screen.getByText('1')).toBeInTheDocument()
|
118
|
+
expect(screen.getByText('2')).toBeInTheDocument()
|
119
|
+
expect(screen.getByText('3')).toBeInTheDocument()
|
120
|
+
expect(screen.getByText('9')).toBeInTheDocument()
|
121
|
+
expect(screen.getByText('10')).toBeInTheDocument()
|
122
|
+
})
|
123
|
+
|
124
|
+
test('handles large number of pages correctly', () => {
|
125
|
+
render(<Pagination {...defaultProps}
|
126
|
+
current={50}
|
127
|
+
range={5}
|
128
|
+
total={100}
|
129
|
+
/>)
|
130
|
+
|
131
|
+
const pagination = screen.getByTestId('pagination-test')
|
132
|
+
expect(pagination).toBeInTheDocument()
|
133
|
+
expect(pagination).toHaveClass('pb_paginate')
|
134
|
+
|
135
|
+
|
136
|
+
expect(screen.getByText('48')).toBeInTheDocument()
|
137
|
+
expect(screen.getByText('49')).toBeInTheDocument()
|
138
|
+
expect(screen.getByText('50')).toBeInTheDocument()
|
139
|
+
expect(screen.getByText('51')).toBeInTheDocument()
|
140
|
+
expect(screen.getByText('52')).toBeInTheDocument()
|
141
|
+
})
|
142
|
+
|
143
|
+
test('syncs with external current prop changes', () => {
|
144
|
+
const { rerender } = render(<Pagination {...defaultProps}
|
145
|
+
current={1}
|
146
|
+
/>)
|
147
|
+
|
148
|
+
expect(screen.getByText('1')).toHaveClass('active')
|
149
|
+
|
150
|
+
rerender(<Pagination {...defaultProps}
|
151
|
+
current={3}
|
152
|
+
/>)
|
153
|
+
|
154
|
+
expect(screen.getByText('3')).toHaveClass('active')
|
155
|
+
expect(screen.getByText('1')).not.toHaveClass('active')
|
156
|
+
})
|
157
|
+
|
158
|
+
test('validates current prop is within valid range', () => {
|
159
|
+
const { rerender } = render(<Pagination {...defaultProps}
|
160
|
+
current={1}
|
161
|
+
/>)
|
162
|
+
|
163
|
+
rerender(<Pagination {...defaultProps}
|
164
|
+
current={0}
|
165
|
+
/>)
|
166
|
+
|
167
|
+
expect(screen.getByText('1')).toHaveClass('active')
|
168
|
+
|
169
|
+
rerender(<Pagination {...defaultProps}
|
170
|
+
current={15}
|
171
|
+
/>)
|
172
|
+
|
173
|
+
expect(screen.getByText('1')).toHaveClass('active')
|
174
|
+
})
|
175
|
+
|
176
|
+
test('handles htmlOptions props', () => {
|
177
|
+
const htmlOptions = { 'data-test': 'test-value' }
|
178
|
+
render(<Pagination {...defaultProps}
|
179
|
+
htmlOptions={htmlOptions}
|
180
|
+
/>)
|
181
|
+
|
182
|
+
const pagination = screen.getByTestId('pagination-test')
|
183
|
+
expect(pagination).toHaveAttribute('data-test', 'test-value')
|
184
|
+
})
|
185
|
+
|
186
|
+
test('renders first and last page buttons when range is small', () => {
|
187
|
+
render(<Pagination {...defaultProps}
|
188
|
+
current={10}
|
189
|
+
range={3}
|
190
|
+
total={20}
|
191
|
+
/>)
|
192
|
+
|
193
|
+
expect(screen.getByText('1')).toBeInTheDocument()
|
194
|
+
expect(screen.getByText('20')).toBeInTheDocument()
|
195
|
+
|
196
|
+
expect(screen.getByText('9')).toBeInTheDocument()
|
197
|
+
expect(screen.getByText('10')).toBeInTheDocument()
|
198
|
+
expect(screen.getByText('11')).toBeInTheDocument()
|
199
|
+
})
|
200
|
+
|
201
|
+
test('renders second and second-to-last page buttons when needed', () => {
|
202
|
+
render(<Pagination {...defaultProps}
|
203
|
+
current={10}
|
204
|
+
range={3}
|
205
|
+
total={20}
|
206
|
+
/>)
|
207
|
+
|
208
|
+
expect(screen.getByText('2')).toBeInTheDocument()
|
209
|
+
|
210
|
+
expect(screen.getByText('19')).toBeInTheDocument()
|
211
|
+
})
|
212
|
+
})
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import React, { useState } from "react";
|
1
|
+
import React, { useState, useEffect } from "react";
|
2
2
|
import classnames from 'classnames'
|
3
3
|
import { GlobalProps, globalProps } from '../utilities/globalProps'
|
4
4
|
import { buildAriaProps, buildCss, buildDataProps, buildHtmlProps } from '../utilities/props'
|
@@ -123,6 +123,13 @@ const Pagination = ( props: PaginationProps) => {
|
|
123
123
|
|
124
124
|
return buttons;
|
125
125
|
};
|
126
|
+
|
127
|
+
// Sync internal state with external current prop
|
128
|
+
useEffect(() => {
|
129
|
+
if (current >= 1 && current <= total) {
|
130
|
+
setCurrentPage(current);
|
131
|
+
}
|
132
|
+
}, [current, total]);
|
126
133
|
|
127
134
|
|
128
135
|
const ariaProps = buildAriaProps(aria)
|
@@ -0,0 +1,112 @@
|
|
1
|
+
import React, { useState } from "react";
|
2
|
+
import Flex from '../../pb_flex/_flex'
|
3
|
+
import Pagination from '../../pb_pagination/_pagination'
|
4
|
+
import Select from '../../pb_select/_select'
|
5
|
+
import Table from '../../pb_table/_table'
|
6
|
+
|
7
|
+
import { data } from "./data";
|
8
|
+
|
9
|
+
const PaginationExternalControl = (props) => {
|
10
|
+
const [totalItems, setTotalItems] = useState(20);
|
11
|
+
const [itemsPerPage, setItemsPerPage] = useState(5);
|
12
|
+
const [currentPage, setCurrentPage] = useState(1);
|
13
|
+
|
14
|
+
const totalPages = Math.ceil(totalItems / itemsPerPage);
|
15
|
+
|
16
|
+
const handlePageChange = (page) => {
|
17
|
+
setCurrentPage(page);
|
18
|
+
};
|
19
|
+
|
20
|
+
const limitedData = data.slice(0, totalItems);
|
21
|
+
const startIndex = (currentPage - 1) * itemsPerPage;
|
22
|
+
const paginatedItems = limitedData.slice(startIndex, startIndex + itemsPerPage);
|
23
|
+
|
24
|
+
const handleTotalItemsChange = (event) => {
|
25
|
+
const value = Number(event.target.value);
|
26
|
+
setTotalItems(value);
|
27
|
+
setCurrentPage(1);
|
28
|
+
};
|
29
|
+
|
30
|
+
const handleItemsPerPageChange = (event) => {
|
31
|
+
const value = Number(event.target.value);
|
32
|
+
setItemsPerPage(value);
|
33
|
+
setCurrentPage(1);
|
34
|
+
};
|
35
|
+
|
36
|
+
return (
|
37
|
+
<>
|
38
|
+
<Flex gap="sm">
|
39
|
+
<Select
|
40
|
+
label="Total Items"
|
41
|
+
onChange={handleTotalItemsChange}
|
42
|
+
options={[
|
43
|
+
{ value: "5", text: "5" },
|
44
|
+
{ value: "10", text: "10" },
|
45
|
+
{ value: "20", text: "20" }
|
46
|
+
]}
|
47
|
+
size="sm"
|
48
|
+
value={String(totalItems)}
|
49
|
+
{...props}
|
50
|
+
/>
|
51
|
+
|
52
|
+
<Select
|
53
|
+
label="Items per Page"
|
54
|
+
onChange={handleItemsPerPageChange}
|
55
|
+
options={[
|
56
|
+
{ value: "3", text: "3" },
|
57
|
+
{ value: "5", text: "5" },
|
58
|
+
{ value: "10", text: "10" }
|
59
|
+
]}
|
60
|
+
size="sm"
|
61
|
+
value={String(itemsPerPage)}
|
62
|
+
{...props}
|
63
|
+
/>
|
64
|
+
</Flex>
|
65
|
+
|
66
|
+
<Pagination
|
67
|
+
current={currentPage}
|
68
|
+
key={`pagination-top-${currentPage}`}
|
69
|
+
marginBottom="xs"
|
70
|
+
onChange={handlePageChange}
|
71
|
+
range={5}
|
72
|
+
total={totalPages}
|
73
|
+
{...props}
|
74
|
+
/>
|
75
|
+
<Table
|
76
|
+
marginBottom="xs"
|
77
|
+
responsive="none"
|
78
|
+
size="sm"
|
79
|
+
{...props}
|
80
|
+
>
|
81
|
+
<Table.Head>
|
82
|
+
<Table.Row>
|
83
|
+
<Table.Header>{"Column 1"}</Table.Header>
|
84
|
+
<Table.Header>{"Column 2"}</Table.Header>
|
85
|
+
<Table.Header>{"Column 3"}</Table.Header>
|
86
|
+
<Table.Header>{"Column 4"}</Table.Header>
|
87
|
+
<Table.Header>{"Column 5"}</Table.Header>
|
88
|
+
</Table.Row>
|
89
|
+
</Table.Head>
|
90
|
+
<Table.Body>
|
91
|
+
{paginatedItems.map((row, index) => (
|
92
|
+
<Table.Row key={index}>
|
93
|
+
{row.map((cell, cellIndex) => (
|
94
|
+
<Table.Cell key={cellIndex}>{cell}</Table.Cell>
|
95
|
+
))}
|
96
|
+
</Table.Row>
|
97
|
+
))}
|
98
|
+
</Table.Body>
|
99
|
+
</Table>
|
100
|
+
<Pagination
|
101
|
+
current={currentPage}
|
102
|
+
key={`pagination-bottom-${currentPage}`}
|
103
|
+
onChange={handlePageChange}
|
104
|
+
range={5}
|
105
|
+
total={totalPages}
|
106
|
+
{...props}
|
107
|
+
/>
|
108
|
+
</>
|
109
|
+
)
|
110
|
+
}
|
111
|
+
|
112
|
+
export default PaginationExternalControl
|
@@ -0,0 +1,3 @@
|
|
1
|
+
The Pagination component supports external control of the current page. This allows for programmatically reseting or changing the current page when filters or other criteria change, without needing to unmount and remount the component.
|
2
|
+
|
3
|
+
In this example, changing the "Total Items" or "Items per Page" dropdowns will automatically reset the pagination to page 1, demonstrating how external control works. The pagination component will update its internal state to reflect the new `current` prop value.
|