@availity/mui-pagination 1.0.5 → 1.0.7
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/CHANGELOG.md +12 -0
- package/dist/index.d.mts +33 -1
- package/dist/index.d.ts +33 -1
- package/dist/index.js +59 -2
- package/dist/index.mjs +57 -1
- package/package.json +1 -1
- package/src/index.ts +1 -0
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,18 @@
|
|
|
2
2
|
|
|
3
3
|
This file was generated using [@jscutlery/semver](https://github.com/jscutlery/semver).
|
|
4
4
|
|
|
5
|
+
## [1.0.7](https://github.com/Availity/element/compare/@availity/mui-pagination@1.0.6...@availity/mui-pagination@1.0.7) (2025-04-21)
|
|
6
|
+
|
|
7
|
+
### Dependency Updates
|
|
8
|
+
|
|
9
|
+
* `mui-list` updated to version `1.0.6`
|
|
10
|
+
## [1.0.6](https://github.com/Availity/element/compare/@availity/mui-pagination@1.0.5...@availity/mui-pagination@1.0.6) (2025-04-16)
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
### Bug Fixes
|
|
14
|
+
|
|
15
|
+
* **mui-pagination:** added missing export ([9ed0267](https://github.com/Availity/element/commit/9ed02670a87d81480add8139d21e536df8090f57))
|
|
16
|
+
|
|
5
17
|
## [1.0.5](https://github.com/Availity/element/compare/@availity/mui-pagination@1.0.4...@availity/mui-pagination@1.0.5) (2025-04-14)
|
|
6
18
|
|
|
7
19
|
### Dependency Updates
|
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { PaginationProps as PaginationProps$1 } from '@mui/material/Pagination';
|
|
2
2
|
import { PaginationItemProps as PaginationItemProps$1 } from '@mui/material/PaginationItem';
|
|
3
|
+
import * as _tanstack_react_query from '@tanstack/react-query';
|
|
3
4
|
|
|
4
5
|
type PaginationProps = {
|
|
5
6
|
/** The size of the component
|
|
@@ -11,4 +12,35 @@ declare const Pagination: (props: PaginationProps) => JSX.Element;
|
|
|
11
12
|
type PaginationItemProps = Omit<PaginationItemProps$1, 'components' | 'color' | 'shape' | 'size'>;
|
|
12
13
|
declare const PaginationItem: (props: PaginationItemProps) => JSX.Element;
|
|
13
14
|
|
|
14
|
-
|
|
15
|
+
type Resource<TData> = {
|
|
16
|
+
postGet: (request: {
|
|
17
|
+
limit: number;
|
|
18
|
+
offset: number;
|
|
19
|
+
} & Record<string, unknown>, config: unknown) => Promise<{
|
|
20
|
+
data: TData & {
|
|
21
|
+
totalCount: number;
|
|
22
|
+
};
|
|
23
|
+
}>;
|
|
24
|
+
getResult: string | ((result: TData) => unknown[]);
|
|
25
|
+
addParams: (data: Record<string, unknown>, config: Record<string, unknown>) => unknown;
|
|
26
|
+
};
|
|
27
|
+
type LoadPageProps<TData> = {
|
|
28
|
+
page: number;
|
|
29
|
+
/** When a function, the function is called with the response body from the API call and is expected to return an array containing the list of items for the page. When a string, the string is expected to be a simple key used to get the value from the response. ("simple" means dot notation is not supported for grabbing values from nested objects. If your result is deeply nested, provide a function) */
|
|
30
|
+
getResult: string | ((result: TData) => unknown[]);
|
|
31
|
+
/** If array, defaults `totalCount` to the length of the array, and page values are sliced from the Array. If a function, it is called with the current page as an argument and expects an array of items to be returned. */
|
|
32
|
+
itemsPerPage?: number;
|
|
33
|
+
/** Object use to create querystring parameters in the request. */
|
|
34
|
+
parameters?: {
|
|
35
|
+
params?: Record<string, unknown>;
|
|
36
|
+
} & Record<string, unknown>;
|
|
37
|
+
/** Availity API resource (see [@availity/api-axios](https://github.com/Availity/sdk-js/tree/master/packages/api-axios)). */
|
|
38
|
+
resource: Resource<TData>;
|
|
39
|
+
};
|
|
40
|
+
/** @requires `@tanstack/react-query` peer dependency */
|
|
41
|
+
declare const useResourcePagination: <TData>({ page, itemsPerPage, parameters, getResult, resource, }: LoadPageProps<TData>) => _tanstack_react_query.UseQueryResult<{
|
|
42
|
+
items: TData[];
|
|
43
|
+
totalCount: number;
|
|
44
|
+
}, unknown>;
|
|
45
|
+
|
|
46
|
+
export { type LoadPageProps, Pagination, PaginationItem, type PaginationItemProps, type PaginationProps, useResourcePagination };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { PaginationProps as PaginationProps$1 } from '@mui/material/Pagination';
|
|
2
2
|
import { PaginationItemProps as PaginationItemProps$1 } from '@mui/material/PaginationItem';
|
|
3
|
+
import * as _tanstack_react_query from '@tanstack/react-query';
|
|
3
4
|
|
|
4
5
|
type PaginationProps = {
|
|
5
6
|
/** The size of the component
|
|
@@ -11,4 +12,35 @@ declare const Pagination: (props: PaginationProps) => JSX.Element;
|
|
|
11
12
|
type PaginationItemProps = Omit<PaginationItemProps$1, 'components' | 'color' | 'shape' | 'size'>;
|
|
12
13
|
declare const PaginationItem: (props: PaginationItemProps) => JSX.Element;
|
|
13
14
|
|
|
14
|
-
|
|
15
|
+
type Resource<TData> = {
|
|
16
|
+
postGet: (request: {
|
|
17
|
+
limit: number;
|
|
18
|
+
offset: number;
|
|
19
|
+
} & Record<string, unknown>, config: unknown) => Promise<{
|
|
20
|
+
data: TData & {
|
|
21
|
+
totalCount: number;
|
|
22
|
+
};
|
|
23
|
+
}>;
|
|
24
|
+
getResult: string | ((result: TData) => unknown[]);
|
|
25
|
+
addParams: (data: Record<string, unknown>, config: Record<string, unknown>) => unknown;
|
|
26
|
+
};
|
|
27
|
+
type LoadPageProps<TData> = {
|
|
28
|
+
page: number;
|
|
29
|
+
/** When a function, the function is called with the response body from the API call and is expected to return an array containing the list of items for the page. When a string, the string is expected to be a simple key used to get the value from the response. ("simple" means dot notation is not supported for grabbing values from nested objects. If your result is deeply nested, provide a function) */
|
|
30
|
+
getResult: string | ((result: TData) => unknown[]);
|
|
31
|
+
/** If array, defaults `totalCount` to the length of the array, and page values are sliced from the Array. If a function, it is called with the current page as an argument and expects an array of items to be returned. */
|
|
32
|
+
itemsPerPage?: number;
|
|
33
|
+
/** Object use to create querystring parameters in the request. */
|
|
34
|
+
parameters?: {
|
|
35
|
+
params?: Record<string, unknown>;
|
|
36
|
+
} & Record<string, unknown>;
|
|
37
|
+
/** Availity API resource (see [@availity/api-axios](https://github.com/Availity/sdk-js/tree/master/packages/api-axios)). */
|
|
38
|
+
resource: Resource<TData>;
|
|
39
|
+
};
|
|
40
|
+
/** @requires `@tanstack/react-query` peer dependency */
|
|
41
|
+
declare const useResourcePagination: <TData>({ page, itemsPerPage, parameters, getResult, resource, }: LoadPageProps<TData>) => _tanstack_react_query.UseQueryResult<{
|
|
42
|
+
items: TData[];
|
|
43
|
+
totalCount: number;
|
|
44
|
+
}, unknown>;
|
|
45
|
+
|
|
46
|
+
export { type LoadPageProps, Pagination, PaginationItem, type PaginationItemProps, type PaginationProps, useResourcePagination };
|
package/dist/index.js
CHANGED
|
@@ -43,12 +43,33 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
43
43
|
mod
|
|
44
44
|
));
|
|
45
45
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
46
|
+
var __async = (__this, __arguments, generator) => {
|
|
47
|
+
return new Promise((resolve, reject) => {
|
|
48
|
+
var fulfilled = (value) => {
|
|
49
|
+
try {
|
|
50
|
+
step(generator.next(value));
|
|
51
|
+
} catch (e) {
|
|
52
|
+
reject(e);
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
var rejected = (value) => {
|
|
56
|
+
try {
|
|
57
|
+
step(generator.throw(value));
|
|
58
|
+
} catch (e) {
|
|
59
|
+
reject(e);
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
63
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
64
|
+
});
|
|
65
|
+
};
|
|
46
66
|
|
|
47
67
|
// src/index.ts
|
|
48
68
|
var index_exports = {};
|
|
49
69
|
__export(index_exports, {
|
|
50
70
|
Pagination: () => Pagination,
|
|
51
|
-
PaginationItem: () => PaginationItem
|
|
71
|
+
PaginationItem: () => PaginationItem,
|
|
72
|
+
useResourcePagination: () => useResourcePagination
|
|
52
73
|
});
|
|
53
74
|
module.exports = __toCommonJS(index_exports);
|
|
54
75
|
|
|
@@ -90,8 +111,44 @@ var getItemAriaLabel = (type, page) => {
|
|
|
90
111
|
var Pagination = (props) => {
|
|
91
112
|
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_Pagination.default, __spreadProps(__spreadValues({}, props), { getItemAriaLabel, renderItem: (item) => /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(PaginationItem, __spreadValues({}, item)) }));
|
|
92
113
|
};
|
|
114
|
+
|
|
115
|
+
// src/lib/ResourcePagination.tsx
|
|
116
|
+
var import_react_query = require("@tanstack/react-query");
|
|
117
|
+
var loadPage = (_0) => __async(void 0, [_0], function* ({
|
|
118
|
+
page,
|
|
119
|
+
itemsPerPage = 10,
|
|
120
|
+
parameters = {},
|
|
121
|
+
getResult,
|
|
122
|
+
resource
|
|
123
|
+
}) {
|
|
124
|
+
const data = __spreadValues({
|
|
125
|
+
limit: itemsPerPage,
|
|
126
|
+
offset: (page - 1) * itemsPerPage
|
|
127
|
+
}, parameters.params);
|
|
128
|
+
const config = resource.addParams(data, parameters);
|
|
129
|
+
const resp = yield resource.postGet(data, config);
|
|
130
|
+
const useGetResult = getResult || resource.getResult;
|
|
131
|
+
const items = (typeof useGetResult === "function" ? useGetResult.call(resource, resp.data) : resp.data[useGetResult]) || resp.data;
|
|
132
|
+
if (!Array.isArray(items)) {
|
|
133
|
+
throw new TypeError(
|
|
134
|
+
`Expected data to be an array but got \`${typeof items}\`. Use the \`getResult\` prop to specify how to get the data from the API response.`
|
|
135
|
+
);
|
|
136
|
+
}
|
|
137
|
+
return {
|
|
138
|
+
items,
|
|
139
|
+
totalCount: resp.data.totalCount
|
|
140
|
+
};
|
|
141
|
+
});
|
|
142
|
+
var useResourcePagination = ({
|
|
143
|
+
page,
|
|
144
|
+
itemsPerPage,
|
|
145
|
+
parameters,
|
|
146
|
+
getResult,
|
|
147
|
+
resource
|
|
148
|
+
}) => (0, import_react_query.useQuery)(["resource", page], () => loadPage({ page, itemsPerPage, parameters, getResult, resource }));
|
|
93
149
|
// Annotate the CommonJS export names for ESM import in node:
|
|
94
150
|
0 && (module.exports = {
|
|
95
151
|
Pagination,
|
|
96
|
-
PaginationItem
|
|
152
|
+
PaginationItem,
|
|
153
|
+
useResourcePagination
|
|
97
154
|
});
|
package/dist/index.mjs
CHANGED
|
@@ -17,6 +17,26 @@ var __spreadValues = (a, b) => {
|
|
|
17
17
|
return a;
|
|
18
18
|
};
|
|
19
19
|
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
|
+
var __async = (__this, __arguments, generator) => {
|
|
21
|
+
return new Promise((resolve, reject) => {
|
|
22
|
+
var fulfilled = (value) => {
|
|
23
|
+
try {
|
|
24
|
+
step(generator.next(value));
|
|
25
|
+
} catch (e) {
|
|
26
|
+
reject(e);
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
var rejected = (value) => {
|
|
30
|
+
try {
|
|
31
|
+
step(generator.throw(value));
|
|
32
|
+
} catch (e) {
|
|
33
|
+
reject(e);
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
37
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
38
|
+
});
|
|
39
|
+
};
|
|
20
40
|
|
|
21
41
|
// src/lib/Pagination.tsx
|
|
22
42
|
import { default as MuiPagination } from "@mui/material/Pagination";
|
|
@@ -58,7 +78,43 @@ var getItemAriaLabel = (type, page) => {
|
|
|
58
78
|
var Pagination = (props) => {
|
|
59
79
|
return /* @__PURE__ */ jsx2(MuiPagination, __spreadProps(__spreadValues({}, props), { getItemAriaLabel, renderItem: (item) => /* @__PURE__ */ jsx2(PaginationItem, __spreadValues({}, item)) }));
|
|
60
80
|
};
|
|
81
|
+
|
|
82
|
+
// src/lib/ResourcePagination.tsx
|
|
83
|
+
import { useQuery } from "@tanstack/react-query";
|
|
84
|
+
var loadPage = (_0) => __async(void 0, [_0], function* ({
|
|
85
|
+
page,
|
|
86
|
+
itemsPerPage = 10,
|
|
87
|
+
parameters = {},
|
|
88
|
+
getResult,
|
|
89
|
+
resource
|
|
90
|
+
}) {
|
|
91
|
+
const data = __spreadValues({
|
|
92
|
+
limit: itemsPerPage,
|
|
93
|
+
offset: (page - 1) * itemsPerPage
|
|
94
|
+
}, parameters.params);
|
|
95
|
+
const config = resource.addParams(data, parameters);
|
|
96
|
+
const resp = yield resource.postGet(data, config);
|
|
97
|
+
const useGetResult = getResult || resource.getResult;
|
|
98
|
+
const items = (typeof useGetResult === "function" ? useGetResult.call(resource, resp.data) : resp.data[useGetResult]) || resp.data;
|
|
99
|
+
if (!Array.isArray(items)) {
|
|
100
|
+
throw new TypeError(
|
|
101
|
+
`Expected data to be an array but got \`${typeof items}\`. Use the \`getResult\` prop to specify how to get the data from the API response.`
|
|
102
|
+
);
|
|
103
|
+
}
|
|
104
|
+
return {
|
|
105
|
+
items,
|
|
106
|
+
totalCount: resp.data.totalCount
|
|
107
|
+
};
|
|
108
|
+
});
|
|
109
|
+
var useResourcePagination = ({
|
|
110
|
+
page,
|
|
111
|
+
itemsPerPage,
|
|
112
|
+
parameters,
|
|
113
|
+
getResult,
|
|
114
|
+
resource
|
|
115
|
+
}) => useQuery(["resource", page], () => loadPage({ page, itemsPerPage, parameters, getResult, resource }));
|
|
61
116
|
export {
|
|
62
117
|
Pagination,
|
|
63
|
-
PaginationItem
|
|
118
|
+
PaginationItem,
|
|
119
|
+
useResourcePagination
|
|
64
120
|
};
|
package/package.json
CHANGED
package/src/index.ts
CHANGED