@pushwoosh/smart-components-kit 2.5.3 → 2.6.0
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/Table/components/DataTable/DataTable.js +3 -1
- package/Table/components/DataTable/types.d.ts +9 -0
- package/Table/components/DataTableList/DataTableList.d.ts +1 -1
- package/Table/components/DataTableList/DataTableList.js +24 -1
- package/Table/components/DataTableList/types.d.ts +2 -1
- package/Table/components/ExpandToggle/ExpandToggle.d.ts +7 -0
- package/Table/components/ExpandToggle/ExpandToggle.js +23 -0
- package/Table/components/ExpandToggle/index.d.ts +1 -0
- package/Table/components/ExpandToggle/index.js +1 -0
- package/Table/components/ItemDetailLink/ItemDetailLink.d.ts +5 -5
- package/Table/components/ItemDetailLink/ItemDetailLink.js +2 -1
- package/Table/expansion.d.ts +6 -0
- package/Table/expansion.js +2 -0
- package/Table/hooks/index.d.ts +1 -0
- package/Table/hooks/index.js +2 -1
- package/Table/hooks/useRowExpansion.d.ts +9 -0
- package/Table/hooks/useRowExpansion.js +26 -0
- package/Table/index.d.ts +3 -2
- package/Table/index.js +3 -2
- package/package.json +10 -10
|
@@ -33,6 +33,7 @@ export function DataTable(props) {
|
|
|
33
33
|
} = context;
|
|
34
34
|
const isFiltered = data.value?.isFiltered || params.search;
|
|
35
35
|
const selection = 'renderItem' in props ? props.selection : undefined;
|
|
36
|
+
const expansion = 'renderItem' in props ? props.expansion : undefined;
|
|
36
37
|
const renderHead = () => {
|
|
37
38
|
if (!('renderHead' in props)) return null;
|
|
38
39
|
if (!selection) return props.renderHead();
|
|
@@ -65,7 +66,8 @@ export function DataTable(props) {
|
|
|
65
66
|
"$bgColor": bgColor,
|
|
66
67
|
children: [renderTableTop?.(context), renderHead(), 'renderList' in props ? props.renderList(context) : _jsx(DataTableList, {
|
|
67
68
|
renderItem: props.renderItem,
|
|
68
|
-
selection: selection
|
|
69
|
+
selection: selection,
|
|
70
|
+
expansion: expansion
|
|
69
71
|
}), !hidePagination && _jsxs(DataTablePagination, {
|
|
70
72
|
allLimits: allLimits ?? [10, 20, 50, 100],
|
|
71
73
|
padding: paginationPadding,
|
|
@@ -23,6 +23,13 @@ export type DataTableSelection<I> = {
|
|
|
23
23
|
/** Omitted: every row is selectable, as in flows that check eligibility on the chosen batch. */
|
|
24
24
|
isSelectable?: (row: I) => boolean;
|
|
25
25
|
};
|
|
26
|
+
/** Row expansion of {@link DataTable}: the content of an open row is rendered right after it, as further children of `Table`. */
|
|
27
|
+
export type DataTableExpansion<I> = {
|
|
28
|
+
expandedKeys: ReadonlySet<string>;
|
|
29
|
+
getKey: (row: I) => string;
|
|
30
|
+
onToggle: (row: I, isExpanded: boolean) => void;
|
|
31
|
+
renderExpanded: (row: I) => ReactNode;
|
|
32
|
+
};
|
|
26
33
|
export type DataTableItemProps<I, P extends DataTableParams> = {
|
|
27
34
|
columns: string;
|
|
28
35
|
width?: string | number;
|
|
@@ -40,5 +47,7 @@ export type DataTableItemProps<I, P extends DataTableParams> = {
|
|
|
40
47
|
onClearRequest?: () => void;
|
|
41
48
|
/** Turns on bulk selection: a checkbox gutter is prepended to the head and to every row. */
|
|
42
49
|
selection?: DataTableSelection<I>;
|
|
50
|
+
/** Turns on row expansion; ignored while `selection` is set (names go plain), the open rows come back when bulk mode ends. */
|
|
51
|
+
expansion?: DataTableExpansion<I>;
|
|
43
52
|
};
|
|
44
53
|
export type DataTableProps<I, P extends DataTableParams> = DataTableListProps<I, P> | DataTableItemProps<I, P>;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import type { DataTableListProps } from './types';
|
|
2
|
-
export declare function DataTableList<T>({ renderItem, selection }: DataTableListProps<T>): import("react").JSX.Element;
|
|
2
|
+
export declare function DataTableList<T>({ renderItem, selection, expansion }: DataTableListProps<T>): import("react").JSX.Element;
|
|
@@ -6,13 +6,15 @@ import Box from '../../assets/box.svg?url';
|
|
|
6
6
|
import Error from '../../assets/error.svg?url';
|
|
7
7
|
import NotFound from '../../assets/notfound.svg?url';
|
|
8
8
|
import { DataTableContext } from '../../context';
|
|
9
|
+
import { ExpansionRowContext } from '../../expansion';
|
|
9
10
|
import { useLang } from '../../polyglot';
|
|
10
11
|
import { LockedText } from '../../styles';
|
|
11
12
|
import { Loading } from '../Loading';
|
|
12
13
|
import { SelectableRow } from '../SelectionRow';
|
|
13
14
|
export function DataTableList({
|
|
14
15
|
renderItem,
|
|
15
|
-
selection
|
|
16
|
+
selection,
|
|
17
|
+
expansion
|
|
16
18
|
}) {
|
|
17
19
|
const {
|
|
18
20
|
data,
|
|
@@ -43,6 +45,27 @@ export function DataTableList({
|
|
|
43
45
|
})
|
|
44
46
|
});
|
|
45
47
|
}
|
|
48
|
+
if (data.value?.items?.length && expansion) {
|
|
49
|
+
const {
|
|
50
|
+
expandedKeys,
|
|
51
|
+
getKey,
|
|
52
|
+
onToggle,
|
|
53
|
+
renderExpanded
|
|
54
|
+
} = expansion;
|
|
55
|
+
return _jsx(_Fragment, {
|
|
56
|
+
children: data.value.items.map(item => {
|
|
57
|
+
const key = getKey(item);
|
|
58
|
+
const isExpanded = expandedKeys.has(key);
|
|
59
|
+
return _jsxs(ExpansionRowContext.Provider, {
|
|
60
|
+
value: {
|
|
61
|
+
isExpanded,
|
|
62
|
+
toggle: () => onToggle(item, !isExpanded)
|
|
63
|
+
},
|
|
64
|
+
children: [renderItem(item), isExpanded && renderExpanded(item)]
|
|
65
|
+
}, key);
|
|
66
|
+
})
|
|
67
|
+
});
|
|
68
|
+
}
|
|
46
69
|
if (data.value?.items?.length) {
|
|
47
70
|
return _jsx(_Fragment, {
|
|
48
71
|
children: data.value.items.map(renderItem)
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { ReactNode } from 'react';
|
|
2
|
-
import type { DataTableSelection } from '../DataTable/types';
|
|
2
|
+
import type { DataTableExpansion, DataTableSelection } from '../DataTable/types';
|
|
3
3
|
export type DataTableListProps<T> = {
|
|
4
4
|
renderItem: (item: T) => ReactNode;
|
|
5
5
|
selection?: DataTableSelection<T>;
|
|
6
|
+
expansion?: DataTableExpansion<T>;
|
|
6
7
|
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { type ReactElement, type ReactNode } from 'react';
|
|
2
|
+
type ExpandToggleProps = {
|
|
3
|
+
children: ReactNode;
|
|
4
|
+
};
|
|
5
|
+
/** The name of an expandable row: a chevron button that toggles the row; a plain name outside an expandable table. */
|
|
6
|
+
export declare function ExpandToggle({ children }: ExpandToggleProps): ReactElement;
|
|
7
|
+
export {};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useContext } from 'react';
|
|
3
|
+
import { ExpansionRowContext } from '../../expansion';
|
|
4
|
+
import { ItemName } from '../../styles';
|
|
5
|
+
import { ItemDetailLink } from '../ItemDetailLink';
|
|
6
|
+
/** The name of an expandable row: a chevron button that toggles the row; a plain name outside an expandable table. */
|
|
7
|
+
export function ExpandToggle({
|
|
8
|
+
children
|
|
9
|
+
}) {
|
|
10
|
+
const row = useContext(ExpansionRowContext);
|
|
11
|
+
if (!row) return _jsx(ItemName, {
|
|
12
|
+
children: children
|
|
13
|
+
});
|
|
14
|
+
return _jsx(ItemDetailLink, {
|
|
15
|
+
as: "button",
|
|
16
|
+
type: "button",
|
|
17
|
+
withChevron: true,
|
|
18
|
+
chevronDirection: row.isExpanded ? 'up' : 'down',
|
|
19
|
+
"aria-expanded": row.isExpanded,
|
|
20
|
+
onClick: row.toggle,
|
|
21
|
+
children: children
|
|
22
|
+
});
|
|
23
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { ExpandToggle } from './ExpandToggle';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { ExpandToggle } from './ExpandToggle';
|
|
@@ -2,17 +2,17 @@ import { type ComponentProps, type ComponentType, type JSX, type ReactElement, t
|
|
|
2
2
|
declare const StyledItemDetailLink: import("styled-components/dist/types").IStyledComponentBase<"web", Omit<import("react").DetailedHTMLProps<import("react").AnchorHTMLAttributes<HTMLAnchorElement>, HTMLAnchorElement>, "style"> & {
|
|
3
3
|
style?: import("react").CSSProperties | import("styled-components/dist/types").CSSPropertiesWithVars | undefined;
|
|
4
4
|
}> & string;
|
|
5
|
-
type
|
|
5
|
+
type ChevronProps = {
|
|
6
6
|
withChevron?: boolean;
|
|
7
|
+
chevronDirection?: 'right' | 'down' | 'up';
|
|
7
8
|
};
|
|
9
|
+
type ItemDetailLinkProps = ComponentProps<typeof StyledItemDetailLink> & ChevronProps;
|
|
8
10
|
export declare function ItemDetailLink<AS extends keyof JSX.IntrinsicElements>(props: JSX.IntrinsicElements[AS] & {
|
|
9
11
|
as: AS;
|
|
10
|
-
|
|
11
|
-
}): ReactElement;
|
|
12
|
+
} & ChevronProps): ReactElement;
|
|
12
13
|
export declare function ItemDetailLink<OuterProps extends object>(props: OuterProps & {
|
|
13
14
|
as: ComponentType<OuterProps>;
|
|
14
|
-
withChevron?: boolean;
|
|
15
15
|
children?: ReactNode;
|
|
16
|
-
}): ReactElement;
|
|
16
|
+
} & ChevronProps): ReactElement;
|
|
17
17
|
export declare function ItemDetailLink(props: ItemDetailLinkProps): ReactElement;
|
|
18
18
|
export {};
|
|
@@ -16,6 +16,7 @@ const Chevron = styled(ChevronIcon).withConfig({
|
|
|
16
16
|
})(["flex-shrink:0;"]);
|
|
17
17
|
export function ItemDetailLink({
|
|
18
18
|
withChevron,
|
|
19
|
+
chevronDirection = 'right',
|
|
19
20
|
children,
|
|
20
21
|
...props
|
|
21
22
|
}) {
|
|
@@ -29,7 +30,7 @@ export function ItemDetailLink({
|
|
|
29
30
|
children: children
|
|
30
31
|
}), _jsx(Chevron, {
|
|
31
32
|
size: "small",
|
|
32
|
-
direction:
|
|
33
|
+
direction: chevronDirection
|
|
33
34
|
})]
|
|
34
35
|
});
|
|
35
36
|
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/** What a row of {@link DataTable} knows about its own expansion; `null` outside an expandable table. */
|
|
2
|
+
export type ExpansionRow = {
|
|
3
|
+
isExpanded: boolean;
|
|
4
|
+
toggle: () => void;
|
|
5
|
+
};
|
|
6
|
+
export declare const ExpansionRowContext: import("react").Context<ExpansionRow | null>;
|
package/Table/hooks/index.d.ts
CHANGED
|
@@ -2,3 +2,4 @@ export { useDataTableContext } from './useDataTableContext';
|
|
|
2
2
|
export { useDataTableContextSync } from './useDataTableContextSync';
|
|
3
3
|
export { useDataTableGetParams } from './useDataTableGetParams';
|
|
4
4
|
export { useBulkSelection, type BulkSelection, type BulkSelectionPageCheckbox } from './useBulkSelection';
|
|
5
|
+
export { useRowExpansion, type RowExpansion } from './useRowExpansion';
|
package/Table/hooks/index.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export { useDataTableContext } from './useDataTableContext';
|
|
2
2
|
export { useDataTableContextSync } from './useDataTableContextSync';
|
|
3
3
|
export { useDataTableGetParams } from './useDataTableGetParams';
|
|
4
|
-
export { useBulkSelection } from './useBulkSelection';
|
|
4
|
+
export { useBulkSelection } from './useBulkSelection';
|
|
5
|
+
export { useRowExpansion } from './useRowExpansion';
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/** What {@link useRowExpansion} returns. */
|
|
2
|
+
export type RowExpansion<T> = {
|
|
3
|
+
expandedKeys: ReadonlySet<string>;
|
|
4
|
+
toggle: (row: T, isExpanded: boolean) => void;
|
|
5
|
+
isExpanded: (row: T) => boolean;
|
|
6
|
+
collapseAll: () => void;
|
|
7
|
+
};
|
|
8
|
+
/** The rows opened in place, kept across pages and bulk mode; `getKey` should be stable. */
|
|
9
|
+
export declare function useRowExpansion<T>(getKey: (row: T) => string): RowExpansion<T>;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { useCallback, useState } from 'react';
|
|
2
|
+
/** The rows opened in place, kept across pages and bulk mode; `getKey` should be stable. */
|
|
3
|
+
export function useRowExpansion(getKey) {
|
|
4
|
+
const [expandedKeys, setExpandedKeys] = useState(() => new Set());
|
|
5
|
+
const toggle = useCallback((row, isExpanded) => {
|
|
6
|
+
const key = getKey(row);
|
|
7
|
+
setExpandedKeys(prev => {
|
|
8
|
+
if (prev.has(key) === isExpanded) return prev;
|
|
9
|
+
const next = new Set(prev);
|
|
10
|
+
if (isExpanded) {
|
|
11
|
+
next.add(key);
|
|
12
|
+
} else {
|
|
13
|
+
next.delete(key);
|
|
14
|
+
}
|
|
15
|
+
return next;
|
|
16
|
+
});
|
|
17
|
+
}, [getKey]);
|
|
18
|
+
const isExpanded = useCallback(row => expandedKeys.has(getKey(row)), [expandedKeys, getKey]);
|
|
19
|
+
const collapseAll = useCallback(() => setExpandedKeys(prev => prev.size ? new Set() : prev), []);
|
|
20
|
+
return {
|
|
21
|
+
expandedKeys,
|
|
22
|
+
toggle,
|
|
23
|
+
isExpanded,
|
|
24
|
+
collapseAll
|
|
25
|
+
};
|
|
26
|
+
}
|
package/Table/index.d.ts
CHANGED
|
@@ -6,8 +6,9 @@ export { DataTableSearchInput } from './components/DataTableSearchInput';
|
|
|
6
6
|
export { DataTableSortableCell } from './components/DataTableSortableCell';
|
|
7
7
|
export { Loading } from './components/Loading';
|
|
8
8
|
export { TablePagination } from './components/TablePagination';
|
|
9
|
-
export { useDataTableContext, useDataTableGetParams, useBulkSelection, type BulkSelection, type BulkSelectionPageCheckbox, } from './hooks';
|
|
9
|
+
export { useDataTableContext, useDataTableGetParams, useBulkSelection, useRowExpansion, type BulkSelection, type BulkSelectionPageCheckbox, type RowExpansion, } from './hooks';
|
|
10
10
|
export { Table, Td, Tr, Th, ElementHover, ItemName, LockedText, Description, } from './styles';
|
|
11
11
|
export { ItemDetailLink } from './components/ItemDetailLink';
|
|
12
|
+
export { ExpandToggle } from './components/ExpandToggle';
|
|
12
13
|
export type { DataTableParams, DataTableData, DataTableContextType } from './types';
|
|
13
|
-
export type { DataTableSelection } from './components/DataTable/types';
|
|
14
|
+
export type { DataTableExpansion, DataTableSelection } from './components/DataTable/types';
|
package/Table/index.js
CHANGED
|
@@ -6,6 +6,7 @@ export { DataTableSearchInput } from './components/DataTableSearchInput';
|
|
|
6
6
|
export { DataTableSortableCell } from './components/DataTableSortableCell';
|
|
7
7
|
export { Loading } from './components/Loading';
|
|
8
8
|
export { TablePagination } from './components/TablePagination';
|
|
9
|
-
export { useDataTableContext, useDataTableGetParams, useBulkSelection } from './hooks';
|
|
9
|
+
export { useDataTableContext, useDataTableGetParams, useBulkSelection, useRowExpansion } from './hooks';
|
|
10
10
|
export { Table, Td, Tr, Th, ElementHover, ItemName, LockedText, Description } from './styles';
|
|
11
|
-
export { ItemDetailLink } from './components/ItemDetailLink';
|
|
11
|
+
export { ItemDetailLink } from './components/ItemDetailLink';
|
|
12
|
+
export { ExpandToggle } from './components/ExpandToggle';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pushwoosh/smart-components-kit",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.6.0",
|
|
4
4
|
"description": "Stateful, data-connected React components shared by Pushwoosh micro-frontends",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -26,18 +26,18 @@
|
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
28
|
"@floating-ui/react-dom": "^2.1.9",
|
|
29
|
-
"@pushwoosh/dumb-components": "^4.
|
|
29
|
+
"@pushwoosh/dumb-components": "^4.18.0",
|
|
30
30
|
"@pushwoosh/kit-constants": "^3.2.1",
|
|
31
31
|
"@pushwoosh/kit-helpers": "^4.17.2",
|
|
32
32
|
"@pushwoosh/kit-icons": "^3.0.2",
|
|
33
|
-
"@pushwoosh/kit-typography": "^2.
|
|
34
|
-
"@pushwoosh/rpc-v2-http-api-data": "^0.2.
|
|
33
|
+
"@pushwoosh/kit-typography": "^2.2.0",
|
|
34
|
+
"@pushwoosh/rpc-v2-http-api-data": "^0.2.556",
|
|
35
35
|
"jwt-decode": "^4.0.0",
|
|
36
36
|
"react-hook-form": "^7.91.0"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
|
-
"@pushwoosh/frontend-builder-engine": "^5.
|
|
40
|
-
"@pushwoosh/spa-context": "^3.
|
|
39
|
+
"@pushwoosh/frontend-builder-engine": "^5.6.0",
|
|
40
|
+
"@pushwoosh/spa-context": "^3.9.0",
|
|
41
41
|
"@svgr/webpack": "^8.1.0",
|
|
42
42
|
"@testing-library/dom": "^10.4.2",
|
|
43
43
|
"@testing-library/react": "^16.3.3",
|
|
@@ -47,10 +47,10 @@
|
|
|
47
47
|
"@types/react-router-dom": "^5.3.3",
|
|
48
48
|
"@types/webpack-env": "^1.18.8",
|
|
49
49
|
"jsdom": "^30.1.3",
|
|
50
|
-
"react": "
|
|
51
|
-
"react-dom": "
|
|
52
|
-
"react-router-dom": "
|
|
53
|
-
"styled-components": "
|
|
50
|
+
"react": "19.3.0",
|
|
51
|
+
"react-dom": "19.3.0",
|
|
52
|
+
"react-router-dom": "5.3.4",
|
|
53
|
+
"styled-components": "6.6.0",
|
|
54
54
|
"vitest": "^4.1.12"
|
|
55
55
|
},
|
|
56
56
|
"peerDependencies": {
|