@homebound/beam 2.248.0 → 2.249.0
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.
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Dispatch, SetStateAction } from "react";
|
|
2
|
+
export type PageSettings = {
|
|
3
|
+
page: number;
|
|
4
|
+
perPage: number;
|
|
5
|
+
};
|
|
6
|
+
interface PaginationProps {
|
|
7
|
+
label: string;
|
|
8
|
+
totalCount: number;
|
|
9
|
+
settings: PageSettings;
|
|
10
|
+
setSettings: Dispatch<SetStateAction<PageSettings>>;
|
|
11
|
+
}
|
|
12
|
+
export declare function Pagination(props: PaginationProps): import("@emotion/react/jsx-runtime").JSX.Element;
|
|
13
|
+
export declare function toFirstAndOffset(page: number, perPage: number): {
|
|
14
|
+
first: number;
|
|
15
|
+
offset: number;
|
|
16
|
+
};
|
|
17
|
+
export declare const pageOptions: {
|
|
18
|
+
id: number;
|
|
19
|
+
name: string;
|
|
20
|
+
}[];
|
|
21
|
+
export {};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.pageOptions = exports.toFirstAndOffset = exports.Pagination = void 0;
|
|
4
|
+
const jsx_runtime_1 = require("@emotion/react/jsx-runtime");
|
|
5
|
+
const react_1 = require("react");
|
|
6
|
+
const components_1 = require("./");
|
|
7
|
+
const Css_1 = require("../Css");
|
|
8
|
+
const inputs_1 = require("../inputs");
|
|
9
|
+
const utils_1 = require("../utils");
|
|
10
|
+
function Pagination(props) {
|
|
11
|
+
const { label, settings, totalCount, setSettings } = props;
|
|
12
|
+
const { perPage, page } = settings;
|
|
13
|
+
const hasNextPage = (0, react_1.useMemo)(() => page < totalCount / perPage, [page, perPage, totalCount]);
|
|
14
|
+
const tid = (0, utils_1.useTestIds)(props, "pagination");
|
|
15
|
+
return ((0, jsx_runtime_1.jsxs)("div", { css: Css_1.Css.df.bGray300.bt.xs.gray500.px1.ml2.pt2.$, ...tid, children: [(0, jsx_runtime_1.jsxs)("div", { css: Css_1.Css.df.mya.mr2.$, ...tid.perPageLabel, children: [label, " per page:"] }), (0, jsx_runtime_1.jsx)("div", { css: Css_1.Css.wPx(78).$, children: (0, jsx_runtime_1.jsx)(inputs_1.SelectField, { compact: true, ...tid.perPage, labelStyle: "hidden", label: `${label} per page`, options: exports.pageOptions, value: perPage, onSelect: (val) => {
|
|
16
|
+
setSettings({ page: 1, perPage: val });
|
|
17
|
+
} }) }), (0, jsx_runtime_1.jsxs)("div", { css: Css_1.Css.mla.mya.df.$, children: [(0, jsx_runtime_1.jsxs)("div", { css: Css_1.Css.df.mya.mr2.$, ...tid.pageInfoLabel, children: [perPage * (page - 1) + 1, " ", hasNextPage ? `- ${perPage * page}` : "", " of ", totalCount, " ", label] }), (0, jsx_runtime_1.jsx)(components_1.IconButton, { ...tid.previousIcon, icon: "chevronLeft", color: Css_1.Palette.LightBlue700, onClick: () => setSettings({ page: settings.page - 1, perPage }), disabled: settings.page === 1 }), (0, jsx_runtime_1.jsx)(components_1.IconButton, { ...tid.nextIcon, icon: "chevronRight", color: Css_1.Palette.LightBlue700, onClick: () => setSettings({ page: settings.page + 1, perPage }), disabled: !hasNextPage })] })] }));
|
|
18
|
+
}
|
|
19
|
+
exports.Pagination = Pagination;
|
|
20
|
+
function toFirstAndOffset(page, perPage) {
|
|
21
|
+
return {
|
|
22
|
+
first: perPage,
|
|
23
|
+
// E.g. on first page the offset is 0, second page the offset is 100, then 200, etc.
|
|
24
|
+
offset: (page - 1) * perPage,
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
exports.toFirstAndOffset = toFirstAndOffset;
|
|
28
|
+
// Make a list of 50/100/150/etc page sizes for the user to chose
|
|
29
|
+
exports.pageOptions = Array(5)
|
|
30
|
+
.fill(0)
|
|
31
|
+
.map((_, i) => ({ id: (i + 1) * 50, name: ((i + 1) * 50).toString() }));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@homebound/beam",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.249.0",
|
|
4
4
|
"author": "Homebound",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
"format": "prettier --loglevel warn --write \"**/*.{ts,tsx,css,md,mdx}\""
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@homebound/form-state": "^2.
|
|
36
|
+
"@homebound/form-state": "^2.16.0",
|
|
37
37
|
"@internationalized/number": "^3.0.3",
|
|
38
38
|
"@react-aria/utils": "^3.13.2",
|
|
39
39
|
"@react-hook/resize-observer": "^1.2.2",
|