@popsure/dirty-swan 0.54.2 → 0.54.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/cjs/index.js +355 -262
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/lib/components/table/components/TableCell/BaseCell/BaseCell.d.ts +17 -0
- package/dist/cjs/lib/components/table/components/TableCell/BaseCell/BaseCell.stories.d.ts +22 -0
- package/dist/cjs/lib/components/table/components/TableCell/BaseCell/MiniProgressBar/MiniProgressBar.d.ts +3 -0
- package/dist/cjs/lib/components/table/components/TableCell/BaseCell/MiniProgressBar/MiniProgressBar.stories.d.ts +25 -0
- package/dist/cjs/lib/components/table/components/TableCell/ButtonCell/ButtonCell.d.ts +9 -0
- package/dist/cjs/lib/components/table/components/TableCell/ButtonCell/ButtonCell.stories.d.ts +17 -0
- package/dist/cjs/lib/components/table/components/TableCell/CTACell/CTACell.d.ts +10 -0
- package/dist/cjs/lib/components/table/components/TableCell/CTACell/CTACell.stories.d.ts +18 -0
- package/dist/cjs/lib/components/table/components/TableCell/TableCell.d.ts +5 -17
- package/dist/cjs/lib/components/table/types.d.ts +19 -2
- package/dist/cjs/lib/components/table/utils/useTableNavigation/useTableNavigation.d.ts +1 -2
- package/dist/esm/TableSection-f6d0028e.js +80 -0
- package/dist/esm/TableSection-f6d0028e.js.map +1 -0
- package/dist/esm/components/cards/card/index.stories.js +2 -2
- package/dist/esm/components/cards/card/index.stories.js.map +1 -1
- package/dist/esm/components/comparisonTable/components/TableInfoButton/index.js +2 -2
- package/dist/esm/components/comparisonTable/components/TableInfoButton/index.js.map +1 -1
- package/dist/esm/components/comparisonTable/index.js +3 -1526
- package/dist/esm/components/comparisonTable/index.js.map +1 -1
- package/dist/esm/components/comparisonTable/index.stories.js +1 -0
- package/dist/esm/components/comparisonTable/index.stories.js.map +1 -1
- package/dist/esm/components/icon/icons/Info.js +2 -2
- package/dist/esm/components/icon/icons/Info.js.map +1 -1
- package/dist/esm/components/icon/icons.stories.js +1 -1
- package/dist/esm/components/icon/index.stories.js +1 -1
- package/dist/esm/components/table/Table.js +22 -13
- package/dist/esm/components/table/Table.js.map +1 -1
- package/dist/esm/components/table/Table.stories.js +100 -32
- package/dist/esm/components/table/Table.stories.js.map +1 -1
- package/dist/esm/components/table/Table.test.js +15 -12
- package/dist/esm/components/table/Table.test.js.map +1 -1
- package/dist/esm/components/table/components/TableCell/BaseCell/BaseCell.js +50 -0
- package/dist/esm/components/table/components/TableCell/BaseCell/BaseCell.js.map +1 -0
- package/dist/esm/components/table/components/TableCell/BaseCell/BaseCell.stories.js +43 -0
- package/dist/esm/components/table/components/TableCell/BaseCell/BaseCell.stories.js.map +1 -0
- package/dist/esm/components/table/components/TableCell/BaseCell/MiniProgressBar/MiniProgressBar.js +15 -0
- package/dist/esm/components/table/components/TableCell/BaseCell/MiniProgressBar/MiniProgressBar.js.map +1 -0
- package/dist/esm/components/table/components/TableCell/BaseCell/MiniProgressBar/MiniProgressBar.stories.js +31 -0
- package/dist/esm/components/table/components/TableCell/BaseCell/MiniProgressBar/MiniProgressBar.stories.js.map +1 -0
- package/dist/esm/components/table/components/TableCell/ButtonCell/ButtonCell.js +23 -0
- package/dist/esm/components/table/components/TableCell/ButtonCell/ButtonCell.js.map +1 -0
- package/dist/esm/components/table/components/TableCell/ButtonCell/ButtonCell.stories.js +28 -0
- package/dist/esm/components/table/components/TableCell/ButtonCell/ButtonCell.stories.js.map +1 -0
- package/dist/esm/components/table/components/TableCell/CTACell/CTACell.js +21 -0
- package/dist/esm/components/table/components/TableCell/CTACell/CTACell.js.map +1 -0
- package/dist/esm/components/table/components/TableCell/CTACell/CTACell.stories.js +26 -0
- package/dist/esm/components/table/components/TableCell/CTACell/CTACell.stories.js.map +1 -0
- package/dist/esm/components/table/components/TableCell/TableCell.js +24 -20
- package/dist/esm/components/table/components/TableCell/TableCell.js.map +1 -1
- package/dist/esm/components/table/components/TableCell/TableCell.test.js +26 -14
- package/dist/esm/components/table/components/TableCell/TableCell.test.js.map +1 -1
- package/dist/esm/components/table/components/TableContents/TableContents.js +11 -3
- package/dist/esm/components/table/components/TableContents/TableContents.js.map +1 -1
- package/dist/esm/components/table/components/TableContents/TableContents.test.js +14 -7
- package/dist/esm/components/table/components/TableContents/TableContents.test.js.map +1 -1
- package/dist/esm/components/table/components/TableSection/TableSection.js +17 -53
- package/dist/esm/components/table/components/TableSection/TableSection.js.map +1 -1
- package/dist/esm/components/table/components/TableSection/TableSection.test.js +12 -5
- package/dist/esm/components/table/components/TableSection/TableSection.test.js.map +1 -1
- package/dist/esm/components/table/utils/useTableNavigation/useTableNavigation.test.js +1 -5
- package/dist/esm/components/table/utils/useTableNavigation/useTableNavigation.test.js.map +1 -1
- package/dist/esm/index-3d286178.js +1529 -0
- package/dist/esm/index-3d286178.js.map +1 -0
- package/dist/esm/{index-0bb5a2ee.js → index-7506ae25.js} +3 -3
- package/dist/esm/{index-0bb5a2ee.js.map → index-7506ae25.js.map} +1 -1
- package/dist/esm/index.js +7 -2
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/lib/components/table/components/TableCell/BaseCell/BaseCell.d.ts +17 -0
- package/dist/esm/lib/components/table/components/TableCell/BaseCell/BaseCell.stories.d.ts +22 -0
- package/dist/esm/lib/components/table/components/TableCell/BaseCell/MiniProgressBar/MiniProgressBar.d.ts +3 -0
- package/dist/esm/lib/components/table/components/TableCell/BaseCell/MiniProgressBar/MiniProgressBar.stories.d.ts +25 -0
- package/dist/esm/lib/components/table/components/TableCell/ButtonCell/ButtonCell.d.ts +9 -0
- package/dist/esm/lib/components/table/components/TableCell/ButtonCell/ButtonCell.stories.d.ts +17 -0
- package/dist/esm/lib/components/table/components/TableCell/CTACell/CTACell.d.ts +10 -0
- package/dist/esm/lib/components/table/components/TableCell/CTACell/CTACell.stories.d.ts +18 -0
- package/dist/esm/lib/components/table/components/TableCell/TableCell.d.ts +5 -17
- package/dist/esm/lib/components/table/types.d.ts +19 -2
- package/dist/esm/lib/components/table/utils/useTableNavigation/useTableNavigation.d.ts +1 -2
- package/dist/esm/{useTableNavigation-8e50b121.js → useTableNavigation-2899712c.js} +12 -16
- package/dist/esm/useTableNavigation-2899712c.js.map +1 -0
- package/package.json +1 -1
- package/src/lib/components/table/Table.stories.tsx +87 -25
- package/src/lib/components/table/Table.test.tsx +3 -6
- package/src/lib/components/table/Table.tsx +11 -9
- package/src/lib/components/table/components/TableCell/BaseCell/BaseCell.module.scss +36 -0
- package/src/lib/components/table/components/TableCell/BaseCell/BaseCell.stories.tsx +45 -0
- package/src/lib/components/table/components/TableCell/BaseCell/BaseCell.tsx +158 -0
- package/src/lib/components/table/components/TableCell/BaseCell/MiniProgressBar/MiniProgressBar.module.scss +44 -0
- package/src/lib/components/table/components/TableCell/BaseCell/MiniProgressBar/MiniProgressBar.stories.tsx +29 -0
- package/src/lib/components/table/components/TableCell/BaseCell/MiniProgressBar/MiniProgressBar.tsx +35 -0
- package/src/lib/components/table/components/TableCell/ButtonCell/ButtonCell.module.scss +43 -0
- package/src/lib/components/table/components/TableCell/ButtonCell/ButtonCell.stories.tsx +65 -0
- package/src/lib/components/table/components/TableCell/ButtonCell/ButtonCell.tsx +40 -0
- package/src/lib/components/table/components/TableCell/CTACell/CTACell.module.scss +3 -0
- package/src/lib/components/table/components/TableCell/CTACell/CTACell.stories.tsx +37 -0
- package/src/lib/components/table/components/TableCell/CTACell/CTACell.tsx +42 -0
- package/src/lib/components/table/components/TableCell/TableCell.module.scss +0 -43
- package/src/lib/components/table/components/TableCell/TableCell.test.tsx +26 -13
- package/src/lib/components/table/components/TableCell/TableCell.tsx +20 -122
- package/src/lib/components/table/components/TableContents/TableContents.test.tsx +6 -6
- package/src/lib/components/table/components/TableSection/TableSection.test.tsx +5 -5
- package/src/lib/components/table/components/TableSection/TableSection.tsx +67 -41
- package/src/lib/components/table/types.ts +16 -2
- package/src/lib/components/table/utils/useTableNavigation/useTableNavigation.test.tsx +0 -4
- package/src/lib/components/table/utils/useTableNavigation/useTableNavigation.ts +13 -20
- package/dist/esm/useTableNavigation-8e50b121.js.map +0 -1
|
@@ -3,7 +3,12 @@ import classNames from 'classnames';
|
|
|
3
3
|
import styles from './TableSection.module.scss';
|
|
4
4
|
import { TableCell, TableCellProps } from '../TableCell/TableCell';
|
|
5
5
|
import { ReactNode, useCallback } from 'react';
|
|
6
|
-
import {
|
|
6
|
+
import {
|
|
7
|
+
isBaseCell,
|
|
8
|
+
ModalData,
|
|
9
|
+
ModalFunction,
|
|
10
|
+
TableCellRowData,
|
|
11
|
+
} from '../../types';
|
|
7
12
|
|
|
8
13
|
export interface TableSectionProps {
|
|
9
14
|
className?: string;
|
|
@@ -24,22 +29,32 @@ const TableSection = ({
|
|
|
24
29
|
}: TableSectionProps) => {
|
|
25
30
|
const headerRow = tableCellRows?.[0];
|
|
26
31
|
|
|
27
|
-
const
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
32
|
+
const getModalTitleFromColumnHeader = (cellIndex: number) => {
|
|
33
|
+
const firstCellInColumn = tableCellRows?.[0]?.[cellIndex];
|
|
34
|
+
let titleFromColumn;
|
|
35
|
+
|
|
36
|
+
switch (firstCellInColumn.type) {
|
|
37
|
+
case 'BUTTON':
|
|
38
|
+
titleFromColumn = firstCellInColumn.buttonCaption;
|
|
39
|
+
break;
|
|
40
|
+
case 'CTA':
|
|
41
|
+
titleFromColumn = firstCellInColumn.title;
|
|
42
|
+
break;
|
|
43
|
+
case undefined:
|
|
44
|
+
titleFromColumn = firstCellInColumn.text || '';
|
|
45
|
+
break;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
return titleFromColumn;
|
|
49
|
+
};
|
|
31
50
|
|
|
32
|
-
const
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
}
|
|
39
|
-
openModal?.({
|
|
40
|
-
body,
|
|
41
|
-
title: title || getColumnContentByKey(cellIndex),
|
|
42
|
-
});
|
|
51
|
+
const getModalTitleFromRowHeader = (currentRow: TableCellRowData) => {
|
|
52
|
+
const firstCellInRow = currentRow?.[0];
|
|
53
|
+
const titleFromRow =
|
|
54
|
+
(isBaseCell(firstCellInRow) && firstCellInRow.text) || '';
|
|
55
|
+
|
|
56
|
+
return titleFromRow;
|
|
57
|
+
};
|
|
43
58
|
|
|
44
59
|
return (
|
|
45
60
|
<table
|
|
@@ -51,23 +66,28 @@ const TableSection = ({
|
|
|
51
66
|
{headerRow && (
|
|
52
67
|
<thead className={hideHeader ? 'sr-only' : ''}>
|
|
53
68
|
<tr>
|
|
54
|
-
{headerRow.map((
|
|
69
|
+
{headerRow.map((tableCellData, cellIndex) => {
|
|
55
70
|
const isFirstCellInRow = cellIndex === 0;
|
|
71
|
+
|
|
56
72
|
return (
|
|
57
73
|
<TableCell
|
|
58
74
|
key={cellIndex}
|
|
59
75
|
isHeader
|
|
60
76
|
isFirstCellInRow={isFirstCellInRow}
|
|
61
77
|
isTopLeftCell={isFirstCellInRow}
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
78
|
+
{...tableCellData}
|
|
79
|
+
{...(isBaseCell(tableCellData)
|
|
80
|
+
? {
|
|
81
|
+
openModal: (body: ReactNode) =>
|
|
82
|
+
openModal?.({
|
|
83
|
+
body,
|
|
84
|
+
title:
|
|
85
|
+
tableCellData.text ||
|
|
86
|
+
getModalTitleFromColumnHeader(cellIndex),
|
|
87
|
+
}),
|
|
88
|
+
align: isFirstCellInRow ? 'left' : 'center',
|
|
89
|
+
}
|
|
90
|
+
: {})}
|
|
71
91
|
/>
|
|
72
92
|
);
|
|
73
93
|
})}
|
|
@@ -82,28 +102,34 @@ const TableSection = ({
|
|
|
82
102
|
return (
|
|
83
103
|
rowIndex > 0 && (
|
|
84
104
|
<tr key={rowIndex} className={styles.tr}>
|
|
85
|
-
{row.map((
|
|
105
|
+
{row.map((tableCellData, cellIndex) => {
|
|
86
106
|
const key = `${rowIndex}-${cellIndex}`;
|
|
87
107
|
const isFirstCellInRow = cellIndex === 0;
|
|
88
108
|
|
|
89
|
-
const onCelInfoClick = (body: ReactNode) =>
|
|
90
|
-
handleOpenModal({
|
|
91
|
-
cellIndex,
|
|
92
|
-
body,
|
|
93
|
-
title: isFirstCellInRow
|
|
94
|
-
? tableCellProps.content
|
|
95
|
-
: undefined,
|
|
96
|
-
});
|
|
97
|
-
|
|
98
109
|
return (
|
|
99
110
|
<TableCell
|
|
100
|
-
align={
|
|
101
|
-
isFirstCellInRow && !isSingleCell ? 'left' : 'center'
|
|
102
|
-
}
|
|
103
111
|
isFirstCellInRow={isFirstCellInRow}
|
|
104
|
-
openModal={onCelInfoClick}
|
|
105
112
|
key={key}
|
|
106
|
-
{...
|
|
113
|
+
{...tableCellData}
|
|
114
|
+
{...(isBaseCell(tableCellData)
|
|
115
|
+
? {
|
|
116
|
+
openModal: (body: ReactNode) => {
|
|
117
|
+
const titleFromRow =
|
|
118
|
+
getModalTitleFromRowHeader(row);
|
|
119
|
+
const titleFromColumnOrRow =
|
|
120
|
+
getModalTitleFromColumnHeader(cellIndex) ||
|
|
121
|
+
getModalTitleFromRowHeader(row);
|
|
122
|
+
|
|
123
|
+
return openModal?.({
|
|
124
|
+
body,
|
|
125
|
+
title: isFirstCellInRow
|
|
126
|
+
? titleFromRow
|
|
127
|
+
: titleFromColumnOrRow,
|
|
128
|
+
});
|
|
129
|
+
},
|
|
130
|
+
align: isFirstCellInRow ? 'left' : 'center',
|
|
131
|
+
}
|
|
132
|
+
: {})}
|
|
107
133
|
/>
|
|
108
134
|
);
|
|
109
135
|
})}
|
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
import { ReactNode } from 'react';
|
|
2
|
-
import
|
|
2
|
+
import { BaseCellProps } from './components/TableCell/BaseCell/BaseCell';
|
|
3
|
+
import { CTACellProps } from './components/TableCell/CTACell/CTACell';
|
|
4
|
+
import { ButtonCellProps } from './components/TableCell/ButtonCell/ButtonCell';
|
|
5
|
+
|
|
6
|
+
type BaseCellData = BaseCellProps & { type?: undefined; cellId?: string };
|
|
7
|
+
type CTACellData = CTACellProps & { type: 'CTA'; cellId?: string };
|
|
8
|
+
type ButtonCellData = ButtonCellProps & { type: 'BUTTON'; cellId?: string };
|
|
9
|
+
|
|
10
|
+
export type TableCellData = BaseCellData | CTACellData | ButtonCellData;
|
|
11
|
+
|
|
12
|
+
export const isBaseCell = (
|
|
13
|
+
tableCellData: TableCellData
|
|
14
|
+
): tableCellData is BaseCellData => {
|
|
15
|
+
return !tableCellData.type;
|
|
16
|
+
};
|
|
3
17
|
|
|
4
18
|
export type TableSectionType = {
|
|
5
19
|
title?: string;
|
|
@@ -11,7 +25,7 @@ export type ModalData = {
|
|
|
11
25
|
body?: ReactNode;
|
|
12
26
|
};
|
|
13
27
|
|
|
14
|
-
export type TableCellRowData =
|
|
28
|
+
export type TableCellRowData = TableCellData[];
|
|
15
29
|
|
|
16
30
|
export type TableSectionData = {
|
|
17
31
|
section?: TableSectionType;
|
|
@@ -11,7 +11,6 @@ const defaultContainerRef = {
|
|
|
11
11
|
} as unknown as RefObject<HTMLElement>;
|
|
12
12
|
|
|
13
13
|
describe('useTableNavigation', () => {
|
|
14
|
-
const columnsLength = 4;
|
|
15
14
|
let onSelectionChanged = jest.fn();
|
|
16
15
|
let containerRef = defaultContainerRef;
|
|
17
16
|
|
|
@@ -25,7 +24,6 @@ describe('useTableNavigation', () => {
|
|
|
25
24
|
useTableNavigation({
|
|
26
25
|
enabled: false,
|
|
27
26
|
containerRef,
|
|
28
|
-
columnsLength,
|
|
29
27
|
onSelectionChanged,
|
|
30
28
|
})
|
|
31
29
|
);
|
|
@@ -44,7 +42,6 @@ describe('useTableNavigation', () => {
|
|
|
44
42
|
useTableNavigation({
|
|
45
43
|
enabled: true,
|
|
46
44
|
containerRef,
|
|
47
|
-
columnsLength,
|
|
48
45
|
onSelectionChanged,
|
|
49
46
|
})
|
|
50
47
|
);
|
|
@@ -67,7 +64,6 @@ describe('useTableNavigation', () => {
|
|
|
67
64
|
useTableNavigation({
|
|
68
65
|
enabled: true,
|
|
69
66
|
containerRef,
|
|
70
|
-
columnsLength,
|
|
71
67
|
onSelectionChanged,
|
|
72
68
|
})
|
|
73
69
|
);
|
|
@@ -8,7 +8,6 @@ interface UseTableNavigationReturn {
|
|
|
8
8
|
|
|
9
9
|
interface UseTableNavigationProps {
|
|
10
10
|
containerRef: React.RefObject<HTMLElement>,
|
|
11
|
-
columnsLength: number,
|
|
12
11
|
enabled?: boolean,
|
|
13
12
|
onSelectionChanged?: (index: number) => void
|
|
14
13
|
}
|
|
@@ -16,22 +15,18 @@ interface UseTableNavigationProps {
|
|
|
16
15
|
export const useTableNavigation = ({
|
|
17
16
|
enabled,
|
|
18
17
|
containerRef,
|
|
19
|
-
columnsLength,
|
|
20
18
|
onSelectionChanged
|
|
21
19
|
}: UseTableNavigationProps): UseTableNavigationReturn => {
|
|
22
|
-
const [activeSection, setActiveSection] = useState(
|
|
23
|
-
const [isIncrease, setIsIncrease] = useState<boolean>();
|
|
20
|
+
const [activeSection, setActiveSection] = useState(0);
|
|
24
21
|
|
|
25
22
|
const handleScrollToSection = (increase?: boolean) => {
|
|
26
23
|
if (!enabled) {
|
|
27
24
|
return;
|
|
28
25
|
}
|
|
29
26
|
|
|
30
|
-
setActiveSection((prevSection) =>
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
return prevSection + (increase ? 1 : -1);
|
|
34
|
-
});
|
|
27
|
+
setActiveSection((prevSection) =>
|
|
28
|
+
prevSection + (increase ? 1 : -1)
|
|
29
|
+
);
|
|
35
30
|
};
|
|
36
31
|
|
|
37
32
|
const handleTableScroll = useCallback(() => {
|
|
@@ -39,14 +34,12 @@ export const useTableNavigation = ({
|
|
|
39
34
|
return;
|
|
40
35
|
}
|
|
41
36
|
|
|
42
|
-
const scrollLeft = containerRef.current.scrollLeft;
|
|
43
37
|
const containerWidth = containerRef.current.getBoundingClientRect().width;
|
|
44
|
-
const
|
|
45
|
-
const
|
|
38
|
+
const scrollLeft = containerRef.current.scrollLeft;
|
|
39
|
+
const cellWidth = containerWidth / 2;
|
|
46
40
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
}, [activeSection, columnsLength, containerRef, enabled]);
|
|
41
|
+
setActiveSection(Math.floor(scrollLeft / cellWidth));
|
|
42
|
+
}, [activeSection, containerRef, enabled]);
|
|
50
43
|
|
|
51
44
|
const debouncedTableScroll = debounce(handleTableScroll, 150);
|
|
52
45
|
|
|
@@ -61,26 +54,26 @@ export const useTableNavigation = ({
|
|
|
61
54
|
}, [enabled]);
|
|
62
55
|
|
|
63
56
|
useEffect(() => {
|
|
64
|
-
if (!enabled
|
|
57
|
+
if (!enabled) {
|
|
65
58
|
return
|
|
66
59
|
}
|
|
67
60
|
|
|
68
|
-
onSelectionChanged?.(activeSection);
|
|
61
|
+
onSelectionChanged?.(activeSection + 1);
|
|
69
62
|
|
|
70
63
|
if (containerRef.current) {
|
|
71
64
|
const containerWidth = containerRef.current.getBoundingClientRect().width;
|
|
72
|
-
const cellWidth = containerWidth /
|
|
65
|
+
const cellWidth = containerWidth / 2;
|
|
73
66
|
|
|
74
67
|
containerRef.current.scroll({
|
|
75
68
|
top: 0,
|
|
76
|
-
left:
|
|
69
|
+
left: cellWidth * activeSection,
|
|
77
70
|
behavior: 'smooth',
|
|
78
71
|
});
|
|
79
72
|
}
|
|
80
73
|
}, [enabled, activeSection]);
|
|
81
74
|
|
|
82
75
|
return {
|
|
83
|
-
activeSection,
|
|
76
|
+
activeSection: activeSection + 1,
|
|
84
77
|
navigateTable: handleScrollToSection,
|
|
85
78
|
}
|
|
86
79
|
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useTableNavigation-8e50b121.js","sources":["../../../src/lib/components/table/utils/useTableNavigation/useTableNavigation.ts"],"sourcesContent":["import debounce from \"lodash.debounce\";\nimport { useCallback, useEffect, useState } from \"react\";\n\ninterface UseTableNavigationReturn {\n activeSection: number;\n navigateTable: (increase?: boolean) => void;\n}\n\ninterface UseTableNavigationProps {\n containerRef: React.RefObject<HTMLElement>,\n columnsLength: number,\n enabled?: boolean,\n onSelectionChanged?: (index: number) => void\n}\n\nexport const useTableNavigation = ({\n enabled,\n containerRef,\n columnsLength,\n onSelectionChanged\n}: UseTableNavigationProps): UseTableNavigationReturn => {\n const [activeSection, setActiveSection] = useState(1);\n const [isIncrease, setIsIncrease] = useState<boolean>();\n\n const handleScrollToSection = (increase?: boolean) => {\n if (!enabled) {\n return;\n }\n\n setActiveSection((prevSection) => {\n setIsIncrease(!!increase);\n\n return prevSection + (increase ? 1 : -1);\n });\n };\n\n const handleTableScroll = useCallback(() => {\n if (!containerRef.current || !enabled) {\n return;\n }\n\n const scrollLeft = containerRef.current.scrollLeft;\n const containerWidth = containerRef.current.getBoundingClientRect().width;\n const cellWidth = containerWidth / (columnsLength - 1);\n const newValue = Math.floor(scrollLeft / cellWidth * 0.8) + 1;\n\n setIsIncrease(newValue > activeSection);\n setActiveSection(newValue);\n }, [activeSection, columnsLength, containerRef, enabled]);\n\n const debouncedTableScroll = debounce(handleTableScroll, 150);\n\n useEffect(() => {\n const container = containerRef.current;\n\n container?.addEventListener('scroll', debouncedTableScroll, {\n passive: true,\n });\n\n return container?.removeEventListener('scroll', handleTableScroll);\n }, [enabled]);\n\n useEffect(() => {\n if (!enabled || typeof isIncrease === 'undefined') {\n return\n }\n\n onSelectionChanged?.(activeSection);\n\n if (containerRef.current) {\n const containerWidth = containerRef.current.getBoundingClientRect().width;\n const cellWidth = containerWidth / columnsLength;\n\n containerRef.current.scroll({\n top: 0,\n left: (cellWidth * activeSection) * (isIncrease ? 1.2 : 0.8),\n behavior: 'smooth',\n });\n }\n }, [enabled, activeSection]);\n\n return {\n activeSection,\n navigateTable: handleScrollToSection,\n }\n}"],"names":["debounce"],"mappings":";;;IAea,kBAAkB,GAAG,UAAC,EAKT;QAJxB,OAAO,aAAA,EACP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