@appdirect/design-system 0.0.17 → 0.0.18
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/bin/ad-sync-design-md.mjs +0 -0
- package/dist/ComplexComponents/DataTable/CellHoverReveal/CellHoverReveal.module.css +25 -0
- package/dist/ComplexComponents/DataTable/CellHoverReveal/index.js +24 -0
- package/dist/ComplexComponents/DataTable/CellHoverReveal/index.tsx +44 -0
- package/dist/ComplexComponents/DataTable/CustomBottomToolbar/CustomBottomToolbar.module.css +7 -0
- package/dist/ComplexComponents/DataTable/CustomBottomToolbar/index.js +25 -77
- package/dist/ComplexComponents/DataTable/CustomBottomToolbar/index.tsx +101 -157
- package/dist/ComplexComponents/DataTable/CustomBottomToolbar/utils.js +14 -7
- package/dist/ComplexComponents/DataTable/CustomBottomToolbar/utils.ts +13 -7
- package/dist/ComplexComponents/DataTable/CustomToolbarAlertBannerContent/CustomToolbarAlertBannerContent.module.css +4 -0
- package/dist/ComplexComponents/DataTable/CustomToolbarAlertBannerContent/index.js +8 -20
- package/dist/ComplexComponents/DataTable/CustomToolbarAlertBannerContent/index.tsx +40 -58
- package/dist/ComplexComponents/DataTable/CustomTopToolbar/CustomTopToolbar.module.css +7 -0
- package/dist/ComplexComponents/DataTable/CustomTopToolbar/DateRangeSelectorFilter/DateRangeSelectorFilter.module.css +3 -0
- package/dist/ComplexComponents/DataTable/CustomTopToolbar/DateRangeSelectorFilter/index.js +50 -154
- package/dist/ComplexComponents/DataTable/CustomTopToolbar/DateRangeSelectorFilter/index.tsx +59 -205
- package/dist/ComplexComponents/DataTable/CustomTopToolbar/DateRangeSelectorFilter/utils.js +48 -0
- package/dist/ComplexComponents/DataTable/CustomTopToolbar/DateRangeSelectorFilter/utils.ts +51 -0
- package/dist/ComplexComponents/DataTable/CustomTopToolbar/FilterChip.js +5 -25
- package/dist/ComplexComponents/DataTable/CustomTopToolbar/FilterChip.tsx +7 -28
- package/dist/ComplexComponents/DataTable/CustomTopToolbar/ResultCount.js +16 -0
- package/dist/ComplexComponents/DataTable/CustomTopToolbar/ResultCount.tsx +26 -0
- package/dist/ComplexComponents/DataTable/CustomTopToolbar/SearchFilter.js +26 -28
- package/dist/ComplexComponents/DataTable/CustomTopToolbar/SearchFilter.tsx +38 -38
- package/dist/ComplexComponents/DataTable/CustomTopToolbar/SelectFilter.js +8 -18
- package/dist/ComplexComponents/DataTable/CustomTopToolbar/SelectFilter.module.css +3 -0
- package/dist/ComplexComponents/DataTable/CustomTopToolbar/SelectFilter.tsx +25 -37
- package/dist/ComplexComponents/DataTable/CustomTopToolbar/index.js +67 -378
- package/dist/ComplexComponents/DataTable/CustomTopToolbar/index.tsx +170 -711
- package/dist/ComplexComponents/DataTable/DataTable.js +74 -393
- package/dist/ComplexComponents/DataTable/DataTable.tsx +229 -546
- package/dist/ComplexComponents/DataTable/DataTableGrid/DataTableGrid.module.css +85 -0
- package/dist/ComplexComponents/DataTable/DataTableGrid/index.js +46 -0
- package/dist/ComplexComponents/DataTable/DataTableGrid/index.tsx +143 -0
- package/dist/ComplexComponents/DataTable/DataTableShell/DataTableShell.module.css +38 -0
- package/dist/ComplexComponents/DataTable/DataTableShell/index.js +9 -0
- package/dist/ComplexComponents/DataTable/DataTableShell/index.tsx +47 -0
- package/dist/ComplexComponents/DataTable/ErrorOverlay/index.js +6 -6
- package/dist/ComplexComponents/DataTable/ErrorOverlay/index.tsx +53 -24
- package/dist/ComplexComponents/DataTable/SelectCheckbox/index.js +33 -0
- package/dist/ComplexComponents/DataTable/SelectCheckbox/index.tsx +63 -0
- package/dist/ComplexComponents/DataTable/SortableHeaderCell/SortableHeaderCell.module.css +3 -0
- package/dist/ComplexComponents/DataTable/SortableHeaderCell/index.js +43 -21
- package/dist/ComplexComponents/DataTable/SortableHeaderCell/index.tsx +62 -38
- package/dist/ComplexComponents/DataTable/ToggleDensityButton/index.js +18 -0
- package/dist/ComplexComponents/DataTable/ToggleDensityButton/index.tsx +47 -0
- package/dist/ComplexComponents/DataTable/ToggleFullScreenButton/index.js +19 -0
- package/dist/ComplexComponents/DataTable/ToggleFullScreenButton/index.tsx +59 -0
- package/dist/ComplexComponents/DataTable/ToolbarAlertBanner/ToolbarAlertBanner.module.css +15 -0
- package/dist/ComplexComponents/DataTable/ToolbarAlertBanner/index.js +8 -0
- package/dist/ComplexComponents/DataTable/ToolbarAlertBanner/index.tsx +20 -0
- package/dist/ComplexComponents/DataTable/hooks/useClickOutside.js +27 -0
- package/dist/ComplexComponents/DataTable/hooks/useClickOutside.ts +39 -0
- package/dist/ComplexComponents/DataTable/index.js +5 -1
- package/dist/ComplexComponents/DataTable/index.ts +13 -2
- package/dist/ComplexComponents/DataTable/table.module.css +9 -0
- package/dist/ComplexComponents/DataTable/tableFeatures.js +6 -0
- package/dist/ComplexComponents/DataTable/tableFeatures.ts +7 -0
- package/dist/ComplexComponents/DataTable/translations/en.js +16 -4
- package/dist/ComplexComponents/DataTable/translations/en.ts +16 -4
- package/dist/ComplexComponents/DataTable/translations/index.js +5 -0
- package/dist/ComplexComponents/DataTable/translations/index.ts +11 -1
- package/dist/ComplexComponents/DataTable/types.js +5 -0
- package/dist/ComplexComponents/DataTable/types.ts +17 -0
- package/dist/ComplexComponents/DataTable/utils/parseCSSVarId.js +3 -0
- package/dist/ComplexComponents/DataTable/utils/parseCSSVarId.ts +4 -0
- package/dist/DESIGN.md +9 -10
- package/dist/contracts/DataTable.json +83 -6
- package/dist/contracts/index.json +1 -1
- package/dist/css/foundations.css +4 -0
- package/dist/css/mantine.css +1 -1
- package/dist/css/tokens.css +3145 -0
- package/dist/index.js +3 -0
- package/dist/index.ts +14 -1
- package/dist/stories/ComplexComponents/DataTable/DataTable.stories.tsx +216 -458
- package/dist/stories/index.json +13 -15
- package/package.json +5 -3
- package/dist/ComplexComponents/DataTable/CustomTopToolbar/ResultCount/index.js +0 -31
- package/dist/ComplexComponents/DataTable/CustomTopToolbar/ResultCount/index.tsx +0 -76
- package/dist/hooks/useTableHandlers.js +0 -136
- package/dist/hooks/useTableHandlers.ts +0 -179
- package/dist/hooks/useTableRenderFunctions.js +0 -164
- package/dist/hooks/useTableRenderFunctions.tsx +0 -283
- package/dist/hooks/useTableState.js +0 -70
- package/dist/hooks/useTableState.ts +0 -81
|
File without changes
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
.cellHoverReveal {
|
|
2
|
+
white-space: nowrap;
|
|
3
|
+
overflow: hidden;
|
|
4
|
+
text-overflow: ellipsis;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
.overflowing:hover,
|
|
8
|
+
.overflowing:focus-visible {
|
|
9
|
+
overflow: visible;
|
|
10
|
+
white-space: normal;
|
|
11
|
+
position: absolute;
|
|
12
|
+
z-index: var(--ad-table-cell-reveal-z-index);
|
|
13
|
+
padding: var(--table-vertical-spacing) var(--table-horizontal-spacing);
|
|
14
|
+
background-color: var(--ad-table-cell-reveal-bg);
|
|
15
|
+
box-shadow: var(--ad-table-cell-reveal-shadow);
|
|
16
|
+
border: var(--ad-table-cell-reveal-border-width) solid var(--ad-table-cell-reveal-border-color);
|
|
17
|
+
text-indent: -1px;
|
|
18
|
+
width: max-content;
|
|
19
|
+
top: 0;
|
|
20
|
+
left: 0;
|
|
21
|
+
height: 100%;
|
|
22
|
+
display: flex;
|
|
23
|
+
justify-content: center;
|
|
24
|
+
align-items: center;
|
|
25
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
'use client'; // DS-ADAPT: Next.js App Router
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
// Source of truth: micro-ui-ts/src/components/Table/CellHoverReveal/index.tsx. Keep in sync; DS-only changes are marked DS-ADAPT.
|
|
4
|
+
import React, { useRef, useState } from "react";
|
|
5
|
+
import clsx from "clsx";
|
|
6
|
+
import styles from "./CellHoverReveal.module.css";
|
|
7
|
+
const CellHoverReveal = ({ children }) => {
|
|
8
|
+
const divRef = useRef(null);
|
|
9
|
+
const [isOverflowing, setIsOverflowing] = useState(false);
|
|
10
|
+
const onMouseEnter = () => {
|
|
11
|
+
const div = divRef.current;
|
|
12
|
+
if (div) {
|
|
13
|
+
setIsOverflowing(div.scrollWidth > div.clientWidth);
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
const onMouseLeave = () => {
|
|
17
|
+
setIsOverflowing(false);
|
|
18
|
+
};
|
|
19
|
+
return (
|
|
20
|
+
// Measures whether the cell text overflows. Not an action control.
|
|
21
|
+
// eslint-disable-next-line jsx-a11y/no-static-element-interactions
|
|
22
|
+
_jsx("div", { ref: divRef, "data-cell-hover-reveal": true, className: clsx(styles.cellHoverReveal, isOverflowing && styles.overflowing), onMouseEnter: onMouseEnter, onMouseLeave: onMouseLeave, tabIndex: 0, onFocus: onMouseEnter, onBlur: onMouseLeave, children: children }));
|
|
23
|
+
};
|
|
24
|
+
export default CellHoverReveal;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
'use client'; // DS-ADAPT: Next.js App Router
|
|
2
|
+
// Source of truth: micro-ui-ts/src/components/Table/CellHoverReveal/index.tsx. Keep in sync; DS-only changes are marked DS-ADAPT.
|
|
3
|
+
import React, { useRef, useState, type ReactElement, type ReactNode } from "react";
|
|
4
|
+
import clsx from "clsx";
|
|
5
|
+
import styles from "./CellHoverReveal.module.css";
|
|
6
|
+
|
|
7
|
+
interface CellHoverRevealProps {
|
|
8
|
+
children: ReactNode;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
const CellHoverReveal = ({ children }: CellHoverRevealProps): ReactElement => {
|
|
12
|
+
const divRef = useRef<HTMLDivElement>(null);
|
|
13
|
+
const [isOverflowing, setIsOverflowing] = useState(false);
|
|
14
|
+
|
|
15
|
+
const onMouseEnter = (): void => {
|
|
16
|
+
const div = divRef.current;
|
|
17
|
+
if (div) {
|
|
18
|
+
setIsOverflowing(div.scrollWidth > div.clientWidth);
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
const onMouseLeave = (): void => {
|
|
23
|
+
setIsOverflowing(false);
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
return (
|
|
27
|
+
// Measures whether the cell text overflows. Not an action control.
|
|
28
|
+
// eslint-disable-next-line jsx-a11y/no-static-element-interactions
|
|
29
|
+
<div
|
|
30
|
+
ref={divRef}
|
|
31
|
+
data-cell-hover-reveal
|
|
32
|
+
className={clsx(styles.cellHoverReveal, isOverflowing && styles.overflowing)}
|
|
33
|
+
onMouseEnter={onMouseEnter}
|
|
34
|
+
onMouseLeave={onMouseLeave}
|
|
35
|
+
tabIndex={0}
|
|
36
|
+
onFocus={onMouseEnter}
|
|
37
|
+
onBlur={onMouseLeave}
|
|
38
|
+
>
|
|
39
|
+
{children}
|
|
40
|
+
</div>
|
|
41
|
+
);
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
export default CellHoverReveal;
|
|
@@ -1,82 +1,30 @@
|
|
|
1
|
+
'use client'; // DS-ADAPT: Next.js App Router
|
|
1
2
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
// Source of truth: micro-ui-ts/src/components/Table/CustomBottomToolbar/index.tsx. Keep in sync; DS-only changes are marked DS-ADAPT.
|
|
2
4
|
import React, { useMemo } from "react";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
const TOOLBAR_STYLES = {
|
|
16
|
-
container: {
|
|
17
|
-
borderTop: "1px solid var(--ad-color-border-subtle)",
|
|
18
|
-
padding: `${rem(5)} ${rem(12)}`,
|
|
19
|
-
backgroundColor: "var(--ad-color-bg-subtle)",
|
|
20
|
-
},
|
|
21
|
-
select: {
|
|
22
|
-
width: "80px",
|
|
23
|
-
},
|
|
24
|
-
selectInput: {
|
|
25
|
-
backgroundColor: "transparent",
|
|
26
|
-
border: "none",
|
|
27
|
-
color: "var(--ad-color-text-default)",
|
|
28
|
-
fontSize: "var(--mantine-font-size-xs)",
|
|
29
|
-
},
|
|
30
|
-
};
|
|
31
|
-
/**
|
|
32
|
-
* Generate the appropriate selected rows text based on count
|
|
33
|
-
*/
|
|
34
|
-
const useSelectedRowsText = (numberOfSelectedRows) => {
|
|
35
|
-
return useMemo(() => {
|
|
36
|
-
if (numberOfSelectedRows === 0)
|
|
37
|
-
return null;
|
|
38
|
-
return numberOfSelectedRows === 1
|
|
39
|
-
? translate("table.selected.row")
|
|
40
|
-
: translate("table.selected.rows", { count: numberOfSelectedRows });
|
|
41
|
-
}, [numberOfSelectedRows]);
|
|
42
|
-
};
|
|
43
|
-
/**
|
|
44
|
-
* Calculate pagination information
|
|
45
|
-
*/
|
|
46
|
-
const usePaginationInfo = (pageIndex, totalCount, pageSize) => {
|
|
47
|
-
return useMemo(() => ({
|
|
48
|
-
totalPages: Math.ceil(totalCount / pageSize),
|
|
49
|
-
currentPage: pageIndex + 1,
|
|
50
|
-
}), [pageIndex, totalCount, pageSize]);
|
|
51
|
-
};
|
|
52
|
-
const CustomBottomToolbar = ({ table, totalCount, pageInfo, numberOfSelectedRows = 0, }) => {
|
|
53
|
-
const { getState, setPageIndex, setPageSize } = table;
|
|
54
|
-
const { pagination } = getState();
|
|
55
|
-
const { pageIndex, pageSize } = pagination;
|
|
56
|
-
const selectedRowsText = useSelectedRowsText(numberOfSelectedRows);
|
|
57
|
-
const { totalPages, currentPage } = usePaginationInfo(pageIndex, totalCount, pageSize);
|
|
58
|
-
const handlePageSizeChange = (value) => {
|
|
59
|
-
if (value) {
|
|
60
|
-
setPageSize(Number(value));
|
|
61
|
-
}
|
|
62
|
-
};
|
|
63
|
-
const handlePreviousPage = () => {
|
|
64
|
-
if (pageIndex > 0) {
|
|
65
|
-
setPageIndex(pageIndex - 1);
|
|
66
|
-
}
|
|
67
|
-
};
|
|
68
|
-
const handleNextPage = () => {
|
|
69
|
-
if (pageIndex < totalPages - 1) {
|
|
70
|
-
setPageIndex(pageIndex + 1);
|
|
71
|
-
}
|
|
5
|
+
import { Box, Flex, Select, ActionIcon, Text } from "@mantine/core";
|
|
6
|
+
import { RiArrowLeftSLine as PreviousPageIcon } from "@remixicon/react"; // DS-ADAPT: @remixicon/react instead of remixicon svg import
|
|
7
|
+
import { RiArrowRightSLine as NextPageIcon } from "@remixicon/react"; // DS-ADAPT: @remixicon/react instead of remixicon svg import
|
|
8
|
+
import { translate } from "../translations/index.js"; // DS-ADAPT: translate lives in DataTable/translations
|
|
9
|
+
import { getFormattedPageCount, getFormattedPageSize, getNumOfRowsPerPageOptions } from "./utils.js";
|
|
10
|
+
import styles from "./CustomBottomToolbar.module.css";
|
|
11
|
+
/** Keeps the page-size control compact; value is max two digits (e.g. 40). */
|
|
12
|
+
const PAGE_SIZE_SELECT_WIDTH = "var(--ad-table-toolbar-page-size-width)";
|
|
13
|
+
const CustomBottomToolbar = ({ paginationState, onPageSizeChange, onNextPage, onPreviousPage, isDisabled = false, hasNextPage, hasPreviousPage, totalNumOfRows = 0, isFetching = false, numberOfSelectedRowsText, }) => {
|
|
14
|
+
const rowCount = totalNumOfRows; // DS-ADAPT: derive directly; copying in an effect lags one render
|
|
15
|
+
const onPageSizeChangeHandler = (newPageSize) => {
|
|
16
|
+
onPageSizeChange(getFormattedPageSize(newPageSize));
|
|
72
17
|
};
|
|
73
|
-
const
|
|
74
|
-
const
|
|
75
|
-
return (_jsxs(
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
18
|
+
const formattedPageLegend = getFormattedPageCount(paginationState.pageIndex, paginationState.pageSize, rowCount);
|
|
19
|
+
const numOfRowsPerPageOptions = useMemo(() => getNumOfRowsPerPageOptions(rowCount, undefined, paginationState.pageSize), [rowCount, paginationState.pageSize]);
|
|
20
|
+
return (_jsxs(Flex, { className: styles.toolbar, bg: "var(--ad-color-bg-subtle)", px: "md", py: "xshalf", justify: "space-between", align: "center", children: [_jsxs(Flex, { align: "center", gap: "sm", w: "fit-content", flex: "none", children: [_jsx(Text, { size: "xs", children: translate("table.rows.per.page") }), _jsx(Box, { w: PAGE_SIZE_SELECT_WIDTH, className: styles.pageSize, children: _jsx(Select, { disabled: !rowCount || isDisabled, "aria-label": translate("table.rows.per.page"), data: numOfRowsPerPageOptions, value: paginationState.pageSize.toString(), onChange: onPageSizeChangeHandler, size: "xs", w: "100%", rightSectionWidth: 22, variant: "unstyled", comboboxProps: { withinPortal: false, width: "max-content" } }) })] }), numberOfSelectedRowsText && _jsx(Text, { size: "xs", children: numberOfSelectedRowsText }), _jsxs(Flex, { align: "center", gap: "xs", children: [_jsx(Text, { size: "xs", children: formattedPageLegend }), _jsx(ActionIcon, { "data-testid": "previous-page-btn", disabled: !hasPreviousPage || isDisabled, onClick: () => {
|
|
21
|
+
if (!isFetching && onPreviousPage) {
|
|
22
|
+
onPreviousPage();
|
|
23
|
+
}
|
|
24
|
+
}, variant: "subtle", color: "var(--ad-color-text-default)", w: 30, "aria-label": translate("table.previous.page.aria"), children: _jsx(PreviousPageIcon, { style: { width: "70%", height: "70%" } }) }), _jsx(ActionIcon, { "data-testid": "next-page-btn", disabled: !hasNextPage || isDisabled, onClick: () => {
|
|
25
|
+
if (!isFetching && onNextPage) {
|
|
26
|
+
onNextPage();
|
|
27
|
+
}
|
|
28
|
+
}, variant: "subtle", color: "var(--ad-color-text-default)", w: 30, "aria-label": translate("table.next.page.aria"), children: _jsx(NextPageIcon, { style: { width: "70%", height: "70%" } }) })] })] }));
|
|
81
29
|
};
|
|
82
30
|
export default CustomBottomToolbar;
|
|
@@ -1,176 +1,120 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
} from "
|
|
8
|
-
import { translate } from
|
|
9
|
-
import {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
padding: `${rem(5)} ${rem(12)}`,
|
|
24
|
-
backgroundColor: "var(--ad-color-bg-subtle)",
|
|
25
|
-
},
|
|
26
|
-
select: {
|
|
27
|
-
width: "80px",
|
|
28
|
-
},
|
|
29
|
-
selectInput: {
|
|
30
|
-
backgroundColor: "transparent",
|
|
31
|
-
border: "none",
|
|
32
|
-
color: "var(--ad-color-text-default)",
|
|
33
|
-
fontSize: "var(--mantine-font-size-xs)",
|
|
34
|
-
},
|
|
35
|
-
} as const;
|
|
36
|
-
|
|
37
|
-
interface PageInfo {
|
|
38
|
-
hasNextPage: boolean;
|
|
39
|
-
hasPreviousPage: boolean;
|
|
40
|
-
startCursor?: string;
|
|
41
|
-
endCursor?: string;
|
|
1
|
+
'use client'; // DS-ADAPT: Next.js App Router
|
|
2
|
+
// Source of truth: micro-ui-ts/src/components/Table/CustomBottomToolbar/index.tsx. Keep in sync; DS-only changes are marked DS-ADAPT.
|
|
3
|
+
import React, { useMemo, ReactElement } from "react";
|
|
4
|
+
import { Box, Flex, Select, ActionIcon, Text } from "@mantine/core";
|
|
5
|
+
import { RiArrowLeftSLine as PreviousPageIcon } from "@remixicon/react"; // DS-ADAPT: @remixicon/react instead of remixicon svg import
|
|
6
|
+
import { RiArrowRightSLine as NextPageIcon } from "@remixicon/react"; // DS-ADAPT: @remixicon/react instead of remixicon svg import
|
|
7
|
+
import { PaginationState } from "../types";
|
|
8
|
+
import { translate } from "../translations"; // DS-ADAPT: translate lives in DataTable/translations
|
|
9
|
+
import { getFormattedPageCount, getFormattedPageSize, getNumOfRowsPerPageOptions } from "./utils";
|
|
10
|
+
import styles from "./CustomBottomToolbar.module.css";
|
|
11
|
+
|
|
12
|
+
export interface CustomBottomToolbarProps {
|
|
13
|
+
paginationState: PaginationState;
|
|
14
|
+
onPageSizeChange: (pageSize: number) => void;
|
|
15
|
+
isDisabled?: boolean;
|
|
16
|
+
onNextPage?: () => void;
|
|
17
|
+
onPreviousPage?: () => void;
|
|
18
|
+
hasPreviousPage?: boolean;
|
|
19
|
+
hasNextPage?: boolean;
|
|
20
|
+
totalNumOfRows: number | undefined;
|
|
21
|
+
isFetching?: boolean;
|
|
22
|
+
numberOfSelectedRowsText?: string; // if row selection is enabled
|
|
42
23
|
}
|
|
43
24
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
/**
|
|
65
|
-
* Calculate pagination information
|
|
66
|
-
*/
|
|
67
|
-
const usePaginationInfo = (pageIndex: number, totalCount: number, pageSize: number) => {
|
|
68
|
-
return useMemo(() => ({
|
|
69
|
-
totalPages: Math.ceil(totalCount / pageSize),
|
|
70
|
-
currentPage: pageIndex + 1,
|
|
71
|
-
}), [pageIndex, totalCount, pageSize]);
|
|
72
|
-
};
|
|
73
|
-
|
|
74
|
-
const CustomBottomToolbar = <T extends MRT_RowData>({
|
|
75
|
-
table,
|
|
76
|
-
totalCount,
|
|
77
|
-
pageInfo,
|
|
78
|
-
numberOfSelectedRows = 0,
|
|
79
|
-
}: CustomBottomToolbarProps<T>): ReactElement => {
|
|
80
|
-
const { getState, setPageIndex, setPageSize } = table;
|
|
81
|
-
const { pagination } = getState();
|
|
82
|
-
const { pageIndex, pageSize } = pagination;
|
|
83
|
-
|
|
84
|
-
const selectedRowsText = useSelectedRowsText(numberOfSelectedRows);
|
|
85
|
-
const { totalPages, currentPage } = usePaginationInfo(pageIndex, totalCount, pageSize);
|
|
86
|
-
|
|
87
|
-
const handlePageSizeChange = (value: string | null) => {
|
|
88
|
-
if (value) {
|
|
89
|
-
setPageSize(Number(value));
|
|
90
|
-
}
|
|
25
|
+
/** Keeps the page-size control compact; value is max two digits (e.g. 40). */
|
|
26
|
+
const PAGE_SIZE_SELECT_WIDTH = "var(--ad-table-toolbar-page-size-width)";
|
|
27
|
+
|
|
28
|
+
const CustomBottomToolbar = ({
|
|
29
|
+
paginationState,
|
|
30
|
+
onPageSizeChange,
|
|
31
|
+
onNextPage,
|
|
32
|
+
onPreviousPage,
|
|
33
|
+
isDisabled = false,
|
|
34
|
+
hasNextPage,
|
|
35
|
+
hasPreviousPage,
|
|
36
|
+
totalNumOfRows = 0,
|
|
37
|
+
isFetching = false,
|
|
38
|
+
numberOfSelectedRowsText,
|
|
39
|
+
}: CustomBottomToolbarProps): ReactElement => {
|
|
40
|
+
const rowCount = totalNumOfRows; // DS-ADAPT: derive directly; copying in an effect lags one render
|
|
41
|
+
|
|
42
|
+
const onPageSizeChangeHandler = (newPageSize: string | null): void => {
|
|
43
|
+
onPageSizeChange(getFormattedPageSize(newPageSize));
|
|
91
44
|
};
|
|
92
45
|
|
|
93
|
-
const
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
const handleNextPage = () => {
|
|
100
|
-
if (pageIndex < totalPages - 1) {
|
|
101
|
-
setPageIndex(pageIndex + 1);
|
|
102
|
-
}
|
|
103
|
-
};
|
|
46
|
+
const formattedPageLegend = getFormattedPageCount(
|
|
47
|
+
paginationState.pageIndex,
|
|
48
|
+
paginationState.pageSize,
|
|
49
|
+
rowCount
|
|
50
|
+
);
|
|
104
51
|
|
|
105
|
-
const
|
|
106
|
-
|
|
52
|
+
const numOfRowsPerPageOptions = useMemo(
|
|
53
|
+
() => getNumOfRowsPerPageOptions(rowCount, undefined, paginationState.pageSize),
|
|
54
|
+
[rowCount, paginationState.pageSize]
|
|
55
|
+
);
|
|
107
56
|
|
|
108
57
|
return (
|
|
109
|
-
<
|
|
110
|
-
|
|
111
|
-
|
|
58
|
+
<Flex
|
|
59
|
+
className={styles.toolbar}
|
|
60
|
+
bg="var(--ad-color-bg-subtle)"
|
|
61
|
+
px="md"
|
|
62
|
+
py="xshalf"
|
|
63
|
+
justify="space-between"
|
|
64
|
+
align="center"
|
|
112
65
|
>
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
<
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
</
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
<Inline gap="xs">
|
|
134
|
-
{selectedRowsText && (
|
|
135
|
-
<Text size="sm">
|
|
136
|
-
{selectedRowsText}
|
|
137
|
-
</Text>
|
|
138
|
-
)}
|
|
139
|
-
</Inline>
|
|
140
|
-
|
|
141
|
-
{/* Right section - Page navigation */}
|
|
142
|
-
<Inline gap="xs">
|
|
66
|
+
<Flex align="center" gap="sm" w="fit-content" flex="none">
|
|
67
|
+
<Text size="xs">{translate("table.rows.per.page")}</Text>
|
|
68
|
+
<Box w={PAGE_SIZE_SELECT_WIDTH} className={styles.pageSize}>
|
|
69
|
+
<Select
|
|
70
|
+
disabled={!rowCount || isDisabled}
|
|
71
|
+
aria-label={translate("table.rows.per.page")}
|
|
72
|
+
data={numOfRowsPerPageOptions}
|
|
73
|
+
value={paginationState.pageSize.toString()}
|
|
74
|
+
onChange={onPageSizeChangeHandler}
|
|
75
|
+
size="xs"
|
|
76
|
+
w="100%"
|
|
77
|
+
rightSectionWidth={22}
|
|
78
|
+
variant="unstyled"
|
|
79
|
+
comboboxProps={{ withinPortal: false, width: "max-content" }}
|
|
80
|
+
/>
|
|
81
|
+
</Box>
|
|
82
|
+
</Flex>
|
|
83
|
+
{numberOfSelectedRowsText && <Text size="xs">{numberOfSelectedRowsText}</Text>}
|
|
84
|
+
<Flex align="center" gap="xs">
|
|
85
|
+
<Text size="xs">{formattedPageLegend}</Text>
|
|
143
86
|
<ActionIcon
|
|
87
|
+
data-testid="previous-page-btn"
|
|
88
|
+
disabled={!hasPreviousPage || isDisabled}
|
|
89
|
+
onClick={(): void => {
|
|
90
|
+
if (!isFetching && onPreviousPage) {
|
|
91
|
+
onPreviousPage();
|
|
92
|
+
}
|
|
93
|
+
}}
|
|
144
94
|
variant="subtle"
|
|
145
|
-
color="
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
disabled={!canGoPrevious}
|
|
149
|
-
aria-label="Previous page"
|
|
95
|
+
color="var(--ad-color-text-default)"
|
|
96
|
+
w={30}
|
|
97
|
+
aria-label={translate("table.previous.page.aria")}
|
|
150
98
|
>
|
|
151
|
-
<
|
|
99
|
+
<PreviousPageIcon style={{ width: "70%", height: "70%" }} />
|
|
152
100
|
</ActionIcon>
|
|
153
|
-
|
|
154
|
-
<Text size="sm">
|
|
155
|
-
{translate("table.pagination.page", {
|
|
156
|
-
current: currentPage,
|
|
157
|
-
total: totalPages,
|
|
158
|
-
})}
|
|
159
|
-
</Text>
|
|
160
|
-
|
|
161
101
|
<ActionIcon
|
|
102
|
+
data-testid="next-page-btn"
|
|
103
|
+
disabled={!hasNextPage || isDisabled}
|
|
104
|
+
onClick={(): void => {
|
|
105
|
+
if (!isFetching && onNextPage) {
|
|
106
|
+
onNextPage();
|
|
107
|
+
}
|
|
108
|
+
}}
|
|
162
109
|
variant="subtle"
|
|
163
|
-
color="
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
disabled={!canGoNext}
|
|
167
|
-
aria-label="Next page"
|
|
110
|
+
color="var(--ad-color-text-default)"
|
|
111
|
+
w={30}
|
|
112
|
+
aria-label={translate("table.next.page.aria")}
|
|
168
113
|
>
|
|
169
|
-
<
|
|
114
|
+
<NextPageIcon style={{ width: "70%", height: "70%" }} />
|
|
170
115
|
</ActionIcon>
|
|
171
|
-
</
|
|
172
|
-
|
|
173
|
-
</Inline>
|
|
116
|
+
</Flex>
|
|
117
|
+
</Flex>
|
|
174
118
|
);
|
|
175
119
|
};
|
|
176
120
|
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
// Source of truth: micro-ui-ts/src/components/Table/CustomBottomToolbar/utils.ts. Keep in sync; DS-only changes are marked DS-ADAPT.
|
|
2
|
+
import { translate } from "../translations/index.js"; // DS-ADAPT: translate lives in DataTable/translations
|
|
2
3
|
const DEFAULT_PAGE_SIZE = 5;
|
|
3
4
|
export const getFormattedPageSize = (newPageSize) => newPageSize ? parseInt(newPageSize, 10) : DEFAULT_PAGE_SIZE;
|
|
4
5
|
export const getFormattedPageCount = (pageIndex, pageSize, rowCount) => {
|
|
@@ -11,13 +12,19 @@ export const getFormattedPageCount = (pageIndex, pageSize, rowCount) => {
|
|
|
11
12
|
total: rowCount,
|
|
12
13
|
});
|
|
13
14
|
};
|
|
14
|
-
export const getNumOfRowsPerPageOptions = (totalNumOfRows, increment = DEFAULT_PAGE_SIZE
|
|
15
|
+
export const getNumOfRowsPerPageOptions = (totalNumOfRows, increment = DEFAULT_PAGE_SIZE, currentPageSize // DS-ADAPT: always keep the active page size selectable so the controlled Select never shows a value missing from its data
|
|
16
|
+
) => {
|
|
17
|
+
const sizes = new Set();
|
|
15
18
|
if (!totalNumOfRows) {
|
|
16
|
-
|
|
19
|
+
sizes.add(increment);
|
|
17
20
|
}
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
+
else {
|
|
22
|
+
for (let i = increment; i - increment < totalNumOfRows; i += increment) {
|
|
23
|
+
sizes.add(i);
|
|
24
|
+
}
|
|
21
25
|
}
|
|
22
|
-
|
|
26
|
+
if (currentPageSize) {
|
|
27
|
+
sizes.add(currentPageSize);
|
|
28
|
+
}
|
|
29
|
+
return [...sizes].sort((a, b) => a - b).map(size => size.toString());
|
|
23
30
|
};
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
// Source of truth: micro-ui-ts/src/components/Table/CustomBottomToolbar/utils.ts. Keep in sync; DS-only changes are marked DS-ADAPT.
|
|
2
|
+
import { translate } from "../translations"; // DS-ADAPT: translate lives in DataTable/translations
|
|
2
3
|
|
|
3
4
|
const DEFAULT_PAGE_SIZE = 5;
|
|
4
5
|
|
|
@@ -22,14 +23,19 @@ export const getFormattedPageCount = (
|
|
|
22
23
|
|
|
23
24
|
export const getNumOfRowsPerPageOptions = (
|
|
24
25
|
totalNumOfRows: number,
|
|
25
|
-
increment = DEFAULT_PAGE_SIZE
|
|
26
|
+
increment = DEFAULT_PAGE_SIZE,
|
|
27
|
+
currentPageSize?: number // DS-ADAPT: always keep the active page size selectable so the controlled Select never shows a value missing from its data
|
|
26
28
|
): string[] => {
|
|
29
|
+
const sizes = new Set<number>();
|
|
27
30
|
if (!totalNumOfRows) {
|
|
28
|
-
|
|
31
|
+
sizes.add(increment);
|
|
32
|
+
} else {
|
|
33
|
+
for (let i = increment; i - increment < totalNumOfRows; i += increment) {
|
|
34
|
+
sizes.add(i);
|
|
35
|
+
}
|
|
29
36
|
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
options.push(i.toString());
|
|
37
|
+
if (currentPageSize) {
|
|
38
|
+
sizes.add(currentPageSize);
|
|
33
39
|
}
|
|
34
|
-
return
|
|
40
|
+
return [...sizes].sort((a, b) => a - b).map(size => size.toString());
|
|
35
41
|
};
|
|
@@ -1,23 +1,11 @@
|
|
|
1
|
-
|
|
1
|
+
'use client'; // DS-ADAPT: Next.js App Router
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
// Source of truth: micro-ui-ts/src/components/Table/CustomToolbartAlertBannerContent/index.tsx. Keep in sync; DS-only changes are marked DS-ADAPT.
|
|
4
|
+
import { ActionIcon, Button, Text, Group, rem } from "@mantine/core";
|
|
2
5
|
import React from "react";
|
|
3
|
-
import {
|
|
4
|
-
import
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
import { RiFlashlightFill } from '@remixicon/react';
|
|
8
|
-
import { translate } from '../translations/index.js';
|
|
9
|
-
const CustomToolbarAlertBannerContent = ({ numberOfSelectedRows, onClearSelection, }) => {
|
|
10
|
-
if (numberOfSelectedRows === 0) {
|
|
11
|
-
return _jsx(_Fragment, {});
|
|
12
|
-
}
|
|
13
|
-
const selectedRowsText = numberOfSelectedRows === 1
|
|
14
|
-
? translate("table.selected.row")
|
|
15
|
-
: translate("table.selected.rows", { count: numberOfSelectedRows });
|
|
16
|
-
return (_jsxs(Inline, { gap: "sm", align: "center", style: {
|
|
17
|
-
background: 'var(--ad-color-brand-primary)',
|
|
18
|
-
color: 'var(--ad-white)',
|
|
19
|
-
borderRadius: 0,
|
|
20
|
-
minHeight: 'var(--mantine-spacing-xl)',
|
|
21
|
-
}, children: [_jsx(ActionIcon, { variant: "transparent", color: "white", onClick: onClearSelection, "aria-label": "Clear selection", size: "sm", children: _jsx(IconX, { size: 16 }) }), _jsx(Button, { variant: "outline", color: "gray", size: "xs", leftSection: _jsx(RiFlashlightFill, { size: 16 }), style: { borderColor: 'white', color: 'white' }, children: "Button one" }), _jsx(Button, { variant: "outline", color: "gray", size: "xs", leftSection: _jsx(RiFlashlightFill, { size: 16 }), style: { borderColor: 'white', color: 'white' }, children: "Button two" }), _jsx(Text, { size: "sm", c: "white", fw: 500, children: selectedRowsText })] }));
|
|
6
|
+
import { IconX } from "@tabler/icons-react";
|
|
7
|
+
import styles from "./CustomToolbarAlertBannerContent.module.css";
|
|
8
|
+
const CustomToolbarAlertBannerContent = ({ resetRowSelection, numberOfSelectedRowsText, actions, }) => {
|
|
9
|
+
return (_jsxs(Group, { gap: "xs", children: [_jsx(ActionIcon, { size: "md", variant: "transparent", color: "white", onClick: resetRowSelection, "aria-label": "close", children: _jsx(IconX, { style: { width: rem(14), height: rem(14) } }) }), actions.map((action) => (_jsx(Button, { onClick: action.onClick, size: "xs", variant: "outline", leftSection: action.SVGIcon, className: styles.action, "aria-label": action.label, children: action.label }, action.label))), _jsx(Text, { size: "sm", c: "inherit", children: numberOfSelectedRowsText })] }));
|
|
22
10
|
};
|
|
23
11
|
export default CustomToolbarAlertBannerContent;
|