@luscii-healthtech/web-ui 30.9.1 → 30.10.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.
@@ -1,13 +1,28 @@
1
- export interface PaginationMenuProps {
2
- pageCount: number;
3
- currentPageNumber: number;
4
- onChange: OnPaginationChange;
5
- pageSize?: PageSize;
6
- localization?: Localization;
7
- resultCount?: number;
8
- small?: boolean;
1
+ export type PaginationMenuProps = {
9
2
  className?: string;
10
- }
3
+ type?: "small" | "large" | "cursor";
4
+ /** @deprecated use type instead */
5
+ small?: boolean;
6
+ pageSize?: PageSize;
7
+ } & (PaginationMenuPropsSmall | PaginationMenuPropsLarge | PaginationMenuPropsCursor);
8
+ type PaginationMenuPropsSmall = ({
9
+ type: "small";
10
+ small?: never;
11
+ } | {
12
+ small: true;
13
+ type?: never;
14
+ }) & PaginationMenuSmallProps;
15
+ type PaginationMenuPropsLarge = ({
16
+ type: "large";
17
+ small?: never;
18
+ } | {
19
+ small?: false | undefined;
20
+ type?: never;
21
+ }) & PaginationMenuLargeProps;
22
+ type PaginationMenuPropsCursor = {
23
+ type: "cursor";
24
+ small?: never;
25
+ } & PaginationMenuCursorProps;
11
26
  export interface PaginationMenuSmallProps {
12
27
  pageCount: number;
13
28
  currentPageNumber: number;
@@ -22,7 +37,15 @@ export interface PaginationMenuLargeProps {
22
37
  localization: Localization;
23
38
  resultCount?: number;
24
39
  }
40
+ export interface PaginationMenuCursorProps {
41
+ previousCursor?: string | null;
42
+ nextCursor?: string | null;
43
+ onChange: OnPaginationCursorChange;
44
+ pageSize?: number;
45
+ localization: Pick<Localization, "previous" | "next">;
46
+ }
25
47
  export type OnPaginationChange = (pageNumber: number, pageSize?: PageSize) => void;
48
+ export type OnPaginationCursorChange = (newCursor: string) => void;
26
49
  export type PageSize = 25 | 50 | 75 | 100;
27
50
  export interface Localization {
28
51
  display: string;
@@ -35,3 +58,4 @@ export type Option = {
35
58
  value: number;
36
59
  label: string;
37
60
  };
61
+ export {};
@@ -0,0 +1,3 @@
1
+ import React from "react";
2
+ import { PaginationMenuCursorProps } from "./PaginationMenu.types";
3
+ export declare const PaginationMenuCursor: (props: PaginationMenuCursorProps) => React.JSX.Element;
@@ -1,6 +1,8 @@
1
+ import { PaginationMenuProps } from "../PaginationMenu/PaginationMenu.types";
1
2
  import { TableFieldText, TableFieldAction, TableFieldContent } from "./Table.types";
2
3
  export declare function isTableFieldText<Item>(content: TableFieldContent<Item>): content is TableFieldText;
3
4
  export declare function isTableFieldAction<Item>(content: TableFieldContent<Item>): content is [TableFieldAction<Item>?, TableFieldAction<Item>?];
5
+ export declare const shouldShowPagination: (paginationMenuProps: PaginationMenuProps | undefined) => paginationMenuProps is PaginationMenuProps;
4
6
  /**
5
7
  * This function is to be used when the data we need can be completely on the client side.
6
8
  * By doing so we have a centralized way to deal with pagination.
@@ -3745,6 +3745,15 @@ function isTableFieldText(content) {
3745
3745
  function isTableFieldAction(content) {
3746
3746
  return Array.isArray(content) && content.some((action) => action && "key" in action && "icon" in action && "handleClick" in action);
3747
3747
  }
3748
+ const shouldShowPagination = (paginationMenuProps) => {
3749
+ if (!paginationMenuProps) {
3750
+ return false;
3751
+ }
3752
+ if (paginationMenuProps.type === "cursor") {
3753
+ return Boolean(paginationMenuProps.previousCursor || paginationMenuProps.nextCursor);
3754
+ }
3755
+ return paginationMenuProps.currentPageNumber > 0 && paginationMenuProps.pageCount > 0;
3756
+ };
3748
3757
  function prepareClientSidePagination({
3749
3758
  /**
3750
3759
  * The array to be split into chunks.
@@ -3866,11 +3875,20 @@ function TableBody(props) {
3866
3875
  ) },
3867
3876
  !props.isLoading && ((_a = props.items) === null || _a === void 0 ? void 0 : _a.map((item, index) => React__namespace.default.createElement(
3868
3877
  "tr",
3869
- { tabIndex: 0, className: classNames__default.default("ui-group", {
3870
- "ui-cursor-pointer ui-transition-colors ui-duration-300 ui-ease-in-out hover:ui-bg-blue-50 focus:ui-outline-primary": props.onRowClick,
3871
- "ui-cursor-default hover:ui-bg-white": !props.onRowClick,
3872
- "ui-bg-blue-100": isItemChecked(index)
3873
- }, props.className), onClick: generateRowClickHandler(item) },
3878
+ {
3879
+ /**
3880
+ * Not the best, but I'm re-adding what it existed in the TableBodyRow:
3881
+ * https://github.com/Luscii/web-ui/pull/820/files#diff-a4cc940bcb5cc070b340404e9d7fb626ab529bac099dba0cb0b8b2b0cbc274bfL67
3882
+ */
3883
+ key: JSON.stringify(item),
3884
+ tabIndex: 0,
3885
+ className: classNames__default.default("ui-group", {
3886
+ "ui-cursor-pointer ui-transition-colors ui-duration-300 ui-ease-in-out hover:ui-bg-blue-50 focus:ui-outline-primary": props.onRowClick,
3887
+ "ui-cursor-default hover:ui-bg-white": !props.onRowClick,
3888
+ "ui-bg-blue-100": isItemChecked(index)
3889
+ }, props.className),
3890
+ onClick: generateRowClickHandler(item)
3891
+ },
3874
3892
  props.isSelectable && React__namespace.default.createElement(
3875
3893
  "td",
3876
3894
  { className: "ui-px-2 first:ui-pl-6 last:ui-pr-6" },
@@ -4097,15 +4115,27 @@ const PaginationMenuLarge = (props) => {
4097
4115
  );
4098
4116
  };
4099
4117
 
4100
- const PaginationMenu = (props) => {
4101
- const buildPaginationLarge = () => {
4102
- if (!props.localization) {
4103
- console.error("Localization is required to use the non small Pagination component, please make sure to pass it as a prop.");
4104
- return React__namespace.default.createElement("span", null, "Invalid props passed to this component.");
4105
- }
4106
- return React__namespace.default.createElement(PaginationMenuLarge, { pageCount: props.pageCount, currentPageNumber: props.currentPageNumber, onChange: props.onChange, pageSize: props.pageSize, localization: props.localization, resultCount: props.resultCount });
4118
+ const PaginationMenuCursor = (props) => {
4119
+ const handleOnChange = (event) => {
4120
+ const cursor = event.currentTarget.dataset.cursor;
4121
+ cursor && props.onChange(cursor);
4107
4122
  };
4108
- return React__namespace.default.createElement("div", { className: classNames__default.default("ui-flex ui-w-full ui-flex-row ui-items-center ui-justify-between", props.className) }, props.small ? React__namespace.default.createElement(PaginationMenuSmall, { pageCount: props.pageCount, currentPageNumber: props.currentPageNumber, pageSize: props.pageSize, onChange: props.onChange }) : buildPaginationLarge());
4123
+ return React__namespace.default.createElement(
4124
+ Stack,
4125
+ { axis: "x", gap: "m", justify: "end", width: "full" },
4126
+ React__namespace.default.createElement(SecondaryButton, { "data-test-id": "prev-button", leadingIcon: React__namespace.default.createElement(LeftArrowIcon, null), "data-cursor": props.previousCursor, isDisabled: !props.previousCursor, onClick: handleOnChange }, props.localization.previous),
4127
+ React__namespace.default.createElement(SecondaryButton, { "data-test-id": "next-button", trailingIcon: React__namespace.default.createElement(RightArrowIcon, null), "data-cursor": props.nextCursor, isDisabled: !props.nextCursor, onClick: handleOnChange }, props.localization.next)
4128
+ );
4129
+ };
4130
+
4131
+ const PaginationMenu = (props) => {
4132
+ return React__namespace.default.createElement(
4133
+ "div",
4134
+ { className: classNames__default.default("ui-flex ui-w-full ui-flex-row ui-items-center ui-justify-between", props.className) },
4135
+ (props.type === "small" || props.small) && React__namespace.default.createElement(PaginationMenuSmall, { pageCount: props.pageCount, currentPageNumber: props.currentPageNumber, pageSize: props.pageSize, onChange: props.onChange }),
4136
+ (props.type === "large" || !props.small && props.type === void 0) && React__namespace.default.createElement(PaginationMenuLarge, { pageCount: props.pageCount, currentPageNumber: props.currentPageNumber, onChange: props.onChange, pageSize: props.pageSize, localization: props.localization, resultCount: props.resultCount }),
4137
+ props.type === "cursor" && React__namespace.default.createElement(PaginationMenuCursor, { previousCursor: props.previousCursor, nextCursor: props.nextCursor, onChange: props.onChange, pageSize: props.pageSize, localization: props.localization })
4138
+ );
4109
4139
  };
4110
4140
 
4111
4141
  const TableFooter = (props) => {
@@ -4147,7 +4177,7 @@ function Table(_a) {
4147
4177
  setIsPristine(false);
4148
4178
  }, [items, isLoading]);
4149
4179
  const showEmptyView = !isPristine && !isLoading && !(items && items.length > 0);
4150
- const showFooter = !isLoading && !showEmptyView && paginationMenuProps && paginationMenuProps.currentPageNumber > 0 && paginationMenuProps.pageCount > 0;
4180
+ const showFooter = !isLoading && !showEmptyView && shouldShowPagination(paginationMenuProps);
4151
4181
  const colSpan = isSelectable ? fieldConfigurations.length + 1 : fieldConfigurations.length;
4152
4182
  const handleOnToggleAll = () => {
4153
4183
  const newState = getSelectAllCheckboxState() === "checked" ? [] : (items !== null && items !== void 0 ? items : []).map((value, index) => ({