@eml-payments/ui-kit 1.8.13 → 1.8.15
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/dist/index.css +2 -2
- package/dist/index.d.cts +488 -0
- package/dist/index.d.ts +488 -0
- package/dist/src/components/Alert/Alert.types.d.ts +1 -1
- package/dist/src/components/Alert/AlertContainer.stories.js +8 -16
- package/dist/src/components/ButtonGroup/ButtonGroup.types.d.ts +3 -3
- package/dist/src/components/Calendar/Calendar.d.ts +1 -1
- package/dist/src/components/Checkbox/Checkbox.js +1 -1
- package/dist/src/components/Checkbox/Checkbox.stories.js +6 -8
- package/dist/src/components/Counter/Counter.d.ts +1 -1
- package/dist/src/components/Counter/Counter.js +9 -1
- package/dist/src/components/DatePicker/DatePicker.js +168 -13
- package/dist/src/components/Dropdown/Dropdown.d.ts +2 -2
- package/dist/src/components/Filters/Filters.js +1 -1
- package/dist/src/components/Pills/Pills.stories.d.ts +1 -1
- package/dist/src/components/Pills/Pills.stories.js +1 -1
- package/dist/src/components/Skeleton/Skeleton.d.ts +1 -1
- package/dist/src/components/Skeleton/Skeleton.js +1 -1
- package/dist/src/components/Spinner/Spinner.d.ts +1 -1
- package/dist/src/components/Stepper/useStepper.js +1 -1
- package/dist/src/components/Switch/Switch.js +1 -1
- package/dist/src/components/Switch/Switch.stories.js +6 -8
- package/dist/src/components/Table/BaseTable/index.d.ts +1 -0
- package/dist/src/components/Table/BaseTable/index.js +1 -0
- package/dist/src/components/Table/Pagination/Pagination.types.d.ts +2 -2
- package/dist/src/components/Table/Pagination/PaginationControls.d.ts +3 -0
- package/dist/src/components/Table/Pagination/PaginationControls.js +22 -0
- package/dist/src/components/Table/Pagination/PaginationControls.types.d.ts +24 -0
- package/dist/src/components/Table/Pagination/PaginationControls.types.js +1 -0
- package/dist/src/components/Table/Table.d.ts +4 -0
- package/dist/src/components/Table/Table.js +93 -0
- package/dist/src/components/Table/Table.stories.d.ts +31 -0
- package/dist/src/components/Table/Table.stories.js +479 -0
- package/dist/src/components/Table/hooks/useInfiniteScrolling.d.ts +29 -0
- package/dist/src/components/Table/hooks/useInfiniteScrolling.js +96 -0
- package/dist/src/components/Table/hooks/usePaginationController.d.ts +16 -0
- package/dist/src/components/Table/hooks/usePaginationController.js +30 -0
- package/dist/src/components/Table/hooks/useTableController.d.ts +26 -0
- package/dist/src/components/Table/hooks/useTableController.js +146 -0
- package/dist/src/context/UIKitProvider.js +2 -3
- package/dist/src/stories/Page.js +1 -1
- package/package.json +1 -5
- package/dist/src/assets/index.d.ts +0 -2
- package/dist/src/assets/index.js +0 -3
- package/dist/src/assets/index.ts +0 -3
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import { useEffect, useLayoutEffect, useMemo, useRef, useState } from 'react';
|
|
2
|
+
import { useReactTable, getCoreRowModel, getSortedRowModel, getPaginationRowModel, getGroupedRowModel, getExpandedRowModel, } from '@tanstack/react-table';
|
|
3
|
+
import { applyFlexSizes, getCheckboxSelectionColumn } from '../table.helpers';
|
|
4
|
+
import { usePaginationController } from './usePaginationController';
|
|
5
|
+
import { useUrlPaginationSync } from './useUrlPaginationSync';
|
|
6
|
+
import { useInfiniteScrolling } from './useInfiniteScrolling';
|
|
7
|
+
export function useTableController({ id, height, data, columns, checkboxSelection, checkboxPosition = 'start', paginationMode = 'client', sorting, onSortingChange, onSelectionChange, enableRowSelection, rowsPerPage = 10, isMultiRowSelection = true, selectedRowIds, rowIdKey = 'id', totalServerRows, onRefetch, showHeader = true, grouping, infiniteScroll, virtualization, }) {
|
|
8
|
+
const safeData = Array.isArray(data) ? data : [];
|
|
9
|
+
const stableGrouping = useMemo(() => grouping !== null && grouping !== void 0 ? grouping : [], [grouping]);
|
|
10
|
+
const parentScrollRef = useRef(null);
|
|
11
|
+
const loaderRef = useRef(null);
|
|
12
|
+
const columnVisibility = useMemo(() => {
|
|
13
|
+
return Object.fromEntries(stableGrouping.map((columnId) => [columnId, false]));
|
|
14
|
+
}, [stableGrouping]);
|
|
15
|
+
const [containerWidth, setContainerWidth] = useState(0);
|
|
16
|
+
useLayoutEffect(() => {
|
|
17
|
+
if (!parentScrollRef.current)
|
|
18
|
+
return;
|
|
19
|
+
const ro = new ResizeObserver(([entry]) => {
|
|
20
|
+
setContainerWidth(entry.contentRect.width);
|
|
21
|
+
});
|
|
22
|
+
ro.observe(parentScrollRef.current);
|
|
23
|
+
return () => ro.disconnect();
|
|
24
|
+
}, []);
|
|
25
|
+
const [tableColumns, setTableColumns] = useState(() => applyFlexSizes(columns !== null && columns !== void 0 ? columns : [], containerWidth, !!(virtualization === null || virtualization === void 0 ? void 0 : virtualization.enabled)));
|
|
26
|
+
const [internalSorting, setInternalSorting] = useState(sorting !== null && sorting !== void 0 ? sorting : []);
|
|
27
|
+
const [internalRowSelection, setInternalRowSelection] = useState(() => {
|
|
28
|
+
if (selectedRowIds) {
|
|
29
|
+
return selectedRowIds.reduce((acc, id) => {
|
|
30
|
+
acc[id] = true;
|
|
31
|
+
return acc;
|
|
32
|
+
}, {});
|
|
33
|
+
}
|
|
34
|
+
return {};
|
|
35
|
+
});
|
|
36
|
+
const { pageIndex, setPageIndex, pageSize, setPageSize } = useUrlPaginationSync(rowsPerPage, id);
|
|
37
|
+
const isInfinite = !!(infiniteScroll === null || infiniteScroll === void 0 ? void 0 : infiniteScroll.enabled);
|
|
38
|
+
const dataPages = useMemo(() => {
|
|
39
|
+
if (!isInfinite) {
|
|
40
|
+
return undefined;
|
|
41
|
+
}
|
|
42
|
+
return [{ rows: safeData }];
|
|
43
|
+
}, [isInfinite, safeData.length]);
|
|
44
|
+
const infiniteOpts = useMemo(() => infiniteScroll, [infiniteScroll]);
|
|
45
|
+
const virtualizationOpts = useMemo(() => virtualization, [virtualization]);
|
|
46
|
+
const { allRows, virtualizationEnabled, rowVirtualizer, hasNextPage } = useInfiniteScrolling({
|
|
47
|
+
dataPages,
|
|
48
|
+
flatData: data,
|
|
49
|
+
infiniteScroll: infiniteOpts,
|
|
50
|
+
virtualization: virtualizationOpts,
|
|
51
|
+
parentScrollRef,
|
|
52
|
+
loaderRef,
|
|
53
|
+
});
|
|
54
|
+
const dataForTable = useMemo(() => (virtualizationEnabled || isInfinite ? allRows : safeData), [virtualizationEnabled, isInfinite, allRows, safeData]);
|
|
55
|
+
const table = useReactTable({
|
|
56
|
+
data: dataForTable,
|
|
57
|
+
columns: tableColumns,
|
|
58
|
+
getRowId: (row) => String(row[rowIdKey]),
|
|
59
|
+
state: {
|
|
60
|
+
...(isInfinite ? {} : { pagination: { pageIndex, pageSize } }),
|
|
61
|
+
sorting: sorting !== null && sorting !== void 0 ? sorting : internalSorting,
|
|
62
|
+
rowSelection: internalRowSelection,
|
|
63
|
+
grouping: stableGrouping,
|
|
64
|
+
columnVisibility,
|
|
65
|
+
},
|
|
66
|
+
getSortedRowModel: getSortedRowModel(),
|
|
67
|
+
getCoreRowModel: getCoreRowModel(),
|
|
68
|
+
getPaginationRowModel: !isInfinite && paginationMode === 'client' ? getPaginationRowModel() : undefined,
|
|
69
|
+
manualPagination: !isInfinite && paginationMode === 'server',
|
|
70
|
+
autoResetPageIndex: false,
|
|
71
|
+
pageCount: !isInfinite && paginationMode === 'server' ? Math.ceil((totalServerRows !== null && totalServerRows !== void 0 ? totalServerRows : 0) / pageSize) : undefined,
|
|
72
|
+
onPaginationChange: (updater) => {
|
|
73
|
+
if (isInfinite)
|
|
74
|
+
return;
|
|
75
|
+
const next = typeof updater === 'function' ? updater({ pageIndex, pageSize }) : updater;
|
|
76
|
+
setPageIndex(next.pageIndex);
|
|
77
|
+
setPageSize(next.pageSize);
|
|
78
|
+
},
|
|
79
|
+
onSortingChange: (updater) => {
|
|
80
|
+
const nextSorting = typeof updater === 'function' ? updater(sorting !== null && sorting !== void 0 ? sorting : internalSorting) : updater;
|
|
81
|
+
setInternalSorting(nextSorting);
|
|
82
|
+
onSortingChange === null || onSortingChange === void 0 ? void 0 : onSortingChange(nextSorting);
|
|
83
|
+
},
|
|
84
|
+
enableRowSelection: enableRowSelection !== null && enableRowSelection !== void 0 ? enableRowSelection : true,
|
|
85
|
+
onRowSelectionChange: (updater) => {
|
|
86
|
+
const newSelection = typeof updater === 'function' ? updater(internalRowSelection) : updater;
|
|
87
|
+
setInternalRowSelection(newSelection);
|
|
88
|
+
if (onSelectionChange) {
|
|
89
|
+
const selectedIdsArray = Object.keys(newSelection).filter((id) => newSelection[id]);
|
|
90
|
+
onSelectionChange(selectedIdsArray);
|
|
91
|
+
}
|
|
92
|
+
},
|
|
93
|
+
enableMultiRowSelection: isMultiRowSelection,
|
|
94
|
+
getGroupedRowModel: getGroupedRowModel(),
|
|
95
|
+
getExpandedRowModel: getExpandedRowModel(),
|
|
96
|
+
});
|
|
97
|
+
useEffect(() => {
|
|
98
|
+
if (paginationMode === 'none') {
|
|
99
|
+
setPageIndex(0);
|
|
100
|
+
}
|
|
101
|
+
}, [paginationMode, setPageIndex]);
|
|
102
|
+
const pagination = usePaginationController({
|
|
103
|
+
table,
|
|
104
|
+
paginationMode,
|
|
105
|
+
onRefetch,
|
|
106
|
+
});
|
|
107
|
+
const selectionColumn = useMemo(() => {
|
|
108
|
+
return checkboxSelection ? getCheckboxSelectionColumn(table) : null;
|
|
109
|
+
}, [checkboxSelection, table]);
|
|
110
|
+
useEffect(() => {
|
|
111
|
+
const normalized = applyFlexSizes(columns !== null && columns !== void 0 ? columns : [], containerWidth, !!(virtualization === null || virtualization === void 0 ? void 0 : virtualization.enabled));
|
|
112
|
+
let finalColumns;
|
|
113
|
+
if (checkboxSelection && selectionColumn) {
|
|
114
|
+
if (checkboxPosition === 'start') {
|
|
115
|
+
finalColumns = [selectionColumn, ...normalized];
|
|
116
|
+
}
|
|
117
|
+
else if (checkboxPosition === 'end') {
|
|
118
|
+
finalColumns = [...normalized, selectionColumn];
|
|
119
|
+
}
|
|
120
|
+
else {
|
|
121
|
+
finalColumns = normalized;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
else {
|
|
125
|
+
finalColumns = normalized;
|
|
126
|
+
}
|
|
127
|
+
setTableColumns(finalColumns);
|
|
128
|
+
}, [columns, checkboxSelection, checkboxPosition, containerWidth, virtualization === null || virtualization === void 0 ? void 0 : virtualization.enabled]);
|
|
129
|
+
return {
|
|
130
|
+
table,
|
|
131
|
+
height,
|
|
132
|
+
showHeader,
|
|
133
|
+
grouping,
|
|
134
|
+
setPageSize,
|
|
135
|
+
setPageIndex,
|
|
136
|
+
sorting: sorting !== null && sorting !== void 0 ? sorting : internalSorting,
|
|
137
|
+
virtualizationEnabled,
|
|
138
|
+
rowVirtualizer,
|
|
139
|
+
hasNextPage,
|
|
140
|
+
parentScrollRef,
|
|
141
|
+
loaderRef,
|
|
142
|
+
infiniteScroll,
|
|
143
|
+
virtualization,
|
|
144
|
+
...pagination,
|
|
145
|
+
};
|
|
146
|
+
}
|
|
@@ -11,18 +11,17 @@ function resolveColorValue(value, isDark) {
|
|
|
11
11
|
return isDark ? ((_b = (_a = value.dark) !== null && _a !== void 0 ? _a : value.light) !== null && _b !== void 0 ? _b : '') : ((_d = (_c = value.light) !== null && _c !== void 0 ? _c : value.dark) !== null && _d !== void 0 ? _d : '');
|
|
12
12
|
}
|
|
13
13
|
function mergeTheme(user) {
|
|
14
|
-
var _a;
|
|
15
14
|
return {
|
|
16
15
|
...defaultTheme,
|
|
17
16
|
...user,
|
|
18
17
|
colors: {
|
|
19
18
|
...defaultTheme.colors,
|
|
20
|
-
...
|
|
19
|
+
...user === null || user === void 0 ? void 0 : user.colors,
|
|
21
20
|
},
|
|
22
21
|
};
|
|
23
22
|
}
|
|
24
23
|
function applyThemeToRoot(theme, isDark) {
|
|
25
|
-
if (
|
|
24
|
+
if (globalThis.window === undefined) {
|
|
26
25
|
return;
|
|
27
26
|
}
|
|
28
27
|
const root = document.documentElement;
|
package/dist/src/stories/Page.js
CHANGED
|
@@ -4,5 +4,5 @@ import { Header } from './Header';
|
|
|
4
4
|
import './page.css';
|
|
5
5
|
export const Page = () => {
|
|
6
6
|
const [user, setUser] = React.useState();
|
|
7
|
-
return (_jsxs("article", { children: [_jsx(Header, { user: user, onLogin: () => setUser({ name: 'Jane Doe' }), onLogout: () => setUser(undefined), onCreateAccount: () => setUser({ name: 'Jane Doe' }) }), _jsxs("section", { className: "storybook-page", children: [_jsx("h2", { children: "Pages in Storybook" }), _jsxs("p", { children: ["We recommend building UIs with a", ' ', _jsx("a", { href: "https://componentdriven.org", target: "_blank", rel: "noopener noreferrer", children: _jsx("strong", { children: "component-driven" }) }), ' ', "process starting with atomic components and ending with pages."] }), _jsx("p", { children: "Render pages with mock data. This makes it easy to build and review page states without needing to navigate to them in your app. Here are some handy patterns for managing page data in Storybook:" }), _jsxs("ul", { children: [_jsx("li", { children: "Use a higher-level connected component. Storybook helps you compose such data from the \"args\" of child component stories" }), _jsx("li", { children: "Assemble data in the page component from your services. You can mock these services out using Storybook." })] }), _jsxs("p", { children: ["Get a guided tutorial on component-driven development at", ' ', _jsx("a", { href: "https://storybook.js.org/tutorials/", target: "_blank", rel: "noopener noreferrer", children: "Storybook tutorials" }), ". Read more in the", ' ', _jsx("a", { href: "https://storybook.js.org/docs", target: "_blank", rel: "noopener noreferrer", children: "docs" }),
|
|
7
|
+
return (_jsxs("article", { children: [_jsx(Header, { user: user, onLogin: () => setUser({ name: 'Jane Doe' }), onLogout: () => setUser(undefined), onCreateAccount: () => setUser({ name: 'Jane Doe' }) }), _jsxs("section", { className: "storybook-page", children: [_jsx("h2", { children: "Pages in Storybook" }), _jsxs("p", { children: ["We recommend building UIs with a", ' ', _jsx("a", { href: "https://componentdriven.org", target: "_blank", rel: "noopener noreferrer", children: _jsx("strong", { children: "component-driven" }) }), ' ', "process starting with atomic components and ending with pages."] }), _jsx("p", { children: "Render pages with mock data. This makes it easy to build and review page states without needing to navigate to them in your app. Here are some handy patterns for managing page data in Storybook:" }), _jsxs("ul", { children: [_jsx("li", { children: "Use a higher-level connected component. Storybook helps you compose such data from the \"args\" of child component stories" }), _jsx("li", { children: "Assemble data in the page component from your services. You can mock these services out using Storybook." })] }), _jsxs("p", { children: ["Get a guided tutorial on component-driven development at", ' ', _jsx("a", { href: "https://storybook.js.org/tutorials/", target: "_blank", rel: "noopener noreferrer", children: "Storybook tutorials" }), ". Read more in the", ' ', _jsx("a", { href: "https://storybook.js.org/docs", target: "_blank", rel: "noopener noreferrer", children: "docs" }), '.'] }), _jsxs("div", { className: "tip-wrapper", children: [_jsx("span", { className: "tip", children: "Tip" }), " Adjust the width of the canvas with the", ' ', _jsx("svg", { width: "10", height: "10", viewBox: "0 0 12 12", xmlns: "http://www.w3.org/2000/svg", children: _jsx("g", { fill: "none", fillRule: "evenodd", children: _jsx("path", { d: "M1.5 5.2h4.8c.3 0 .5.2.5.4v5.1c-.1.2-.3.3-.4.3H1.4a.5.5 0 01-.5-.4V5.7c0-.3.2-.5.5-.5zm0-2.1h6.9c.3 0 .5.2.5.4v7a.5.5 0 01-1 0V4H1.5a.5.5 0 010-1zm0-2.1h9c.3 0 .5.2.5.4v9.1a.5.5 0 01-1 0V2H1.5a.5.5 0 010-1zm4.3 5.2H2V10h3.8V6.2z", id: "a", fill: "#999" }) }) }), "Viewports addon in the toolbar"] })] })] }));
|
|
8
8
|
};
|
package/package.json
CHANGED
|
@@ -1,16 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eml-payments/ui-kit",
|
|
3
|
-
"version": "1.8.
|
|
3
|
+
"version": "1.8.15",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "ARLO UIKit",
|
|
6
6
|
"homepage": "https://github.com/EML-Payments/arlo.npm.uikit#readme",
|
|
7
7
|
"bugs": {
|
|
8
8
|
"url": "https://github.com/EML-Payments/arlo.npm.uikit/issues"
|
|
9
9
|
},
|
|
10
|
-
"repository": {
|
|
11
|
-
"type": "git",
|
|
12
|
-
"url": "git+https://github.com/EML-Payments/arlo.npm.uikit.git"
|
|
13
|
-
},
|
|
14
10
|
"license": "MIT",
|
|
15
11
|
"author": "EML Payments",
|
|
16
12
|
"type": "commonjs",
|
package/dist/src/assets/index.js
DELETED
package/dist/src/assets/index.ts
DELETED