@canonical/react-components 0.49.0 → 0.50.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.
- package/dist/components/TablePagination/TablePagination.d.ts +44 -4
- package/dist/components/TablePagination/TablePagination.js +61 -97
- package/dist/components/TablePagination/TablePaginationControls/TablePaginationControls.d.ts +5 -15
- package/dist/components/TablePagination/TablePaginationControls/TablePaginationControls.js +43 -10
- package/dist/components/TablePagination/utils.d.ts +22 -0
- package/dist/components/TablePagination/utils.js +65 -0
- package/package.json +1 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React, { HTMLAttributes, PropsWithChildren, ReactNode } from "react";
|
|
2
2
|
import "./TablePagination.scss";
|
|
3
|
-
export type
|
|
3
|
+
export type BasePaginationProps = {
|
|
4
4
|
/**
|
|
5
5
|
* list of data elements to be paginated. This component is un-opinionated about
|
|
6
6
|
* the structure of the data but it should be identical to the data structure
|
|
@@ -9,7 +9,7 @@ export type Props = PropsWithChildren<{
|
|
|
9
9
|
data: unknown[];
|
|
10
10
|
/**
|
|
11
11
|
* prop name of the child table component that receives paginated data.
|
|
12
|
-
* default value is set to
|
|
12
|
+
* default value is set to `rows`, which is the data prop for the `MainTable` component
|
|
13
13
|
*/
|
|
14
14
|
dataForwardProp?: string;
|
|
15
15
|
/**
|
|
@@ -32,6 +32,46 @@ export type Props = PropsWithChildren<{
|
|
|
32
32
|
* place the pagination component above or below the table?
|
|
33
33
|
*/
|
|
34
34
|
position?: "above" | "below";
|
|
35
|
-
}
|
|
36
|
-
|
|
35
|
+
};
|
|
36
|
+
export type ExternalControlProps = BasePaginationProps & {
|
|
37
|
+
/**
|
|
38
|
+
* Whether the component will be controlled via external state.
|
|
39
|
+
*/
|
|
40
|
+
externallyControlled?: true;
|
|
41
|
+
/**
|
|
42
|
+
* the total number of items available within the data. This prop is only relevant
|
|
43
|
+
* and will be required if `externallyControlled` is set to `true`.
|
|
44
|
+
*/
|
|
45
|
+
totalItems: number;
|
|
46
|
+
/**
|
|
47
|
+
* the current page that's showing. This prop is only relevant and will be required
|
|
48
|
+
* if `externallyControlled` is set to `true`.
|
|
49
|
+
*/
|
|
50
|
+
currentPage: number;
|
|
51
|
+
/**
|
|
52
|
+
* size per page. This prop is only relevant and will be required if
|
|
53
|
+
* `externallyControlled` is set to `true`.
|
|
54
|
+
*/
|
|
55
|
+
pageSize: number;
|
|
56
|
+
/**
|
|
57
|
+
* callback indicating a page change event to the parent component.
|
|
58
|
+
* This prop is only relevant and will be required if `externallyControlled` is set
|
|
59
|
+
* to `true`.
|
|
60
|
+
*/
|
|
61
|
+
onPageChange: (page: number) => void;
|
|
62
|
+
/**
|
|
63
|
+
* callback indicating a page size change event to the parent component.
|
|
64
|
+
* This prop is only relevant and will be required if `externallyControlled` is set
|
|
65
|
+
* to `true`.
|
|
66
|
+
*/
|
|
67
|
+
onPageSizeChange: (pageSize: number) => void;
|
|
68
|
+
};
|
|
69
|
+
export type InternalControlProps = BasePaginationProps & {
|
|
70
|
+
/**
|
|
71
|
+
* Whether the component will be controlled via external state.
|
|
72
|
+
*/
|
|
73
|
+
externallyControlled?: false;
|
|
74
|
+
};
|
|
75
|
+
export type Props = PropsWithChildren<ExternalControlProps | InternalControlProps> & HTMLAttributes<HTMLDivElement>;
|
|
76
|
+
declare const TablePagination: (props: Props) => React.JSX.Element;
|
|
37
77
|
export default TablePagination;
|
|
@@ -5,121 +5,85 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
var _react = _interopRequireWildcard(require("react"));
|
|
8
|
-
var _classnames = _interopRequireDefault(require("classnames"));
|
|
9
|
-
var _hooks = require("../../hooks");
|
|
10
|
-
var _Select = _interopRequireDefault(require("../Select"));
|
|
11
|
-
var _TablePaginationControls = _interopRequireDefault(require("./TablePaginationControls"));
|
|
12
8
|
require("./TablePagination.scss");
|
|
9
|
+
var _TablePaginationControls = _interopRequireDefault(require("./TablePaginationControls"));
|
|
10
|
+
var _utils = require("./utils");
|
|
11
|
+
var _hooks = require("../../hooks");
|
|
13
12
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
14
13
|
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
15
14
|
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
16
15
|
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
* 'small screen' in this case is relative to the width of the description div
|
|
20
|
-
*/
|
|
21
|
-
const figureSmallScreen = descriptionRef => {
|
|
22
|
-
const descriptionElement = descriptionRef.current;
|
|
23
|
-
if (!descriptionElement) {
|
|
24
|
-
return true;
|
|
25
|
-
}
|
|
26
|
-
return descriptionElement.getBoundingClientRect().width < 230;
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* Iterate direct react child components and override the value of the prop specified by @param dataForwardProp
|
|
31
|
-
* for those child components.
|
|
32
|
-
* @param children - react node children to iterate
|
|
33
|
-
* @param dataForwardProp - the name of the prop from the children components to override
|
|
34
|
-
* @param data - actual data to be passed to the prop specified by @param dataForwardProp
|
|
35
|
-
*/
|
|
36
|
-
const renderChildren = (children, dataForwardProp, data) => {
|
|
37
|
-
return _react.Children.map(children, child => {
|
|
38
|
-
return /*#__PURE__*/(0, _react.cloneElement)(child, {
|
|
39
|
-
[dataForwardProp]: data
|
|
40
|
-
});
|
|
41
|
-
});
|
|
42
|
-
};
|
|
43
|
-
const DEFAULT_PAGE_LIMITS = [50, 100, 200];
|
|
44
|
-
const generatePagingOptions = pageLimits => {
|
|
45
|
-
return pageLimits.map(limit => ({
|
|
46
|
-
value: limit,
|
|
47
|
-
label: "".concat(limit, "/page")
|
|
48
|
-
}));
|
|
49
|
-
};
|
|
50
|
-
const TablePagination = _ref => {
|
|
51
|
-
let {
|
|
16
|
+
const TablePagination = props => {
|
|
17
|
+
const {
|
|
52
18
|
data,
|
|
53
|
-
|
|
19
|
+
dataForwardProp = "rows",
|
|
54
20
|
itemName = "item",
|
|
21
|
+
className,
|
|
55
22
|
description,
|
|
23
|
+
pageLimits = _utils.DEFAULT_PAGE_LIMITS,
|
|
56
24
|
position = "above",
|
|
57
|
-
|
|
58
|
-
pageLimits = DEFAULT_PAGE_LIMITS,
|
|
25
|
+
externallyControlled,
|
|
59
26
|
children,
|
|
60
27
|
...divProps
|
|
61
|
-
} =
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
28
|
+
} = props;
|
|
29
|
+
|
|
30
|
+
// Safety check to ensure pageSize is a valid option in
|
|
31
|
+
// pageLimits if the component is externally controlled
|
|
32
|
+
if (externallyControlled) {
|
|
33
|
+
let pageSizeFound = false;
|
|
34
|
+
for (const limit of pageLimits) {
|
|
35
|
+
if (limit === Number(props.pageSize)) {
|
|
36
|
+
pageSizeFound = true;
|
|
37
|
+
break;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
if (!pageSizeFound) {
|
|
41
|
+
throw new Error("pageSize must be a valid option in pageLimits, pageLimits is set to [".concat(pageLimits, "]"));
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
const [internalPageSize, setInternalPageSize] = (0, _react.useState)(() => {
|
|
45
|
+
return (0, _utils.generatePagingOptions)(pageLimits)[0].value;
|
|
66
46
|
});
|
|
67
47
|
const {
|
|
68
48
|
paginate,
|
|
69
|
-
currentPage,
|
|
70
|
-
pageData
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
itemsPerPage: pageSize,
|
|
49
|
+
currentPage: internalCurrentPage,
|
|
50
|
+
pageData: internalData
|
|
51
|
+
} = (0, _hooks.usePagination)(externallyControlled ? [] : data, {
|
|
52
|
+
itemsPerPage: internalPageSize,
|
|
74
53
|
autoResetPage: true
|
|
75
54
|
});
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
}, [isSmallScreen]);
|
|
85
|
-
const handlePageSizeChange = e => {
|
|
86
|
-
paginate(1);
|
|
87
|
-
setPageSize(parseInt(e.target.value));
|
|
88
|
-
};
|
|
89
|
-
const getDescription = () => {
|
|
90
|
-
if (description) {
|
|
91
|
-
return description;
|
|
92
|
-
}
|
|
93
|
-
const visibleCount = pageData.length;
|
|
94
|
-
if (isSmallScreen) {
|
|
95
|
-
return "".concat(visibleCount, " out of ").concat(totalItems);
|
|
55
|
+
const controlData = externallyControlled ? data : internalData;
|
|
56
|
+
const controlPageSize = externallyControlled ? props.pageSize : internalPageSize;
|
|
57
|
+
const controlTotalItems = externallyControlled ? props.totalItems : data.length;
|
|
58
|
+
const controlCurrentPage = externallyControlled ? props.currentPage : internalCurrentPage;
|
|
59
|
+
const handlePageChange = page => {
|
|
60
|
+
if (externallyControlled) {
|
|
61
|
+
props.onPageChange(page);
|
|
62
|
+
return;
|
|
96
63
|
}
|
|
97
|
-
|
|
98
|
-
|
|
64
|
+
paginate(page);
|
|
65
|
+
};
|
|
66
|
+
const handlePageSizeChange = pageSize => {
|
|
67
|
+
if (externallyControlled) {
|
|
68
|
+
props.onPageSizeChange(pageSize);
|
|
69
|
+
return;
|
|
99
70
|
}
|
|
100
|
-
|
|
71
|
+
paginate(1);
|
|
72
|
+
setInternalPageSize(pageSize);
|
|
101
73
|
};
|
|
102
|
-
const
|
|
103
|
-
const
|
|
104
|
-
|
|
105
|
-
className:
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
onPageChange:
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
className: "items-per-page",
|
|
117
|
-
label: "Items per page",
|
|
118
|
-
labelClassName: "u-off-screen",
|
|
119
|
-
id: "itemsPerPage",
|
|
120
|
-
options: generatePagingOptions(pageLimits),
|
|
121
|
-
onChange: handlePageSizeChange,
|
|
122
|
-
value: pageSize
|
|
123
|
-
})), position === "above" && clonedChildren);
|
|
74
|
+
const clonedChildren = (0, _utils.renderChildren)(children, dataForwardProp, controlData);
|
|
75
|
+
const controls = /*#__PURE__*/_react.default.createElement(_TablePaginationControls.default, _extends({}, divProps, {
|
|
76
|
+
data: controlData,
|
|
77
|
+
className: className,
|
|
78
|
+
itemName: itemName,
|
|
79
|
+
description: description,
|
|
80
|
+
pageLimits: pageLimits,
|
|
81
|
+
totalItems: controlTotalItems,
|
|
82
|
+
currentPage: controlCurrentPage,
|
|
83
|
+
pageSize: controlPageSize,
|
|
84
|
+
onPageChange: handlePageChange,
|
|
85
|
+
onPageSizeChange: handlePageSizeChange
|
|
86
|
+
}));
|
|
87
|
+
return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, position === "above" && controls, clonedChildren, position === "below" && controls);
|
|
124
88
|
};
|
|
125
89
|
var _default = exports.default = TablePagination;
|
package/dist/components/TablePagination/TablePaginationControls/TablePaginationControls.d.ts
CHANGED
|
@@ -1,16 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* The current page of the data
|
|
8
|
-
*/
|
|
9
|
-
currentPage: number;
|
|
10
|
-
/**
|
|
11
|
-
* The total number of pages that exists within the data
|
|
12
|
-
*/
|
|
13
|
-
totalPages: number;
|
|
14
|
-
};
|
|
15
|
-
declare const TablePaginationControls: ({ onPageChange, currentPage, totalPages, }: Props) => JSX.Element;
|
|
1
|
+
import { HTMLAttributes } from "react";
|
|
2
|
+
import { BasePaginationProps, ExternalControlProps, InternalControlProps } from "../TablePagination";
|
|
3
|
+
export type AllProps = BasePaginationProps & InternalControlProps & ExternalControlProps;
|
|
4
|
+
export type Props = Omit<AllProps, "externallyControlled" | "dataForwardProp" | "position"> & HTMLAttributes<HTMLDivElement>;
|
|
5
|
+
declare const TablePaginationControls: ({ data, className, itemName, description, pageLimits, totalItems, currentPage, pageSize, onPageChange, onPageSizeChange, ...divProps }: Props) => JSX.Element;
|
|
16
6
|
export default TablePaginationControls;
|
|
@@ -4,18 +4,38 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
-
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
8
7
|
var _Button = _interopRequireDefault(require("../../Button"));
|
|
9
8
|
var _Icon = _interopRequireDefault(require("../../Icon"));
|
|
10
9
|
var _Input = _interopRequireDefault(require("../../Input"));
|
|
10
|
+
var _Select = _interopRequireDefault(require("../../Select"));
|
|
11
11
|
var _react = _interopRequireDefault(require("react"));
|
|
12
|
+
var _classnames = _interopRequireDefault(require("classnames"));
|
|
13
|
+
var _utils = require("../utils");
|
|
12
14
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
15
|
+
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
13
16
|
const TablePaginationControls = _ref => {
|
|
14
17
|
let {
|
|
15
|
-
|
|
18
|
+
data,
|
|
19
|
+
className,
|
|
20
|
+
itemName,
|
|
21
|
+
description,
|
|
22
|
+
pageLimits,
|
|
23
|
+
totalItems,
|
|
16
24
|
currentPage,
|
|
17
|
-
|
|
25
|
+
pageSize,
|
|
26
|
+
onPageChange,
|
|
27
|
+
onPageSizeChange,
|
|
28
|
+
...divProps
|
|
18
29
|
} = _ref;
|
|
30
|
+
const isSmallScreen = (0, _utils.useFigureSmallScreen)();
|
|
31
|
+
const totalPages = Math.ceil(totalItems / pageSize);
|
|
32
|
+
const descriptionDisplay = (0, _utils.getDescription)({
|
|
33
|
+
description,
|
|
34
|
+
data,
|
|
35
|
+
isSmallScreen,
|
|
36
|
+
totalItems,
|
|
37
|
+
itemName
|
|
38
|
+
});
|
|
19
39
|
const handleDecrementPage = currentPage => {
|
|
20
40
|
if (currentPage > 1) {
|
|
21
41
|
onPageChange(currentPage - 1);
|
|
@@ -30,7 +50,17 @@ const TablePaginationControls = _ref => {
|
|
|
30
50
|
const newPage = Math.min(totalPages, Math.max(1, parseInt(e.target.value)));
|
|
31
51
|
onPageChange(newPage);
|
|
32
52
|
};
|
|
33
|
-
|
|
53
|
+
const handlePageSizeChange = e => {
|
|
54
|
+
onPageSizeChange(parseInt(e.target.value));
|
|
55
|
+
};
|
|
56
|
+
return /*#__PURE__*/_react.default.createElement("div", _extends({
|
|
57
|
+
className: (0, _classnames.default)("pagination", className)
|
|
58
|
+
}, divProps, {
|
|
59
|
+
role: "navigation"
|
|
60
|
+
}), /*#__PURE__*/_react.default.createElement("div", {
|
|
61
|
+
className: "description",
|
|
62
|
+
id: "pagination-description"
|
|
63
|
+
}, descriptionDisplay), /*#__PURE__*/_react.default.createElement(_Button.default, {
|
|
34
64
|
"aria-label": "Previous page",
|
|
35
65
|
className: "back",
|
|
36
66
|
appearance: "base",
|
|
@@ -56,11 +86,14 @@ const TablePaginationControls = _ref => {
|
|
|
56
86
|
onClick: () => handleIncrementPage(currentPage, totalPages)
|
|
57
87
|
}, /*#__PURE__*/_react.default.createElement(_Icon.default, {
|
|
58
88
|
name: "chevron-down"
|
|
59
|
-
}))
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
89
|
+
})), /*#__PURE__*/_react.default.createElement(_Select.default, {
|
|
90
|
+
className: "u-no-margin--bottom",
|
|
91
|
+
label: "Items per page",
|
|
92
|
+
labelClassName: "u-off-screen",
|
|
93
|
+
id: "itemsPerPage",
|
|
94
|
+
options: (0, _utils.generatePagingOptions)(pageLimits),
|
|
95
|
+
onChange: handlePageSizeChange,
|
|
96
|
+
value: pageSize
|
|
97
|
+
}));
|
|
65
98
|
};
|
|
66
99
|
var _default = exports.default = TablePaginationControls;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { ReactElement, ReactNode } from "react";
|
|
2
|
+
/**
|
|
3
|
+
* Iterate direct react child components and override the value of the prop specified by @param dataForwardProp
|
|
4
|
+
* for those child components.
|
|
5
|
+
* @param children - react node children to iterate
|
|
6
|
+
* @param dataForwardProp - the name of the prop from the children components to override
|
|
7
|
+
* @param data - actual data to be passed to the prop specified by @param dataForwardProp
|
|
8
|
+
*/
|
|
9
|
+
export declare const renderChildren: (children: ReactNode, dataForwardProp: string, data: unknown[]) => ReactElement<any, string | import("react").JSXElementConstructor<any>>[];
|
|
10
|
+
export declare const DEFAULT_PAGE_LIMITS: number[];
|
|
11
|
+
export declare const generatePagingOptions: (pageLimits: number[]) => {
|
|
12
|
+
value: number;
|
|
13
|
+
label: string;
|
|
14
|
+
}[];
|
|
15
|
+
export declare const getDescription: ({ description, data, isSmallScreen, totalItems, itemName, }: {
|
|
16
|
+
description: ReactNode;
|
|
17
|
+
data: unknown[];
|
|
18
|
+
isSmallScreen: boolean;
|
|
19
|
+
totalItems: number;
|
|
20
|
+
itemName: string;
|
|
21
|
+
}) => string | number | true | ReactElement<any, string | import("react").JSXElementConstructor<any>> | Iterable<ReactNode>;
|
|
22
|
+
export declare const useFigureSmallScreen: () => boolean;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.useFigureSmallScreen = exports.renderChildren = exports.getDescription = exports.generatePagingOptions = exports.DEFAULT_PAGE_LIMITS = void 0;
|
|
7
|
+
var _react = require("react");
|
|
8
|
+
/**
|
|
9
|
+
* Iterate direct react child components and override the value of the prop specified by @param dataForwardProp
|
|
10
|
+
* for those child components.
|
|
11
|
+
* @param children - react node children to iterate
|
|
12
|
+
* @param dataForwardProp - the name of the prop from the children components to override
|
|
13
|
+
* @param data - actual data to be passed to the prop specified by @param dataForwardProp
|
|
14
|
+
*/
|
|
15
|
+
const renderChildren = (children, dataForwardProp, data) => {
|
|
16
|
+
return _react.Children.map(children, child => {
|
|
17
|
+
return /*#__PURE__*/(0, _react.cloneElement)(child, {
|
|
18
|
+
[dataForwardProp]: data
|
|
19
|
+
});
|
|
20
|
+
});
|
|
21
|
+
};
|
|
22
|
+
exports.renderChildren = renderChildren;
|
|
23
|
+
const DEFAULT_PAGE_LIMITS = exports.DEFAULT_PAGE_LIMITS = [50, 100, 200];
|
|
24
|
+
const generatePagingOptions = pageLimits => {
|
|
25
|
+
return pageLimits.map(limit => ({
|
|
26
|
+
value: limit,
|
|
27
|
+
label: "".concat(limit, "/page")
|
|
28
|
+
}));
|
|
29
|
+
};
|
|
30
|
+
exports.generatePagingOptions = generatePagingOptions;
|
|
31
|
+
const getDescription = _ref => {
|
|
32
|
+
let {
|
|
33
|
+
description,
|
|
34
|
+
data,
|
|
35
|
+
isSmallScreen,
|
|
36
|
+
totalItems,
|
|
37
|
+
itemName
|
|
38
|
+
} = _ref;
|
|
39
|
+
if (description) {
|
|
40
|
+
return description;
|
|
41
|
+
}
|
|
42
|
+
const visibleCount = data.length;
|
|
43
|
+
if (isSmallScreen) {
|
|
44
|
+
return "".concat(visibleCount, " out of ").concat(totalItems);
|
|
45
|
+
}
|
|
46
|
+
if (visibleCount === totalItems && visibleCount > 1) {
|
|
47
|
+
return "Showing all ".concat(totalItems, " ").concat(itemName, "s");
|
|
48
|
+
}
|
|
49
|
+
return "Showing ".concat(visibleCount, " out of ").concat(totalItems, " ").concat(itemName).concat(totalItems !== 1 ? "s" : "");
|
|
50
|
+
};
|
|
51
|
+
exports.getDescription = getDescription;
|
|
52
|
+
const useFigureSmallScreen = () => {
|
|
53
|
+
const [isSmallScreen, setSmallScreen] = (0, _react.useState)(false);
|
|
54
|
+
(0, _react.useEffect)(() => {
|
|
55
|
+
const handleResize = () => {
|
|
56
|
+
setSmallScreen(window.innerWidth < 620);
|
|
57
|
+
};
|
|
58
|
+
window.addEventListener("resize", handleResize);
|
|
59
|
+
return () => {
|
|
60
|
+
window.removeEventListener("resize", handleResize);
|
|
61
|
+
};
|
|
62
|
+
}, []);
|
|
63
|
+
return isSmallScreen;
|
|
64
|
+
};
|
|
65
|
+
exports.useFigureSmallScreen = useFigureSmallScreen;
|