@deque/cauldron-react 4.5.0-canary.0c764a21 → 4.5.0-canary.7f6a304a

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,20 @@
1
+ import React from 'react';
2
+ import { Placement } from '@popperjs/core';
3
+ interface Props extends React.HTMLAttributes<HTMLDivElement> {
4
+ totalItems: number;
5
+ itemsPerPage?: number;
6
+ currentPage?: number;
7
+ statusLabel?: React.ReactNode;
8
+ firstPageLabel?: string;
9
+ previousPageLabel?: string;
10
+ nextPageLabel?: string;
11
+ lastPageLabel?: string;
12
+ onNextPageClick?: () => void;
13
+ onPreviousPageClick?: () => void;
14
+ onFirstPageClick?: () => void;
15
+ onLastPageClick?: () => void;
16
+ tooltipPlacement?: Placement;
17
+ className?: string;
18
+ }
19
+ declare const Pagination: React.ForwardRefExoticComponent<Props & React.RefAttributes<HTMLDivElement>>;
20
+ export default Pagination;
@@ -1,20 +1,3 @@
1
- import React from 'react';
2
- import { Placement } from '@popperjs/core';
3
- interface Props extends React.HTMLAttributes<HTMLDivElement> {
4
- totalItems: number;
5
- itemsPerPage?: number;
6
- currentPage?: number;
7
- statusLabel?: React.ReactNode;
8
- firstPageLabel?: string;
9
- previousPageLabel?: string;
10
- nextPageLabel?: string;
11
- lastPageLabel?: string;
12
- onNextPageClick?: () => void;
13
- onPreviousPageClick?: () => void;
14
- onFirstPageClick?: () => void;
15
- onLastPageClick?: () => void;
16
- tooltipPlacement?: Placement;
17
- className?: string;
18
- }
19
- declare const Pagination: React.ForwardRefExoticComponent<Props & React.RefAttributes<HTMLDivElement>>;
1
+ import Pagination from './Pagination';
2
+ export { usePagination } from './usePagination';
20
3
  export default Pagination;
@@ -0,0 +1,24 @@
1
+ interface Options {
2
+ totalItems: number;
3
+ initialPageSize?: number;
4
+ initialPage?: number;
5
+ }
6
+ interface PaginationResults {
7
+ totalItems: number;
8
+ currentPage: number;
9
+ itemsPerPage: number;
10
+ onNextPageClick: () => void;
11
+ onPreviousPageClick: () => void;
12
+ onFirstPageClick: () => void;
13
+ onLastPageClick: () => void;
14
+ }
15
+ interface PageStatus {
16
+ currentPage: number;
17
+ pageStart: number;
18
+ pageEnd: number;
19
+ }
20
+ export declare const usePagination: ({ totalItems, initialPageSize, initialPage }: Options) => {
21
+ pagination: PaginationResults;
22
+ pageStatus: PageStatus;
23
+ };
24
+ export {};
package/lib/index.d.ts CHANGED
@@ -45,7 +45,7 @@ export { default as Panel } from './components/Panel';
45
45
  export { default as IssuePanel } from './components/IssuePanel';
46
46
  export { default as ProgressBar } from './components/ProgressBar';
47
47
  export { Address, AddressLine, AddressCityStateZip } from './components/Address';
48
- export { default as Pagination } from './components/Pagination';
48
+ export { default as Pagination, usePagination } from './components/Pagination';
49
49
  export { default as FieldWrap } from './components/FieldWrap';
50
50
  export { default as Breadcrumb, BreadcrumbItem, BreadcrumbLink } from './components/Breadcrumb';
51
51
  export { default as TwoColumnPanel, ColumnHeader, ColumnGroupHeader, ColumnLeft, ColumnRight, ColumnList } from './components/TwoColumnPanel';
package/lib/index.js CHANGED
@@ -8532,6 +8532,34 @@ Pagination.propTypes = {
8532
8532
  className: PropTypes.string
8533
8533
  };
8534
8534
 
8535
+ var usePagination = function (_a) {
8536
+ var totalItems = _a.totalItems, _b = _a.initialPageSize, initialPageSize = _b === void 0 ? 10 : _b, _c = _a.initialPage, initialPage = _c === void 0 ? 1 : _c;
8537
+ var _d = tslib.__read(React.useState(initialPage), 2), currentPage = _d[0], setCurrentPage = _d[1];
8538
+ var pageStart = currentPage * initialPageSize - initialPageSize + 1;
8539
+ var pageEnd = Math.min(pageStart + initialPageSize - 1, totalItems);
8540
+ var onFirstPageClick = function () { return setCurrentPage(1); };
8541
+ var onPreviousPageClick = function () { return setCurrentPage(currentPage - 1); };
8542
+ var onNextPageClick = function () { return setCurrentPage(currentPage + 1); };
8543
+ var onLastPageClick = function () {
8544
+ return setCurrentPage(Math.ceil(totalItems / initialPageSize));
8545
+ };
8546
+ var pagination = {
8547
+ totalItems: totalItems,
8548
+ currentPage: currentPage,
8549
+ itemsPerPage: initialPageSize,
8550
+ onFirstPageClick: onFirstPageClick,
8551
+ onPreviousPageClick: onPreviousPageClick,
8552
+ onNextPageClick: onNextPageClick,
8553
+ onLastPageClick: onLastPageClick
8554
+ };
8555
+ var pageStatus = {
8556
+ currentPage: currentPage,
8557
+ pageStart: pageStart,
8558
+ pageEnd: pageEnd
8559
+ };
8560
+ return { pagination: pagination, pageStatus: pageStatus };
8561
+ };
8562
+
8535
8563
  var FieldWrap = React__default.forwardRef(function (_a, ref) {
8536
8564
  var children = _a.children, className = _a.className, _b = _a.as, Component = _b === void 0 ? 'div' : _b, props = tslib.__rest(_a, ["children", "className", "as"]);
8537
8565
  return (React__default.createElement(Component, tslib.__assign({ ref: ref, className: classNames('Panel', className) }, props), children));
@@ -8894,4 +8922,5 @@ exports.Workspace = Workspace;
8894
8922
  exports.focusableSelector = focusableSelector;
8895
8923
  exports.iconTypes = iconTypes;
8896
8924
  exports.useDidUpdate = useDidUpdate;
8925
+ exports.usePagination = usePagination;
8897
8926
  exports.useThemeContext = useThemeContext;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@deque/cauldron-react",
3
- "version": "4.5.0-canary.0c764a21",
3
+ "version": "4.5.0-canary.7f6a304a",
4
4
  "description": "Fully accessible react components library for Deque Cauldron",
5
5
  "publishConfig": {
6
6
  "access": "public"