@eml-payments/ui-kit 1.3.3 → 1.4.3
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 +1 -1
- package/dist/index.d.cts +488 -0
- package/dist/index.d.ts +488 -0
- package/dist/src/components/Alert/Alert.js +9 -5
- package/dist/src/components/DatePicker/DatePicker.js +7 -3
- package/dist/src/components/Dialog/DialogContainer.stories.js +5 -4
- package/dist/src/components/Dropdown/Dropdown.stories.js +11 -9
- package/dist/src/components/DropdownWrapper/DropdownWrapper.stories.js +20 -18
- package/dist/src/components/Table/BaseTable/BaseTable.d.ts +2 -0
- package/dist/src/components/Table/BaseTable/BaseTable.js +8 -0
- package/dist/src/components/Table/BaseTable/BaseTable.stories.d.ts +7 -0
- package/dist/src/components/Table/BaseTable/BaseTable.stories.js +42 -0
- package/dist/src/components/Table/BaseTable/BaseTable.types.d.ts +0 -0
- package/dist/src/components/Table/BaseTable/BaseTable.types.js +1 -0
- package/dist/src/components/Table/BaseTable/TableHeader.d.ts +7 -0
- package/dist/src/components/Table/BaseTable/TableHeader.js +15 -0
- 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/InfiniteTable/InfiniteTable.d.ts +4 -0
- package/dist/src/components/Table/InfiniteTable/InfiniteTable.js +49 -0
- package/dist/src/components/Table/InfiniteTable/InfiniteTable.props.d.ts +32 -0
- package/dist/src/components/Table/InfiniteTable/InfiniteTable.props.js +1 -0
- package/dist/src/components/Table/InfiniteTable/InfiniteTable.stories.d.ts +8 -0
- package/dist/src/components/Table/InfiniteTable/InfiniteTable.stories.js +109 -0
- package/dist/src/components/Table/InfiniteTable/index.d.ts +2 -0
- package/dist/src/components/Table/InfiniteTable/index.js +1 -0
- package/dist/src/components/Table/InfiniteTable/useInfiniteScrollTrigger.d.ts +12 -0
- package/dist/src/components/Table/InfiniteTable/useInfiniteScrollTrigger.js +31 -0
- package/dist/src/components/Table/InfiniteTable/useInfiniteScrolling.d.ts +29 -0
- package/dist/src/components/Table/InfiniteTable/useInfiniteScrolling.js +103 -0
- package/dist/src/components/Table/InfiniteTable/useInfiniteTableController.d.ts +14 -0
- package/dist/src/components/Table/InfiniteTable/useInfiniteTableController.js +76 -0
- package/dist/src/components/Table/Pagination/PageSizeSelector.d.ts +2 -0
- package/dist/src/components/Table/Pagination/PageSizeSelector.js +9 -0
- package/dist/src/components/Table/Pagination/Pagination.types.d.ts +21 -0
- package/dist/src/components/Table/Pagination/Pagination.types.js +1 -0
- package/dist/src/components/Table/Pagination/PaginationFooter.d.ts +2 -0
- package/dist/src/components/Table/Pagination/PaginationFooter.js +10 -0
- package/dist/src/components/Table/Pagination/index.d.ts +3 -2
- package/dist/src/components/Table/Pagination/index.js +3 -2
- package/dist/src/components/Table/Pagination/usePaginationController.d.ts +16 -0
- package/dist/src/components/Table/Pagination/usePaginationController.js +33 -0
- package/dist/src/components/Table/StandardTable/StandardTable.d.ts +4 -0
- package/dist/src/components/Table/StandardTable/StandardTable.js +47 -0
- package/dist/src/components/Table/StandardTable/StandardTable.stories.d.ts +25 -0
- package/dist/src/components/Table/StandardTable/StandardTable.stories.js +268 -0
- package/dist/src/components/Table/StandardTable/StandardTable.types.d.ts +4 -0
- package/dist/src/components/Table/StandardTable/StandardTable.types.js +1 -0
- package/dist/src/components/Table/StandardTable/index.d.ts +2 -0
- package/dist/src/components/Table/StandardTable/index.js +1 -0
- package/dist/src/components/Table/StandardTable/useStandardTableController.d.ts +22 -0
- package/dist/src/components/Table/StandardTable/useStandardTableController.js +100 -0
- package/dist/src/components/Table/Table.js +1 -1
- package/dist/src/components/Table/Table.types.d.ts +72 -29
- package/dist/src/components/Table/body/Body.types.d.ts +0 -0
- package/dist/src/components/Table/body/Body.types.js +1 -0
- package/dist/src/components/Table/body/renderGroupRow.d.ts +13 -0
- package/dist/src/components/Table/body/renderGroupRow.js +14 -0
- package/dist/src/components/Table/body/renderLeafRow.d.ts +11 -0
- package/dist/src/components/Table/body/renderLeafRow.js +17 -0
- package/dist/src/components/Table/body/renderTableBody.d.ts +22 -0
- package/dist/src/components/Table/body/renderTableBody.js +21 -0
- package/dist/src/components/Table/body/utils/getColSpan.d.ts +2 -0
- package/dist/src/components/Table/body/utils/getColSpan.js +4 -0
- package/dist/src/components/Table/body/utils/getTableBodyState.d.ts +16 -0
- package/dist/src/components/Table/body/utils/getTableBodyState.js +9 -0
- package/dist/src/components/Table/body/utils/index.d.ts +2 -0
- package/dist/src/components/Table/body/utils/index.js +2 -0
- package/dist/src/components/Table/hooks/useTableColumns.d.ts +2 -0
- package/dist/src/components/Table/hooks/useTableColumns.js +5 -0
- package/dist/src/components/Table/hooks/useTableLayout.d.ts +5 -0
- package/dist/src/components/Table/hooks/useTableLayout.js +21 -0
- package/dist/src/components/Table/hooks/useTableSorting.d.ts +5 -0
- package/dist/src/components/Table/hooks/useTableSorting.js +14 -0
- package/dist/src/components/Table/hooks/useUrlPaginationSync.d.ts +4 -5
- package/dist/src/components/Table/hooks/useUrlPaginationSync.js +23 -9
- package/dist/src/components/Table/index.d.ts +5 -2
- package/dist/src/components/Table/index.js +2 -2
- package/dist/src/components/Table/render-rows/renderTableRows.d.ts +22 -0
- package/dist/src/components/Table/render-rows/renderTableRows.js +31 -0
- package/dist/src/components/Table/table.helpers.d.ts +5 -2
- package/dist/src/components/Table/table.helpers.js +13 -7
- package/dist/src/components/Tooltip/Tooltip.stories.js +1 -1
- package/dist/src/components/UICreditCard/UICreditCard.js +1 -1
- package/dist/src/components/UICreditCard/UICreditCard.stories.js +10 -8
- package/package.json +2 -2
|
@@ -1,5 +1,11 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { SortingState, ColumnDef, Table } from '@tanstack/react-table';
|
|
2
2
|
import type { DropdownOption, DropdownStructure } from '../DropdownWrapper/DropdownWrapper.types';
|
|
3
|
+
import type { ReactNode } from 'react';
|
|
4
|
+
declare module '@tanstack/react-table' {
|
|
5
|
+
interface TableMeta<TData> {
|
|
6
|
+
hasActions?: boolean;
|
|
7
|
+
}
|
|
8
|
+
}
|
|
3
9
|
export type FlexColumnDef<T> = ColumnDef<T> & {
|
|
4
10
|
flex?: number;
|
|
5
11
|
};
|
|
@@ -12,47 +18,84 @@ export type InfiniteScrollOptions = {
|
|
|
12
18
|
loadingMoreMessage?: string;
|
|
13
19
|
noMoreDataMessage?: string;
|
|
14
20
|
};
|
|
15
|
-
export type
|
|
16
|
-
export interface VirtualizationOptions {
|
|
21
|
+
export type VirtualizationOptions = {
|
|
17
22
|
enabled: boolean;
|
|
18
23
|
rowEstimate?: number;
|
|
19
24
|
overscan?: number;
|
|
25
|
+
};
|
|
26
|
+
export type ClientPaginationProps = {
|
|
27
|
+
paginationMode?: 'client' | 'none';
|
|
28
|
+
rowsPerPage?: number;
|
|
29
|
+
onRefetch?: never;
|
|
30
|
+
totalServerRows?: never;
|
|
31
|
+
};
|
|
32
|
+
export type ServerPaginationProps = {
|
|
33
|
+
paginationMode: 'server';
|
|
34
|
+
rowsPerPage?: number;
|
|
35
|
+
onRefetch: (pageIndex: number, pageSize: number) => void;
|
|
36
|
+
totalServerRows: number;
|
|
37
|
+
};
|
|
38
|
+
export type StandardPaginationProps = ClientPaginationProps | ServerPaginationProps;
|
|
39
|
+
export interface ITableActionsDropdownProps<T> {
|
|
40
|
+
getOptions: (row: T) => DropdownOption[];
|
|
41
|
+
structure?: DropdownStructure;
|
|
42
|
+
renderCustomTrigger?: (row: T) => ReactNode;
|
|
43
|
+
menuAlignment?: 'start' | 'end' | 'center';
|
|
44
|
+
isDisabled?: boolean | ((row: T) => boolean);
|
|
20
45
|
}
|
|
21
|
-
export
|
|
46
|
+
export type GroupRowClickHandler<T> = (args: {
|
|
47
|
+
columnId: string;
|
|
48
|
+
value: unknown;
|
|
49
|
+
rows: T[];
|
|
50
|
+
}) => void;
|
|
51
|
+
export interface TableInputProps<T> {
|
|
22
52
|
id: string;
|
|
23
|
-
height?: number | string;
|
|
24
53
|
data: T[];
|
|
25
54
|
columns: FlexColumnDef<T>[];
|
|
26
55
|
rowIdKey?: keyof T | 'id';
|
|
56
|
+
height?: number | string;
|
|
57
|
+
showHeader?: boolean;
|
|
27
58
|
className?: string;
|
|
28
|
-
|
|
29
|
-
showSkeletonRows?: boolean;
|
|
30
|
-
checkboxSelection?: boolean;
|
|
31
|
-
checkboxPosition?: 'start' | 'end';
|
|
59
|
+
/** Sorting */
|
|
32
60
|
sorting?: SortingState;
|
|
33
61
|
onSortingChange?: (s: SortingState) => void;
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
totalServerRows?: number;
|
|
39
|
-
paginationMode?: PaginationMode;
|
|
40
|
-
noRowsMessage?: string;
|
|
41
|
-
rowsPerPage?: number;
|
|
42
|
-
selectedRowIds?: string[];
|
|
43
|
-
tableActionsDropdown?: {
|
|
44
|
-
getOptions: (row: T) => DropdownOption[];
|
|
45
|
-
structure?: DropdownStructure;
|
|
46
|
-
renderCustomTrigger?: (row: T) => React.ReactNode;
|
|
47
|
-
menuAlignment?: 'start' | 'end' | 'center' | undefined;
|
|
48
|
-
isDisabled?: boolean | ((row: T) => boolean);
|
|
49
|
-
};
|
|
62
|
+
/** Grouping */
|
|
63
|
+
grouping?: string[];
|
|
64
|
+
isLoading?: boolean;
|
|
65
|
+
/** Row interactions */
|
|
50
66
|
onRowClick?: (row: T) => void;
|
|
51
67
|
isRowClickable?: (row: T) => boolean;
|
|
52
|
-
|
|
53
|
-
|
|
68
|
+
onGroupRowClick?: GroupRowClickHandler<T>;
|
|
69
|
+
/** Search */
|
|
54
70
|
isSearchActive?: boolean;
|
|
71
|
+
searchQuery?: string;
|
|
72
|
+
minSearchLength?: number;
|
|
55
73
|
noSearchResultsMessage?: string;
|
|
56
|
-
|
|
57
|
-
|
|
74
|
+
noRowsMessage?: string;
|
|
75
|
+
/** Actions */
|
|
76
|
+
tableActionsDropdown?: ITableActionsDropdownProps<T>;
|
|
58
77
|
}
|
|
78
|
+
export interface BaseTableProps<T> {
|
|
79
|
+
table: Table<T>;
|
|
80
|
+
height?: number | string;
|
|
81
|
+
showHeader?: boolean;
|
|
82
|
+
className?: string;
|
|
83
|
+
isLoading?: boolean;
|
|
84
|
+
renderBody: () => ReactNode;
|
|
85
|
+
footer?: ReactNode;
|
|
86
|
+
containerRef?: React.Ref<HTMLDivElement>;
|
|
87
|
+
}
|
|
88
|
+
export type StandardTableProps<T extends {
|
|
89
|
+
id: string;
|
|
90
|
+
}> = TableInputProps<T> & StandardPaginationProps;
|
|
91
|
+
export type InfiniteScrollTableProps<T extends {
|
|
92
|
+
id: string;
|
|
93
|
+
}> = TableInputProps<T> & {
|
|
94
|
+
infiniteScroll: InfiniteScrollOptions;
|
|
95
|
+
virtualization?: VirtualizationOptions;
|
|
96
|
+
/** explicitly not supported */
|
|
97
|
+
paginationMode?: never;
|
|
98
|
+
rowsPerPage?: never;
|
|
99
|
+
onRefetch?: never;
|
|
100
|
+
totalServerRows?: never;
|
|
101
|
+
};
|
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { Row } from '@tanstack/react-table';
|
|
2
|
+
interface RenderGroupRowProps<T> {
|
|
3
|
+
row: Row<T> & {
|
|
4
|
+
groupingColumnId: string;
|
|
5
|
+
};
|
|
6
|
+
onGroupRowClick?: (args: {
|
|
7
|
+
columnId: string;
|
|
8
|
+
value: unknown;
|
|
9
|
+
rows: T[];
|
|
10
|
+
}) => void;
|
|
11
|
+
}
|
|
12
|
+
export declare function renderGroupRow<T>({ row, onGroupRowClick }: RenderGroupRowProps<T>): import("react/jsx-runtime").JSX.Element;
|
|
13
|
+
export {};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { classNames } from '../../../utils';
|
|
3
|
+
export function renderGroupRow({ row, onGroupRowClick }) {
|
|
4
|
+
const columnId = row.groupingColumnId;
|
|
5
|
+
const groupValue = row.getGroupingValue(columnId);
|
|
6
|
+
const clickable = Boolean(onGroupRowClick);
|
|
7
|
+
return (_jsx("tr", { className: classNames('border-none', clickable && 'cursor-pointer hover:bg-muted/40'), onClick: clickable
|
|
8
|
+
? () => onGroupRowClick === null || onGroupRowClick === void 0 ? void 0 : onGroupRowClick({
|
|
9
|
+
columnId,
|
|
10
|
+
value: groupValue,
|
|
11
|
+
rows: row.subRows.map((r) => r.original),
|
|
12
|
+
})
|
|
13
|
+
: undefined, children: _jsx("td", { colSpan: row.getVisibleCells().length, className: "p-0", children: _jsx("div", { className: "px-4 py-4 text-sm text-muted-foreground", children: String(groupValue) }) }) }));
|
|
14
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { type Row } from '@tanstack/react-table';
|
|
2
|
+
import type { ITableActionsDropdownProps } from '../Table.types';
|
|
3
|
+
export declare function renderLeafRow<T extends {
|
|
4
|
+
id: string;
|
|
5
|
+
}>({ row, onRowClick, isRowClickable, hasActions, tableActionsDropdown, }: {
|
|
6
|
+
row: Row<T>;
|
|
7
|
+
onRowClick?: (row: T) => void;
|
|
8
|
+
isRowClickable?: (row: T) => boolean;
|
|
9
|
+
hasActions?: boolean;
|
|
10
|
+
tableActionsDropdown?: ITableActionsDropdownProps<T>;
|
|
11
|
+
}): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Button } from '../../Button';
|
|
3
|
+
import { DropdownWrapper } from '../../DropdownWrapper';
|
|
4
|
+
import { classNames } from '../../../utils';
|
|
5
|
+
import { flexRender } from '@tanstack/react-table';
|
|
6
|
+
import { FiMoreHorizontal } from 'react-icons/fi';
|
|
7
|
+
import { getRowInteractivity } from '../table.helpers';
|
|
8
|
+
export function renderLeafRow({ row, onRowClick, isRowClickable, hasActions, tableActionsDropdown, }) {
|
|
9
|
+
var _a, _b;
|
|
10
|
+
const original = row.original;
|
|
11
|
+
const { clickable, disabled } = getRowInteractivity(original, onRowClick, isRowClickable);
|
|
12
|
+
return (_jsxs("tr", { className: classNames('border-t transition-colors', clickable && 'cursor-pointer hover:bg-gray-50', disabled && 'bg-muted/40 text-muted-foreground cursor-not-allowed'), onClick: clickable ? () => onRowClick === null || onRowClick === void 0 ? void 0 : onRowClick(original) : undefined, children: [row.getVisibleCells().map((cell) => {
|
|
13
|
+
const width = cell.column.getSize();
|
|
14
|
+
const isSelect = cell.column.id === 'select';
|
|
15
|
+
return (_jsx("td", { style: { width }, className: isSelect ? 'p-1' : 'px-4 py-3', children: flexRender(cell.column.columnDef.cell, cell.getContext()) }, cell.id));
|
|
16
|
+
}), hasActions && tableActionsDropdown && (_jsx("td", { className: "w-[40px] px-2 py-2 text-right", children: _jsx(DropdownWrapper, { options: tableActionsDropdown.getOptions(original), menuAlignment: tableActionsDropdown.menuAlignment, isTriggerElementDisabled: disabled, triggerElement: (_b = (_a = tableActionsDropdown.renderCustomTrigger) === null || _a === void 0 ? void 0 : _a.call(tableActionsDropdown, original)) !== null && _b !== void 0 ? _b : (_jsx(Button, { size: "icon", variant: "ghost", className: "p-1", disabled: disabled, children: _jsx(FiMoreHorizontal, { size: 16 }) })) }) }))] }, row.id));
|
|
17
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { Table } from '@tanstack/react-table';
|
|
2
|
+
import type { ITableActionsDropdownProps } from '../Table.types';
|
|
3
|
+
import type { TableBodyState } from './utils';
|
|
4
|
+
interface RenderTableBodyProps<T extends {
|
|
5
|
+
id: string;
|
|
6
|
+
}> {
|
|
7
|
+
table: Table<T>;
|
|
8
|
+
state: TableBodyState<T>;
|
|
9
|
+
colSpan: number;
|
|
10
|
+
onRowClick?: (row: T) => void;
|
|
11
|
+
isRowClickable?: (row: T) => boolean;
|
|
12
|
+
onGroupRowClick?: (args: {
|
|
13
|
+
columnId: string;
|
|
14
|
+
value: unknown;
|
|
15
|
+
rows: T[];
|
|
16
|
+
}) => void;
|
|
17
|
+
tableActionsDropdown?: ITableActionsDropdownProps<T>;
|
|
18
|
+
}
|
|
19
|
+
export declare function renderTableBody<T extends {
|
|
20
|
+
id: string;
|
|
21
|
+
}>({ table, state, colSpan, onRowClick, isRowClickable, onGroupRowClick, tableActionsDropdown, }: RenderTableBodyProps<T>): React.ReactNode;
|
|
22
|
+
export {};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { renderTableRows } from '../render-rows/renderTableRows';
|
|
3
|
+
export function renderTableBody({ table, state, colSpan, onRowClick, isRowClickable, onGroupRowClick, tableActionsDropdown, }) {
|
|
4
|
+
var _a;
|
|
5
|
+
switch (state.type) {
|
|
6
|
+
case 'loading':
|
|
7
|
+
return null; // spinner handled by BaseTable
|
|
8
|
+
case 'empty':
|
|
9
|
+
return (_jsx("tr", { children: _jsx("td", { colSpan: colSpan, className: "px-4 py-8 text-center text-muted-foreground", children: state.message }) }));
|
|
10
|
+
case 'rows':
|
|
11
|
+
return renderTableRows({
|
|
12
|
+
table,
|
|
13
|
+
rows: state.rows,
|
|
14
|
+
hasActions: Boolean((_a = table.options.meta) === null || _a === void 0 ? void 0 : _a.hasActions),
|
|
15
|
+
onRowClick,
|
|
16
|
+
isRowClickable,
|
|
17
|
+
onGroupRowClick,
|
|
18
|
+
tableActionsDropdown,
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { Row } from '@tanstack/react-table';
|
|
2
|
+
import type { ReactNode } from 'react';
|
|
3
|
+
export type TableBodyState<T> = {
|
|
4
|
+
type: 'loading';
|
|
5
|
+
} | {
|
|
6
|
+
type: 'empty';
|
|
7
|
+
message: ReactNode;
|
|
8
|
+
} | {
|
|
9
|
+
type: 'rows';
|
|
10
|
+
rows: Row<T>[];
|
|
11
|
+
};
|
|
12
|
+
export declare function getTableBodyState<T>({ rows, isLoading, noResultsMessage, }: {
|
|
13
|
+
rows: Row<T>[];
|
|
14
|
+
isLoading?: boolean;
|
|
15
|
+
noResultsMessage: ReactNode;
|
|
16
|
+
}): TableBodyState<T>;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { useMemo } from 'react';
|
|
2
|
+
import { applyFlexSizes } from '../table.helpers';
|
|
3
|
+
export function useTableColumns(columns, containerWidth, virtualizationEnabled) {
|
|
4
|
+
return useMemo(() => applyFlexSizes(columns, containerWidth, virtualizationEnabled), [columns, containerWidth, virtualizationEnabled]);
|
|
5
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { useLayoutEffect, useRef, useState } from 'react';
|
|
2
|
+
export function useTableLayout() {
|
|
3
|
+
const parentScrollRef = useRef(null);
|
|
4
|
+
const loaderRef = useRef(null);
|
|
5
|
+
const [containerWidth, setContainerWidth] = useState(0);
|
|
6
|
+
useLayoutEffect(() => {
|
|
7
|
+
if (!parentScrollRef.current) {
|
|
8
|
+
return;
|
|
9
|
+
}
|
|
10
|
+
const ro = new ResizeObserver(([entry]) => {
|
|
11
|
+
setContainerWidth(entry.contentRect.width);
|
|
12
|
+
});
|
|
13
|
+
ro.observe(parentScrollRef.current);
|
|
14
|
+
return () => ro.disconnect();
|
|
15
|
+
}, []);
|
|
16
|
+
return {
|
|
17
|
+
parentScrollRef,
|
|
18
|
+
loaderRef,
|
|
19
|
+
containerWidth,
|
|
20
|
+
};
|
|
21
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { SortingState } from '@tanstack/react-table';
|
|
2
|
+
export declare function useTableSorting(controlledSorting?: SortingState, onSortingChange?: (s: SortingState) => void): {
|
|
3
|
+
sorting: SortingState;
|
|
4
|
+
onSortingChange: (updater: SortingState | ((prev: SortingState) => SortingState)) => void;
|
|
5
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { useState } from 'react';
|
|
2
|
+
export function useTableSorting(controlledSorting, onSortingChange) {
|
|
3
|
+
const [internalSorting, setInternalSorting] = useState(controlledSorting !== null && controlledSorting !== void 0 ? controlledSorting : []);
|
|
4
|
+
const sorting = controlledSorting !== null && controlledSorting !== void 0 ? controlledSorting : internalSorting;
|
|
5
|
+
const handleSortingChange = (updater) => {
|
|
6
|
+
const next = typeof updater === 'function' ? updater(sorting) : updater;
|
|
7
|
+
setInternalSorting(next);
|
|
8
|
+
onSortingChange === null || onSortingChange === void 0 ? void 0 : onSortingChange(next);
|
|
9
|
+
};
|
|
10
|
+
return {
|
|
11
|
+
sorting,
|
|
12
|
+
onSortingChange: handleSortingChange,
|
|
13
|
+
};
|
|
14
|
+
}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
export declare function useUrlPaginationSync(
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
pageSize: number;
|
|
5
|
-
setPageSize: import("react").Dispatch<import("react").SetStateAction<number>>;
|
|
1
|
+
export declare function useUrlPaginationSync(tableId: string, defaultPageSize: number): {
|
|
2
|
+
initialPageIndex: number;
|
|
3
|
+
initialPageSize: number;
|
|
4
|
+
syncToUrl: (pageIndex: number, pageSize: number) => void;
|
|
6
5
|
};
|
|
@@ -1,12 +1,26 @@
|
|
|
1
|
-
import { useState } from 'react';
|
|
1
|
+
import { useCallback, useState } from 'react';
|
|
2
2
|
import { useSearchParams } from 'react-router-dom';
|
|
3
|
-
export function useUrlPaginationSync(
|
|
4
|
-
const [searchParams] = useSearchParams();
|
|
5
|
-
const pageSizeKey = `${tableId}_pageSize`;
|
|
3
|
+
export function useUrlPaginationSync(tableId, defaultPageSize) {
|
|
4
|
+
const [searchParams, setSearchParams] = useSearchParams();
|
|
6
5
|
const pageNoKey = `${tableId}_pageNo`;
|
|
7
|
-
const
|
|
8
|
-
const
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
6
|
+
const pageSizeKey = `${tableId}_pageSize`;
|
|
7
|
+
const [initialPageIndex] = useState(() => {
|
|
8
|
+
const raw = Number(searchParams.get(pageNoKey));
|
|
9
|
+
return Number.isFinite(raw) && raw > 0 ? raw - 1 : 0;
|
|
10
|
+
});
|
|
11
|
+
const [initialPageSize] = useState(() => {
|
|
12
|
+
const raw = Number(searchParams.get(pageSizeKey));
|
|
13
|
+
return Number.isFinite(raw) && raw > 0 ? raw : defaultPageSize;
|
|
14
|
+
});
|
|
15
|
+
const syncToUrl = useCallback((pageIndex, pageSize) => {
|
|
16
|
+
const next = new URLSearchParams(searchParams);
|
|
17
|
+
next.set(pageNoKey, String(pageIndex + 1)); // 1-based
|
|
18
|
+
next.set(pageSizeKey, String(pageSize));
|
|
19
|
+
setSearchParams(next, { replace: true });
|
|
20
|
+
}, [pageNoKey, pageSizeKey, searchParams, setSearchParams]);
|
|
21
|
+
return {
|
|
22
|
+
initialPageIndex,
|
|
23
|
+
initialPageSize,
|
|
24
|
+
syncToUrl,
|
|
25
|
+
};
|
|
12
26
|
}
|
|
@@ -1,2 +1,5 @@
|
|
|
1
|
-
export
|
|
2
|
-
export
|
|
1
|
+
export { StandardTable } from './StandardTable';
|
|
2
|
+
export { InfiniteTable } from './InfiniteTable';
|
|
3
|
+
export type { StandardTableProps } from './StandardTable/StandardTable.types';
|
|
4
|
+
export type { InfiniteTableProps } from './InfiniteTable/InfiniteTable.props';
|
|
5
|
+
export type { FlexColumnDef, TableInputProps, ITableActionsDropdownProps, GroupRowClickHandler, StandardPaginationProps, ClientPaginationProps, ServerPaginationProps, InfiniteScrollOptions, VirtualizationOptions, InfiniteScrollTableProps, } from './Table.types';
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export
|
|
2
|
-
export
|
|
1
|
+
export { StandardTable } from './StandardTable';
|
|
2
|
+
export { InfiniteTable } from './InfiniteTable';
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type React from 'react';
|
|
2
|
+
import { type Row, type Table } from '@tanstack/react-table';
|
|
3
|
+
import type { ITableActionsDropdownProps } from '../Table.types';
|
|
4
|
+
interface RenderTableRowsProps<T extends {
|
|
5
|
+
id: string;
|
|
6
|
+
}> {
|
|
7
|
+
table: Table<T>;
|
|
8
|
+
rows: Row<T>[];
|
|
9
|
+
hasActions: boolean;
|
|
10
|
+
onRowClick?: (row: T) => void;
|
|
11
|
+
isRowClickable?: (row: T) => boolean;
|
|
12
|
+
onGroupRowClick?: (args: {
|
|
13
|
+
columnId: string;
|
|
14
|
+
value: unknown;
|
|
15
|
+
rows: T[];
|
|
16
|
+
}) => void;
|
|
17
|
+
tableActionsDropdown?: ITableActionsDropdownProps<T>;
|
|
18
|
+
}
|
|
19
|
+
export declare function renderTableRows<T extends {
|
|
20
|
+
id: string;
|
|
21
|
+
}>({ table, rows, onRowClick, isRowClickable, onGroupRowClick, tableActionsDropdown, hasActions, }: RenderTableRowsProps<T>): React.ReactNode[];
|
|
22
|
+
export {};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { renderGroupRow } from '../body/renderGroupRow';
|
|
2
|
+
import { renderLeafRow } from '../body/renderLeafRow';
|
|
3
|
+
export function renderTableRows({ table, rows, onRowClick, isRowClickable, onGroupRowClick, tableActionsDropdown, hasActions, }) {
|
|
4
|
+
const result = [];
|
|
5
|
+
for (const row of rows) {
|
|
6
|
+
if (row.getIsGrouped() && row.groupingColumnId) {
|
|
7
|
+
const groupedRow = row;
|
|
8
|
+
result.push(renderGroupRow({
|
|
9
|
+
row: groupedRow,
|
|
10
|
+
onGroupRowClick,
|
|
11
|
+
}), ...renderTableRows({
|
|
12
|
+
table,
|
|
13
|
+
rows: row.subRows,
|
|
14
|
+
hasActions,
|
|
15
|
+
onRowClick,
|
|
16
|
+
isRowClickable,
|
|
17
|
+
onGroupRowClick,
|
|
18
|
+
tableActionsDropdown,
|
|
19
|
+
}));
|
|
20
|
+
continue;
|
|
21
|
+
}
|
|
22
|
+
result.push(renderLeafRow({
|
|
23
|
+
row,
|
|
24
|
+
onRowClick,
|
|
25
|
+
isRowClickable,
|
|
26
|
+
hasActions,
|
|
27
|
+
tableActionsDropdown,
|
|
28
|
+
}));
|
|
29
|
+
}
|
|
30
|
+
return result;
|
|
31
|
+
}
|
|
@@ -1,8 +1,11 @@
|
|
|
1
|
-
import type { Table } from '@tanstack/react-table';
|
|
2
1
|
import type { FlexColumnDef } from './Table.types';
|
|
3
|
-
export declare function getCheckboxSelectionColumn<T>(
|
|
2
|
+
export declare function getCheckboxSelectionColumn<T>(): FlexColumnDef<T>;
|
|
4
3
|
export type VirtualFlexColumnDef<T> = FlexColumnDef<T> & {
|
|
5
4
|
size?: number;
|
|
6
5
|
_virtualLocked?: boolean;
|
|
7
6
|
};
|
|
8
7
|
export declare function applyFlexSizes<T>(columns?: FlexColumnDef<T>[], containerWidth?: number, virtualizationEnabled?: boolean): VirtualFlexColumnDef<T>[];
|
|
8
|
+
export declare function getRowInteractivity<T>(row: T, onRowClick?: (row: T) => void, isRowClickable?: (row: T) => boolean): {
|
|
9
|
+
clickable: boolean;
|
|
10
|
+
disabled: boolean;
|
|
11
|
+
};
|
|
@@ -1,21 +1,19 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import { Checkbox } from '../Checkbox';
|
|
3
|
-
export function getCheckboxSelectionColumn(
|
|
3
|
+
export function getCheckboxSelectionColumn() {
|
|
4
4
|
return {
|
|
5
5
|
id: 'select',
|
|
6
6
|
size: 24,
|
|
7
|
-
header: () => {
|
|
7
|
+
header: ({ table }) => {
|
|
8
8
|
if (!table.options.enableMultiRowSelection) {
|
|
9
9
|
return null;
|
|
10
10
|
}
|
|
11
11
|
const hasSelectableRows = table.getRowModel().rows.some((row) => row.getCanSelect());
|
|
12
|
-
return (_jsx("div", { className: "flex
|
|
13
|
-
// indeterminate={table.getIsSomeRowsSelected()} TODO: Implement indeterminate state
|
|
14
|
-
disabled: !hasSelectableRows, onCheckedChange: (checked) => {
|
|
12
|
+
return (_jsx("div", { className: "flex h-full items-center justify-center", children: _jsx(Checkbox, { checked: table.getIsAllPageRowsSelected(), disabled: !hasSelectableRows, onCheckedChange: (checked) => {
|
|
15
13
|
table.toggleAllPageRowsSelected(Boolean(checked));
|
|
16
14
|
} }) }));
|
|
17
15
|
},
|
|
18
|
-
cell: ({ row }) => (_jsx("div", { className: "flex
|
|
16
|
+
cell: ({ row }) => (_jsx("div", { className: "flex h-full items-center justify-center", children: _jsx(Checkbox, { checked: row.getIsSelected(), disabled: !row.getCanSelect(), onCheckedChange: (checked) => {
|
|
19
17
|
row.toggleSelected(Boolean(checked));
|
|
20
18
|
} }) })),
|
|
21
19
|
enableSorting: false,
|
|
@@ -24,8 +22,9 @@ export function getCheckboxSelectionColumn(table) {
|
|
|
24
22
|
};
|
|
25
23
|
}
|
|
26
24
|
export function applyFlexSizes(columns, containerWidth = 0, virtualizationEnabled = false) {
|
|
27
|
-
if (!columns)
|
|
25
|
+
if (!columns) {
|
|
28
26
|
return [];
|
|
27
|
+
}
|
|
29
28
|
if (!virtualizationEnabled || containerWidth === 0) {
|
|
30
29
|
return columns;
|
|
31
30
|
}
|
|
@@ -40,3 +39,10 @@ export function applyFlexSizes(columns, containerWidth = 0, virtualizationEnable
|
|
|
40
39
|
};
|
|
41
40
|
});
|
|
42
41
|
}
|
|
42
|
+
export function getRowInteractivity(row, onRowClick, isRowClickable) {
|
|
43
|
+
const allowed = isRowClickable ? isRowClickable(row) : true;
|
|
44
|
+
return {
|
|
45
|
+
clickable: Boolean(onRowClick) && allowed,
|
|
46
|
+
disabled: !allowed,
|
|
47
|
+
};
|
|
48
|
+
}
|
|
@@ -12,7 +12,7 @@ export const Default = {
|
|
|
12
12
|
render: () => (_jsx(TooltipStoryWrapper, { content: "Simple tooltip", children: _jsx(Button, { children: "Hover me" }) })),
|
|
13
13
|
};
|
|
14
14
|
export const LongTextResponsive = {
|
|
15
|
-
render: () => (_jsx(TooltipStoryWrapper, { content: "This tooltip contains a longer message that wraps gracefully across multiple lines. On smaller\
|
|
15
|
+
render: () => (_jsx(TooltipStoryWrapper, { content: "This tooltip contains a longer message that wraps gracefully across multiple lines. On smaller\n\t\tscreens, it narrows and stacks vertically so it's easier to read\u2014especially useful for\n\t\taccessibility, mobile devices, or multi-language support.", side: "top", children: _jsx(Button, { children: "Hover me" }) })),
|
|
16
16
|
};
|
|
17
17
|
export const OnDifferentSides = {
|
|
18
18
|
render: () => (_jsxs("div", { className: "grid grid-cols-2 gap-4", children: [_jsx(TooltipStoryWrapper, { content: "Top tooltip", side: "top", children: _jsx(Button, { children: "Top" }) }), _jsx(TooltipStoryWrapper, { content: "Bottom tooltip", side: "bottom", children: _jsx(Button, { children: "Bottom" }) }), _jsx(TooltipStoryWrapper, { content: "Left tooltip", side: "left", children: _jsx(Button, { children: "Left" }) }), _jsx(TooltipStoryWrapper, { content: "Right tooltip", side: "right", children: _jsx(Button, { children: "Right" }) })] })),
|
|
@@ -13,5 +13,5 @@ export const UICreditCard = ({ cvv, cvvLabel = 'CVV', cardNumber, cardNumberLabe
|
|
|
13
13
|
backgroundImage: `url(${backImageUrl})`,
|
|
14
14
|
}, children: customBackContent !== null && customBackContent !== void 0 ? customBackContent : (_jsxs("div", { className: "flex flex-col justify-end flex-1 gap-2", children: [_jsx("div", { children: _jsxs("div", { className: "flex flex-col items-start", children: [_jsx("div", { className: `text-xs text-(--uikit-textSecondary) ${classNames === null || classNames === void 0 ? void 0 : classNames.fieldLabel}`, children: cardholderNameLabel }), _jsx("div", { className: `text-base text-(--uikit-textPrimary) ${classNames === null || classNames === void 0 ? void 0 : classNames.fieldValue}`, children: cardholderName })] }) }), _jsxs("div", { className: "flex flex-col items-start", children: [_jsxs("div", { className: "flex items-center gap-2", children: [_jsx("span", { className: `text-xs text-(--uikit-textSecondary) ${classNames === null || classNames === void 0 ? void 0 : classNames.fieldLabel}`, children: cardNumberLabel }), enableCopy && _jsx(CopyButton, { value: cardNumber, className: classNames === null || classNames === void 0 ? void 0 : classNames.copyIcon })] }), _jsx("div", { className: `text-base text-(--uikit-textPrimary) ${classNames === null || classNames === void 0 ? void 0 : classNames.fieldValue}`, children: cardNumber })] }), _jsxs("div", { className: "flex items-start gap-10", children: [expiryDate && (_jsxs("div", { className: "flex flex-col items-start", children: [_jsxs("div", { className: "flex items-center gap-2", children: [_jsx("span", { className: "text-xs text-(--uikit-textSecondary)", children: expiryDateLabel }), enableCopy && (_jsx(CopyButton, { value: expiryDate, className: classNames === null || classNames === void 0 ? void 0 : classNames.copyIcon }))] }), _jsx("div", { className: `text-base text-(--uikit-textPrimary) ${classNames === null || classNames === void 0 ? void 0 : classNames.fieldValue}`, children: expiryDate })] })), cvv && (_jsxs("div", { className: "flex flex-col items-start", children: [_jsxs("div", { className: "flex items-center gap-2", children: [_jsx("span", { className: "text-xs text-(--uikit-textSecondary)", children: cvvLabel }), enableCopy && _jsx(CopyButton, { value: cvv, className: classNames === null || classNames === void 0 ? void 0 : classNames.copyIcon })] }), _jsx("div", { className: `text-base text-(--uikit-textPrimary) ${classNames === null || classNames === void 0 ? void 0 : classNames.fieldValue}`, children: cvv })] }))] })] })) }), isBlocked && (_jsx("div", { className: `absolute inset-0 h-full w-full opacity-50 ${classNames === null || classNames === void 0 ? void 0 : classNames.blockedOverlay}`, style: {
|
|
15
15
|
zIndex: 10,
|
|
16
|
-
}, children: _jsx("img", { src: blockedImageUrlOverlay, alt: "Card blocked", className:
|
|
16
|
+
}, children: _jsx("img", { src: blockedImageUrlOverlay, alt: "Card blocked", className: "h-full w-full object-cover rounded-(--uikit-radius)" }) }))] }) }));
|
|
17
17
|
};
|
|
@@ -31,15 +31,17 @@ export const WithDefaultFlipState = {
|
|
|
31
31
|
export const CopyDisabled = {
|
|
32
32
|
render: () => (_jsx("div", { style: { maxWidth: '450px', margin: '0 auto' }, children: _jsx(UICreditCard, { isFlipped: true, enableCopy: false, cardholderName: "No Copy", cardNumber: "4444 5555 6666 7777", expiryDate: "11/29", cvv: "000", frontImageUrl: "https://fastly.picsum.photos/id/349/200/300.jpg?hmac=gEjHZbjuKtdD2GOM-qQtuaA95TCvDUs6iVvKraQ94nU", backImageUrl: "https://fastly.picsum.photos/id/349/200/300.jpg?hmac=gEjHZbjuKtdD2GOM-qQtuaA95TCvDUs6iVvKraQ94nU" }) })),
|
|
33
33
|
};
|
|
34
|
+
function ControlledFlipToggleExample() {
|
|
35
|
+
const [flipped, setFlipped] = useState(false);
|
|
36
|
+
return (_jsx("div", { style: { maxWidth: '450px', margin: '0 auto' }, children: _jsxs("div", { className: "flex flex-col items-center gap-4", children: [_jsx("button", { className: "px-4 py-2 bg-blue-600 text-white rounded hover:bg-blue-700 transition", onClick: () => setFlipped((prev) => !prev), children: flipped ? 'Show Front' : 'Show Back' }), _jsx(UICreditCard, { isFlipped: flipped, cardholderName: "Toggle Flip", cardNumber: "8888 9999 0000 1111", expiryDate: "08/28", cvv: "456", enableCopy: true, frontImageUrl: "https://fastly.picsum.photos/id/349/200/300.jpg?hmac=gEjHZbjuKtdD2GOM-qQtuaA95TCvDUs6iVvKraQ94nU", backImageUrl: "https://fastly.picsum.photos/id/349/200/300.jpg?hmac=gEjHZbjuKtdD2GOM-qQtuaA95TCvDUs6iVvKraQ94nU" })] }) }));
|
|
37
|
+
}
|
|
34
38
|
export const ControlledFlipToggle = {
|
|
35
|
-
render: () => {
|
|
36
|
-
const [flipped, setFlipped] = useState(false);
|
|
37
|
-
return (_jsx("div", { style: { maxWidth: '450px', margin: '0 auto' }, children: _jsxs("div", { className: "flex flex-col items-center gap-4", children: [_jsx("button", { className: "px-4 py-2 bg-blue-600 text-white rounded hover:bg-blue-700 transition", onClick: () => setFlipped((prev) => !prev), children: flipped ? 'Show Front' : 'Show Back' }), _jsx(UICreditCard, { isFlipped: flipped, cardholderName: "Toggle Flip", cardNumber: "8888 9999 0000 1111", expiryDate: "08/28", cvv: "456", enableCopy: true, frontImageUrl: "https://fastly.picsum.photos/id/349/200/300.jpg?hmac=gEjHZbjuKtdD2GOM-qQtuaA95TCvDUs6iVvKraQ94nU", backImageUrl: "https://fastly.picsum.photos/id/349/200/300.jpg?hmac=gEjHZbjuKtdD2GOM-qQtuaA95TCvDUs6iVvKraQ94nU" })] }) }));
|
|
38
|
-
},
|
|
39
|
+
render: () => _jsx(ControlledFlipToggleExample, {}),
|
|
39
40
|
};
|
|
41
|
+
function BlockedCardExample() {
|
|
42
|
+
const [flipped, setFlipped] = useState(false);
|
|
43
|
+
return (_jsx("div", { style: { maxWidth: '450px', margin: '0 auto' }, children: _jsxs("div", { className: "flex flex-col items-center gap-4", children: [_jsx("button", { className: "px-4 py-2 bg-blue-600 text-white rounded hover:bg-blue-700 transition", onClick: () => setFlipped((prev) => !prev), children: flipped ? 'Show Front' : 'Show Back' }), _jsx(UICreditCard, { isFlipped: flipped, isBlocked: true, blockedImageUrlOverlay: "https://thumbs.dreamstime.com/b/frozen-background-12857463.jpg", cardholderName: "Blocked Card", cardNumber: "5555 6666 7777 8888", expiryDate: "10/27", cvv: "321", enableCopy: false, frontImageUrl: "https://fastly.picsum.photos/id/349/200/300.jpg?hmac=gEjHZbjuKtdD2GOM-qQtuaA95TCvDUs6iVvKraQ94nU", backImageUrl: "https://fastly.picsum.photos/id/349/200/300.jpg?hmac=gEjHZbjuKtdD2GOM-qQtuaA95TCvDUs6iVvKraQ94nU" })] }) }));
|
|
44
|
+
}
|
|
40
45
|
export const BlockedCard = {
|
|
41
|
-
render: () => {
|
|
42
|
-
const [flipped, setFlipped] = useState(false);
|
|
43
|
-
return (_jsx("div", { style: { maxWidth: '450px', margin: '0 auto' }, children: _jsxs("div", { className: "flex flex-col items-center gap-4", children: [_jsx("button", { className: "px-4 py-2 bg-blue-600 text-white rounded hover:bg-blue-700 transition", onClick: () => setFlipped((prev) => !prev), children: flipped ? 'Show Front' : 'Show Back' }), _jsx(UICreditCard, { isFlipped: flipped, isBlocked: true, blockedImageUrlOverlay: "https://thumbs.dreamstime.com/b/frozen-background-12857463.jpg", cardholderName: "Blocked Card", cardNumber: "5555 6666 7777 8888", expiryDate: "10/27", cvv: "321", enableCopy: false, frontImageUrl: "https://fastly.picsum.photos/id/349/200/300.jpg?hmac=gEjHZbjuKtdD2GOM-qQtuaA95TCvDUs6iVvKraQ94nU", backImageUrl: "https://fastly.picsum.photos/id/349/200/300.jpg?hmac=gEjHZbjuKtdD2GOM-qQtuaA95TCvDUs6iVvKraQ94nU" })] }) }));
|
|
44
|
-
},
|
|
46
|
+
render: () => _jsx(BlockedCardExample, {}),
|
|
45
47
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eml-payments/ui-kit",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.3",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "ARLO UIKit",
|
|
6
6
|
"homepage": "https://github.com/EML-Payments/arlo.npm.uikit#readme",
|
|
@@ -67,7 +67,7 @@
|
|
|
67
67
|
"class-variance-authority": "^0.7.1",
|
|
68
68
|
"clsx": "^2.1.1",
|
|
69
69
|
"dayjs": "^1.11.19",
|
|
70
|
-
"lucide-react": "^0.
|
|
70
|
+
"lucide-react": "^0.575.0",
|
|
71
71
|
"prettier": "^3.6.2",
|
|
72
72
|
"react": ">=18.0.0",
|
|
73
73
|
"react-day-picker": "^9.13.0",
|