1 | import _extends from "@babel/runtime/helpers/esm/extends";
|
2 | import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
3 | const _excluded = ["count", "getItemAriaLabel", "onPageChange", "page", "rowsPerPage", "showFirstButton", "showLastButton", "direction", "ownerState", "slotProps", "slots"];
|
4 | var _span, _span2, _span3, _span4;
|
5 | import * as React from 'react';
|
6 | import { useSlotProps } from '../utils';
|
7 | import { jsx as _jsx } from "react/jsx-runtime";
|
8 | import { jsxs as _jsxs } from "react/jsx-runtime";
|
9 | function LastPageIconDefault() {
|
10 | return _span || (_span = _jsx("span", {
|
11 | children: '⇾|'
|
12 | }));
|
13 | }
|
14 | function FirstPageIconDefault() {
|
15 | return _span2 || (_span2 = _jsx("span", {
|
16 | children: '|⇽'
|
17 | }));
|
18 | }
|
19 | function NextPageIconDefault() {
|
20 | return _span3 || (_span3 = _jsx("span", {
|
21 | children: '⇾'
|
22 | }));
|
23 | }
|
24 | function BackPageIconDefault() {
|
25 | return _span4 || (_span4 = _jsx("span", {
|
26 | children: '⇽'
|
27 | }));
|
28 | }
|
29 | function defaultGetAriaLabel(type) {
|
30 | return `Go to ${type} page`;
|
31 | }
|
32 |
|
33 |
|
34 |
|
35 |
|
36 | const TablePaginationActions = React.forwardRef(function TablePaginationActions(props, forwardedRef) {
|
37 | var _slots$root, _slots$firstButton, _slots$lastButton, _slots$nextButton, _slots$backButton, _slots$lastPageIcon, _slots$firstPageIcon, _slots$nextPageIcon, _slots$backPageIcon;
|
38 | const {
|
39 | count,
|
40 | getItemAriaLabel = defaultGetAriaLabel,
|
41 | onPageChange,
|
42 | page,
|
43 | rowsPerPage,
|
44 | showFirstButton = false,
|
45 | showLastButton = false,
|
46 | direction
|
47 |
|
48 | ,
|
49 |
|
50 | slotProps = {},
|
51 | slots = {}
|
52 | } = props,
|
53 | other = _objectWithoutPropertiesLoose(props, _excluded);
|
54 | const ownerState = props;
|
55 | const handleFirstPageButtonClick = event => {
|
56 | onPageChange(event, 0);
|
57 | };
|
58 | const handleBackButtonClick = event => {
|
59 | onPageChange(event, page - 1);
|
60 | };
|
61 | const handleNextButtonClick = event => {
|
62 | onPageChange(event, page + 1);
|
63 | };
|
64 | const handleLastPageButtonClick = event => {
|
65 | onPageChange(event, Math.max(0, Math.ceil(count / rowsPerPage) - 1));
|
66 | };
|
67 | const Root = (_slots$root = slots.root) != null ? _slots$root : 'div';
|
68 | const rootProps = useSlotProps({
|
69 | elementType: Root,
|
70 | externalSlotProps: slotProps.root,
|
71 | externalForwardedProps: other,
|
72 | additionalProps: {
|
73 | ref: forwardedRef
|
74 | },
|
75 | ownerState
|
76 | });
|
77 | const FirstButton = (_slots$firstButton = slots.firstButton) != null ? _slots$firstButton : 'button';
|
78 | const firstButtonProps = useSlotProps({
|
79 | elementType: FirstButton,
|
80 | externalSlotProps: slotProps.firstButton,
|
81 | additionalProps: {
|
82 | onClick: handleFirstPageButtonClick,
|
83 | disabled: page === 0,
|
84 | 'aria-label': getItemAriaLabel('first', page),
|
85 | title: getItemAriaLabel('first', page)
|
86 | },
|
87 | ownerState
|
88 | });
|
89 | const LastButton = (_slots$lastButton = slots.lastButton) != null ? _slots$lastButton : 'button';
|
90 | const lastButtonProps = useSlotProps({
|
91 | elementType: LastButton,
|
92 | externalSlotProps: slotProps.lastButton,
|
93 | additionalProps: {
|
94 | onClick: handleLastPageButtonClick,
|
95 | disabled: page >= Math.ceil(count / rowsPerPage) - 1,
|
96 | 'aria-label': getItemAriaLabel('last', page),
|
97 | title: getItemAriaLabel('last', page)
|
98 | },
|
99 | ownerState
|
100 | });
|
101 | const NextButton = (_slots$nextButton = slots.nextButton) != null ? _slots$nextButton : 'button';
|
102 | const nextButtonProps = useSlotProps({
|
103 | elementType: NextButton,
|
104 | externalSlotProps: slotProps.nextButton,
|
105 | additionalProps: {
|
106 | onClick: handleNextButtonClick,
|
107 | disabled: count !== -1 ? page >= Math.ceil(count / rowsPerPage) - 1 : false,
|
108 | 'aria-label': getItemAriaLabel('next', page),
|
109 | title: getItemAriaLabel('next', page)
|
110 | },
|
111 | ownerState
|
112 | });
|
113 | const BackButton = (_slots$backButton = slots.backButton) != null ? _slots$backButton : 'button';
|
114 | const backButtonProps = useSlotProps({
|
115 | elementType: BackButton,
|
116 | externalSlotProps: slotProps.backButton,
|
117 | additionalProps: {
|
118 | onClick: handleBackButtonClick,
|
119 | disabled: page === 0,
|
120 | 'aria-label': getItemAriaLabel('previous', page),
|
121 | title: getItemAriaLabel('previous', page)
|
122 | },
|
123 | ownerState
|
124 | });
|
125 | const LastPageIcon = (_slots$lastPageIcon = slots.lastPageIcon) != null ? _slots$lastPageIcon : LastPageIconDefault;
|
126 | const FirstPageIcon = (_slots$firstPageIcon = slots.firstPageIcon) != null ? _slots$firstPageIcon : FirstPageIconDefault;
|
127 | const NextPageIcon = (_slots$nextPageIcon = slots.nextPageIcon) != null ? _slots$nextPageIcon : NextPageIconDefault;
|
128 | const BackPageIcon = (_slots$backPageIcon = slots.backPageIcon) != null ? _slots$backPageIcon : BackPageIconDefault;
|
129 | return _jsxs(Root, _extends({}, rootProps, {
|
130 | children: [showFirstButton && _jsx(FirstButton, _extends({}, firstButtonProps, {
|
131 | children: direction === 'rtl' ? _jsx(LastPageIcon, {}) : _jsx(FirstPageIcon, {})
|
132 | })), _jsx(BackButton, _extends({}, backButtonProps, {
|
133 | children: direction === 'rtl' ? _jsx(NextPageIcon, {}) : _jsx(BackPageIcon, {})
|
134 | })), _jsx(NextButton, _extends({}, nextButtonProps, {
|
135 | children: direction === 'rtl' ? _jsx(BackPageIcon, {}) : _jsx(NextPageIcon, {})
|
136 | })), showLastButton && _jsx(LastButton, _extends({}, lastButtonProps, {
|
137 | children: direction === 'rtl' ? _jsx(FirstPageIcon, {}) : _jsx(LastPageIcon, {})
|
138 | }))]
|
139 | }));
|
140 | });
|
141 | export default TablePaginationActions; |
\ | No newline at end of file |