@eml-payments/ui-kit 1.1.3 → 1.1.4
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/src/components/Table/Table.stories.d.ts +2 -9
- package/dist/src/components/Table/Table.stories.js +48 -14
- package/dist/src/components/Table/Table.types.d.ts +0 -4
- package/dist/src/components/Table/hooks/useTableController.d.ts +1 -1
- package/dist/src/components/Table/hooks/useTableController.js +3 -5
- package/dist/src/components/Table/hooks/useUrlPaginationSync.d.ts +1 -6
- package/dist/src/components/Table/hooks/useUrlPaginationSync.js +5 -11
- package/package.json +1 -1
|
@@ -1,14 +1,6 @@
|
|
|
1
1
|
import { Table } from './Table';
|
|
2
|
-
import type { TableProps } from './Table.types';
|
|
3
2
|
import type { Meta, StoryObj } from '@storybook/react';
|
|
4
|
-
|
|
5
|
-
initialPageNo?: number;
|
|
6
|
-
initialPageSize?: number;
|
|
7
|
-
}
|
|
8
|
-
type TableStoryArgs = TableProps<{
|
|
9
|
-
id: string;
|
|
10
|
-
}> & ExtraArgs;
|
|
11
|
-
declare const meta: Meta<TableStoryArgs>;
|
|
3
|
+
declare const meta: Meta<typeof Table>;
|
|
12
4
|
export default meta;
|
|
13
5
|
type Story = StoryObj<typeof Table>;
|
|
14
6
|
export declare const Basic: Story;
|
|
@@ -32,3 +24,4 @@ export declare const WithSearch: Story;
|
|
|
32
24
|
export declare const ServerSideSearch: Story;
|
|
33
25
|
export declare const ClientPaginationWithQueryParams: StoryObj;
|
|
34
26
|
export declare const ServerPaginationWithQueryParams: StoryObj;
|
|
27
|
+
export declare const TwoTablesWithQueryParams: StoryObj;
|
|
@@ -44,18 +44,6 @@ const columns = [
|
|
|
44
44
|
const meta = {
|
|
45
45
|
title: 'UIKit/Table',
|
|
46
46
|
component: Table,
|
|
47
|
-
args: {
|
|
48
|
-
initialPageNo: 1,
|
|
49
|
-
initialPageSize: 10,
|
|
50
|
-
},
|
|
51
|
-
decorators: [
|
|
52
|
-
(Story, context) => {
|
|
53
|
-
const { initialPageNo, initialPageSize } = context.args;
|
|
54
|
-
const query = `?pageNo=${initialPageNo}&pageSize=${initialPageSize}`;
|
|
55
|
-
window.history.replaceState({}, '', query);
|
|
56
|
-
return _jsx(Story, {});
|
|
57
|
-
},
|
|
58
|
-
],
|
|
59
47
|
tags: ['autodocs'],
|
|
60
48
|
render: () => _jsx(Table, { id: "example-table", data: data, columns: columns }),
|
|
61
49
|
};
|
|
@@ -279,18 +267,36 @@ export const ServerSideSearch = {
|
|
|
279
267
|
return (_jsxs("div", { className: "space-y-4", children: [_jsx("div", { style: { width: '300px' }, children: _jsx(SearchInput, { onSearch: (q) => setQuery(q), onClear: () => setQuery(''), placeholder: "Search users..." }) }), _jsx(Table, { id: "server-search-table", data: data, columns: columns, paginationMode: "server", totalServerRows: 100, onRefetch: fetchData, isLoading: isLoading, isSearchActive: query.trim().length >= 3 })] }));
|
|
280
268
|
},
|
|
281
269
|
};
|
|
270
|
+
// Note: Does not update state search params
|
|
282
271
|
export const ClientPaginationWithQueryParams = {
|
|
283
272
|
args: {
|
|
284
273
|
initialPageNo: 2,
|
|
285
274
|
initialPageSize: 5,
|
|
286
275
|
},
|
|
287
|
-
|
|
276
|
+
decorators: [
|
|
277
|
+
(Story, context) => {
|
|
278
|
+
const { initialPageNo, initialPageSize } = context.args;
|
|
279
|
+
const query = `?clients_pageNo=${initialPageNo}&clients_pageSize=${initialPageSize}`;
|
|
280
|
+
window.history.replaceState({}, '', query);
|
|
281
|
+
return _jsx(Story, {});
|
|
282
|
+
},
|
|
283
|
+
],
|
|
284
|
+
render: () => (_jsxs(_Fragment, { children: [_jsx(CurrentUrl, {}), _jsx(Table, { id: "clients", data: data, columns: columns, paginationMode: "client", showHeader: true })] })),
|
|
288
285
|
};
|
|
286
|
+
// Note: Does not update state search params
|
|
289
287
|
export const ServerPaginationWithQueryParams = {
|
|
290
288
|
args: {
|
|
291
289
|
initialPageNo: 2,
|
|
292
290
|
initialPageSize: 5,
|
|
293
291
|
},
|
|
292
|
+
decorators: [
|
|
293
|
+
(Story, context) => {
|
|
294
|
+
const { initialPageNo, initialPageSize } = context.args;
|
|
295
|
+
const query = `?clients_pageNo=${initialPageNo}&clients_pageSize=${initialPageSize}`;
|
|
296
|
+
window.history.replaceState({}, '', query);
|
|
297
|
+
return _jsx(Story, {});
|
|
298
|
+
},
|
|
299
|
+
],
|
|
294
300
|
render: () => {
|
|
295
301
|
const [data, setData] = useState([]);
|
|
296
302
|
const [isLoading, setIsLoading] = useState(false);
|
|
@@ -300,6 +306,34 @@ export const ServerPaginationWithQueryParams = {
|
|
|
300
306
|
setData(results);
|
|
301
307
|
setIsLoading(false);
|
|
302
308
|
}, []);
|
|
303
|
-
return (_jsxs(_Fragment, { children: [_jsx(CurrentUrl, {}), _jsx(Table, { id: "
|
|
309
|
+
return (_jsxs(_Fragment, { children: [_jsx(CurrentUrl, {}), _jsx(Table, { id: "clients", data: data, columns: columns, paginationMode: "server", totalServerRows: 100, onRefetch: fetchData, isLoading: isLoading, showHeader: true })] }));
|
|
310
|
+
},
|
|
311
|
+
};
|
|
312
|
+
// Note: Does not update state search params
|
|
313
|
+
export const TwoTablesWithQueryParams = {
|
|
314
|
+
args: {
|
|
315
|
+
clientsInitialPageNo: 2,
|
|
316
|
+
clientsInitialPageSize: 5,
|
|
317
|
+
usersInitialPageNo: 3,
|
|
318
|
+
usersInitialPageSize: 10,
|
|
319
|
+
},
|
|
320
|
+
decorators: [
|
|
321
|
+
(Story, context) => {
|
|
322
|
+
const { clientsInitialPageNo, clientsInitialPageSize, usersInitialPageNo, usersInitialPageSize } = context.args;
|
|
323
|
+
const query = `?clients_pageNo=${clientsInitialPageNo}&clients_pageSize=${clientsInitialPageSize}&users_pageNo=${usersInitialPageNo}&users_pageSize=${usersInitialPageSize}`;
|
|
324
|
+
window.history.replaceState({}, '', query);
|
|
325
|
+
return _jsx(Story, {});
|
|
326
|
+
},
|
|
327
|
+
],
|
|
328
|
+
render: () => {
|
|
329
|
+
const [usersData, setUsersData] = useState([]);
|
|
330
|
+
const [isLoadingUsers, setIsLoadingUsers] = useState(false);
|
|
331
|
+
const fetchUsersData = useCallback(async (pageIndex, pageSize) => {
|
|
332
|
+
setIsLoadingUsers(true);
|
|
333
|
+
const results = await fetchServerData(pageIndex, pageSize);
|
|
334
|
+
setUsersData(results);
|
|
335
|
+
setIsLoadingUsers(false);
|
|
336
|
+
}, []);
|
|
337
|
+
return (_jsxs(_Fragment, { children: [_jsx(CurrentUrl, {}), _jsxs("div", { style: { display: 'flex', gap: '2rem' }, children: [_jsx(Table, { id: "clients", data: data, columns: columns, paginationMode: "client", showHeader: true }), _jsx(Table, { id: "users", data: usersData, columns: columns, paginationMode: "server", totalServerRows: 100, onRefetch: fetchUsersData, isLoading: isLoadingUsers, showHeader: true })] })] }));
|
|
304
338
|
},
|
|
305
339
|
};
|
|
@@ -2,7 +2,7 @@ import { type SortingState } from '@tanstack/react-table';
|
|
|
2
2
|
import type { TableProps } from '../Table.types';
|
|
3
3
|
export declare function useTableController<T extends {
|
|
4
4
|
id: string;
|
|
5
|
-
}>({ data, columns, checkboxSelection, checkboxPosition, paginationMode, sorting, onSortingChange, onSelectionChange, enableRowSelection, rowsPerPage, isMultiRowSelection, selectedRowIds, rowIdKey, totalServerRows, onRefetch, showHeader, grouping,
|
|
5
|
+
}>({ id, data, columns, checkboxSelection, checkboxPosition, paginationMode, sorting, onSortingChange, onSelectionChange, enableRowSelection, rowsPerPage, isMultiRowSelection, selectedRowIds, rowIdKey, totalServerRows, onRefetch, showHeader, grouping, }: TableProps<T>): {
|
|
6
6
|
pageIndex: number;
|
|
7
7
|
pageSize: number;
|
|
8
8
|
canNextPage: boolean;
|
|
@@ -3,7 +3,7 @@ import { useReactTable, getCoreRowModel, getSortedRowModel, getPaginationRowMode
|
|
|
3
3
|
import { applyFlexSizes, getCheckboxSelectionColumn } from '../table.helpers';
|
|
4
4
|
import { usePaginationController } from './usePaginationController';
|
|
5
5
|
import { useUrlPaginationSync } from './useUrlPaginationSync';
|
|
6
|
-
export function useTableController({ data, columns, checkboxSelection, checkboxPosition = 'start', paginationMode = 'client', sorting, onSortingChange, onSelectionChange, enableRowSelection, rowsPerPage = 10, isMultiRowSelection = true, selectedRowIds, rowIdKey = 'id', totalServerRows, onRefetch, showHeader = true, grouping,
|
|
6
|
+
export function useTableController({ id, data, columns, checkboxSelection, checkboxPosition = 'start', paginationMode = 'client', sorting, onSortingChange, onSelectionChange, enableRowSelection, rowsPerPage = 10, isMultiRowSelection = true, selectedRowIds, rowIdKey = 'id', totalServerRows, onRefetch, showHeader = true, grouping, }) {
|
|
7
7
|
const safeData = Array.isArray(data) ? data : [];
|
|
8
8
|
const stableGrouping = useMemo(() => grouping !== null && grouping !== void 0 ? grouping : [], [grouping]);
|
|
9
9
|
const columnVisibility = useMemo(() => {
|
|
@@ -20,7 +20,7 @@ export function useTableController({ data, columns, checkboxSelection, checkboxP
|
|
|
20
20
|
}
|
|
21
21
|
return {};
|
|
22
22
|
});
|
|
23
|
-
const { pageIndex, setPageIndex, pageSize, setPageSize } = useUrlPaginationSync(rowsPerPage,
|
|
23
|
+
const { pageIndex, setPageIndex, pageSize, setPageSize } = useUrlPaginationSync(rowsPerPage, id);
|
|
24
24
|
const table = useReactTable({
|
|
25
25
|
data: safeData,
|
|
26
26
|
columns: tableColumns,
|
|
@@ -37,9 +37,7 @@ export function useTableController({ data, columns, checkboxSelection, checkboxP
|
|
|
37
37
|
getPaginationRowModel: paginationMode === 'client' ? getPaginationRowModel() : undefined,
|
|
38
38
|
manualPagination: paginationMode === 'server',
|
|
39
39
|
autoResetPageIndex: false,
|
|
40
|
-
pageCount: paginationMode === 'server'
|
|
41
|
-
? Math.ceil((totalServerRows !== null && totalServerRows !== void 0 ? totalServerRows : 0) / pageSize)
|
|
42
|
-
: undefined,
|
|
40
|
+
pageCount: paginationMode === 'server' ? Math.ceil((totalServerRows !== null && totalServerRows !== void 0 ? totalServerRows : 0) / pageSize) : undefined,
|
|
43
41
|
onPaginationChange: (updater) => {
|
|
44
42
|
const next = typeof updater === 'function' ? updater({ pageIndex, pageSize }) : updater;
|
|
45
43
|
setPageIndex(next.pageIndex);
|
|
@@ -1,11 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
pageSize?: string;
|
|
3
|
-
pageNo?: string;
|
|
4
|
-
}
|
|
5
|
-
export declare function useUrlPaginationSync(rowsPerPage: number, queryParamKeys?: QueryParamKeys): {
|
|
1
|
+
export declare function useUrlPaginationSync(rowsPerPage: number, tableId: string): {
|
|
6
2
|
pageIndex: number;
|
|
7
3
|
setPageIndex: import("react").Dispatch<import("react").SetStateAction<number>>;
|
|
8
4
|
pageSize: number;
|
|
9
5
|
setPageSize: import("react").Dispatch<import("react").SetStateAction<number>>;
|
|
10
6
|
};
|
|
11
|
-
export {};
|
|
@@ -1,18 +1,12 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { useState } from 'react';
|
|
2
2
|
import { useSearchParams } from 'react-router-dom';
|
|
3
|
-
export function useUrlPaginationSync(rowsPerPage,
|
|
4
|
-
const [searchParams
|
|
5
|
-
const pageSizeKey =
|
|
6
|
-
const pageNoKey =
|
|
3
|
+
export function useUrlPaginationSync(rowsPerPage, tableId) {
|
|
4
|
+
const [searchParams] = useSearchParams();
|
|
5
|
+
const pageSizeKey = `${tableId}_pageSize`;
|
|
6
|
+
const pageNoKey = `${tableId}_pageNo`;
|
|
7
7
|
const initialPageIndex = Math.max(parseInt(searchParams.get(pageNoKey) || '1') - 1, 0);
|
|
8
8
|
const initialPageSize = Math.max(parseInt(searchParams.get(pageSizeKey) || String(rowsPerPage !== null && rowsPerPage !== void 0 ? rowsPerPage : 10)), 1);
|
|
9
9
|
const [pageIndex, setPageIndex] = useState(initialPageIndex);
|
|
10
10
|
const [pageSize, setPageSize] = useState(initialPageSize);
|
|
11
|
-
useEffect(() => {
|
|
12
|
-
const newParams = new URLSearchParams(searchParams);
|
|
13
|
-
newParams.set(pageNoKey, String(pageIndex + 1));
|
|
14
|
-
newParams.set(pageSizeKey, String(pageSize));
|
|
15
|
-
setSearchParams(newParams, { replace: true });
|
|
16
|
-
}, [pageIndex, pageSize]);
|
|
17
11
|
return { pageIndex, setPageIndex, pageSize, setPageSize };
|
|
18
12
|
}
|