@popsure/dirty-swan 0.54.2 → 0.54.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/cjs/index.js +329 -239
- 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 +9 -0
- package/dist/cjs/lib/components/table/components/TableCell/CTACell/CTACell.stories.d.ts +17 -0
- package/dist/cjs/lib/components/table/components/TableCell/TableCell.d.ts +5 -17
- package/dist/cjs/lib/components/table/types.d.ts +11 -2
- package/dist/cjs/lib/components/table/utils/useTableNavigation/useTableNavigation.d.ts +1 -2
- 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 +26 -12
- package/dist/esm/components/table/Table.js.map +1 -1
- package/dist/esm/components/table/Table.stories.js +54 -12
- package/dist/esm/components/table/Table.stories.js.map +1 -1
- package/dist/esm/components/table/Table.test.js +12 -6
- 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 +25 -0
- package/dist/esm/components/table/components/TableCell/CTACell/CTACell.stories.js.map +1 -0
- package/dist/esm/components/table/components/TableCell/TableCell.js +21 -20
- package/dist/esm/components/table/components/TableCell/TableCell.js.map +1 -1
- package/dist/esm/components/table/components/TableCell/TableCell.test.js +28 -14
- package/dist/esm/components/table/components/TableCell/TableCell.test.js.map +1 -1
- package/dist/esm/components/table/components/TableContents/TableContents.js +10 -2
- package/dist/esm/components/table/components/TableContents/TableContents.js.map +1 -1
- package/dist/esm/components/table/components/TableContents/TableContents.test.js +9 -2
- package/dist/esm/components/table/components/TableContents/TableContents.test.js.map +1 -1
- package/dist/esm/components/table/components/TableSection/TableSection.js +39 -7
- package/dist/esm/components/table/components/TableSection/TableSection.js.map +1 -1
- package/dist/esm/components/table/components/TableSection/TableSection.test.js +9 -2
- 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 +6 -1
- 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 +9 -0
- package/dist/esm/lib/components/table/components/TableCell/CTACell/CTACell.stories.d.ts +17 -0
- package/dist/esm/lib/components/table/components/TableCell/TableCell.d.ts +5 -17
- package/dist/esm/lib/components/table/types.d.ts +11 -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 +41 -5
- package/src/lib/components/table/Table.test.tsx +1 -1
- package/src/lib/components/table/Table.tsx +17 -8
- 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 +160 -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 +34 -0
- package/src/lib/components/table/components/TableCell/CTACell/CTACell.tsx +40 -0
- package/src/lib/components/table/components/TableCell/TableCell.module.scss +0 -43
- package/src/lib/components/table/components/TableCell/TableCell.test.tsx +25 -13
- package/src/lib/components/table/components/TableCell/TableCell.tsx +16 -122
- package/src/lib/components/table/components/TableContents/TableContents.test.tsx +2 -2
- package/src/lib/components/table/components/TableSection/TableSection.test.tsx +3 -3
- package/src/lib/components/table/components/TableSection/TableSection.tsx +40 -13
- package/src/lib/components/table/types.ts +9 -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
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import classNames from 'classnames';
|
|
2
|
+
import { ReactNode } from 'react';
|
|
3
|
+
|
|
4
|
+
export type CTACellProps = {
|
|
5
|
+
content?: ReactNode;
|
|
6
|
+
subContent?: ReactNode;
|
|
7
|
+
grey?: boolean;
|
|
8
|
+
narrow?: boolean;
|
|
9
|
+
href: string;
|
|
10
|
+
};
|
|
11
|
+
import styles from './CTACell.module.scss';
|
|
12
|
+
|
|
13
|
+
export const CTACell = ({
|
|
14
|
+
content,
|
|
15
|
+
subContent,
|
|
16
|
+
grey,
|
|
17
|
+
narrow,
|
|
18
|
+
href,
|
|
19
|
+
}: CTACellProps) => {
|
|
20
|
+
return (
|
|
21
|
+
<div className="wmn3 ta-center">
|
|
22
|
+
<p className="p-h3">
|
|
23
|
+
{content}
|
|
24
|
+
{subContent && <span className="tc-purple-500"> {subContent}</span>}
|
|
25
|
+
</p>
|
|
26
|
+
<a
|
|
27
|
+
className={classNames('mt16', {
|
|
28
|
+
'p-btn--primary': !grey,
|
|
29
|
+
'p-btn--secondary-grey': grey,
|
|
30
|
+
[styles.narrow]: narrow,
|
|
31
|
+
})}
|
|
32
|
+
href={href}
|
|
33
|
+
target="_blank"
|
|
34
|
+
rel="noopener noreferrer"
|
|
35
|
+
>
|
|
36
|
+
Get covered
|
|
37
|
+
</a>
|
|
38
|
+
</div>
|
|
39
|
+
);
|
|
40
|
+
};
|
|
@@ -1,17 +1,6 @@
|
|
|
1
1
|
@use '../../../../scss/public/colors' as *;
|
|
2
2
|
@use '../../../../scss/public/grid' as *;
|
|
3
3
|
|
|
4
|
-
.button {
|
|
5
|
-
min-height: initial;
|
|
6
|
-
height: initial;
|
|
7
|
-
width: initial;
|
|
8
|
-
padding: 0;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
.icon {
|
|
12
|
-
margin: 2px;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
4
|
.th {
|
|
16
5
|
vertical-align: middle;
|
|
17
6
|
scroll-snap-align: end;
|
|
@@ -23,15 +12,6 @@
|
|
|
23
12
|
}
|
|
24
13
|
}
|
|
25
14
|
|
|
26
|
-
.thRow {
|
|
27
|
-
position: sticky;
|
|
28
|
-
top: 0;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
.thCol {
|
|
32
|
-
text-align: left;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
15
|
.fixedCell {
|
|
36
16
|
position: sticky;
|
|
37
17
|
left: 0;
|
|
@@ -47,26 +27,3 @@
|
|
|
47
27
|
background-color: $ds-grey-200;
|
|
48
28
|
}
|
|
49
29
|
}
|
|
50
|
-
|
|
51
|
-
.topLeftCell {
|
|
52
|
-
position: relative;
|
|
53
|
-
display: none;
|
|
54
|
-
|
|
55
|
-
&:after {
|
|
56
|
-
content: '';
|
|
57
|
-
display: block;
|
|
58
|
-
position: absolute;
|
|
59
|
-
top: calc(
|
|
60
|
-
50% + 16px
|
|
61
|
-
); // Display bottom border at the same distance regardless of cell height
|
|
62
|
-
|
|
63
|
-
height: 4px;
|
|
64
|
-
width: 100%;
|
|
65
|
-
max-width: 140px;
|
|
66
|
-
background-color: $ds-primary-500;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
@include p-size-tablet {
|
|
70
|
-
display: flex;
|
|
71
|
-
}
|
|
72
|
-
}
|
|
@@ -1,25 +1,39 @@
|
|
|
1
1
|
import { render, screen } from '../../../../util/testUtils';
|
|
2
|
-
import { TableCell } from './TableCell';
|
|
2
|
+
import { TableCell, TableCellProps } from './TableCell';
|
|
3
3
|
|
|
4
4
|
const openModal = jest.fn();
|
|
5
5
|
|
|
6
|
+
const setup = ({ isNavigation, ...rest }: TableCellProps = {}) => render(
|
|
7
|
+
isNavigation
|
|
8
|
+
? <TableCell {...rest} isNavigation />
|
|
9
|
+
: (
|
|
10
|
+
<table>
|
|
11
|
+
<tbody>
|
|
12
|
+
<tr>
|
|
13
|
+
<TableCell {...rest} />
|
|
14
|
+
</tr>
|
|
15
|
+
</tbody>
|
|
16
|
+
</table>
|
|
17
|
+
)
|
|
18
|
+
);
|
|
19
|
+
|
|
6
20
|
describe('TableCell', () => {
|
|
7
21
|
it('renders the component with boolean true', () => {
|
|
8
|
-
|
|
22
|
+
setup({ checkmarkValue: true });
|
|
9
23
|
|
|
10
24
|
expect(screen.getByTitle('Yes')).toBeInTheDocument();
|
|
11
25
|
expect(screen.getByTestId('table-cell-boolean-yes')).toBeInTheDocument();
|
|
12
26
|
});
|
|
13
27
|
|
|
14
28
|
it('renders the component with boolean false', () => {
|
|
15
|
-
|
|
29
|
+
setup({ checkmarkValue: false });
|
|
16
30
|
|
|
17
31
|
expect(screen.getByTitle('No')).toBeInTheDocument();
|
|
18
32
|
expect(screen.getByTestId('table-cell-boolean-no')).toBeInTheDocument();
|
|
19
33
|
});
|
|
20
34
|
|
|
21
35
|
it('renders the component without boolean', () => {
|
|
22
|
-
|
|
36
|
+
setup();
|
|
23
37
|
|
|
24
38
|
expect(screen.queryByTitle('Yes')).not.toBeInTheDocument();
|
|
25
39
|
expect(screen.queryByTitle('No')).not.toBeInTheDocument();
|
|
@@ -32,42 +46,40 @@ describe('TableCell', () => {
|
|
|
32
46
|
});
|
|
33
47
|
|
|
34
48
|
it('renders the component with rating', () => {
|
|
35
|
-
|
|
49
|
+
setup({ rating: { type: 'star', value: 2 } });
|
|
36
50
|
|
|
37
51
|
expect(screen.getByTitle('2 out of 3')).toBeInTheDocument();
|
|
38
52
|
});
|
|
39
53
|
|
|
40
54
|
it('renders the component without rating', () => {
|
|
41
|
-
|
|
55
|
+
setup();
|
|
42
56
|
|
|
43
57
|
expect(screen.queryByTestId('table-cell-rating')).not.toBeInTheDocument();
|
|
44
58
|
});
|
|
45
59
|
|
|
46
60
|
it('renders the component with text', () => {
|
|
47
|
-
|
|
61
|
+
setup({ content: "Sample text" });
|
|
48
62
|
|
|
49
63
|
expect(screen.getByText('Sample text')).toBeInTheDocument();
|
|
50
64
|
});
|
|
51
65
|
|
|
52
66
|
it('renders the component without text', () => {
|
|
53
|
-
|
|
67
|
+
setup();
|
|
54
68
|
|
|
55
69
|
expect(screen.queryByTestId('table-cell-text')).not.toBeInTheDocument();
|
|
56
70
|
});
|
|
57
71
|
|
|
58
72
|
it('renders the component without info', () => {
|
|
59
|
-
|
|
73
|
+
setup();
|
|
60
74
|
|
|
61
75
|
expect(screen.queryByText('View more info')).not.toBeInTheDocument();
|
|
62
76
|
});
|
|
63
77
|
|
|
64
78
|
it('calls openModal when info button is clicked', () => {
|
|
65
|
-
|
|
66
|
-
<TableCell modalContent="Additional information" openModal={openModal} />
|
|
67
|
-
);
|
|
79
|
+
setup({ modalContent: "Additional information", openModal });
|
|
68
80
|
|
|
69
81
|
// Click info button
|
|
70
|
-
screen.
|
|
82
|
+
screen.getByTestId('ds-table-info-button').click();
|
|
71
83
|
|
|
72
84
|
// Assert openModal is called with info prop
|
|
73
85
|
expect(openModal).toHaveBeenCalledWith('Additional information');
|
|
@@ -1,50 +1,26 @@
|
|
|
1
|
-
import { ReactNode } from 'react';
|
|
2
|
-
import { Button } from '../../../button';
|
|
3
|
-
import {
|
|
4
|
-
CheckIcon,
|
|
5
|
-
InfoIcon,
|
|
6
|
-
StarFilledIcon,
|
|
7
|
-
XIcon,
|
|
8
|
-
ZapFilledIcon,
|
|
9
|
-
} from '../../../icon';
|
|
10
1
|
import classNames from 'classnames';
|
|
11
2
|
|
|
12
3
|
import styles from './TableCell.module.scss';
|
|
4
|
+
import { BaseCell, BaseCellProps } from './BaseCell/BaseCell';
|
|
5
|
+
import { TableCellData } from '../../types';
|
|
6
|
+
import { CTACell } from './CTACell/CTACell';
|
|
7
|
+
import { ButtonCell } from './ButtonCell/ButtonCell';
|
|
13
8
|
|
|
14
|
-
|
|
15
|
-
align?: 'center' | 'left' | 'right';
|
|
16
|
-
checkmarkValue?: boolean;
|
|
17
|
-
content?: ReactNode;
|
|
18
|
-
modalContent?: ReactNode;
|
|
19
|
-
openModal?: (modalContent: ReactNode) => void;
|
|
20
|
-
subContent?: ReactNode;
|
|
21
|
-
rating?: {
|
|
22
|
-
value: number;
|
|
23
|
-
type: 'zap' | 'star';
|
|
24
|
-
};
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
interface PositionalTableCellProps {
|
|
9
|
+
type PositionalTableCellProps = {
|
|
28
10
|
isHeader?: boolean;
|
|
29
11
|
isFirstCellInRow?: boolean;
|
|
30
12
|
isTopLeftCell?: boolean;
|
|
31
13
|
isNavigation?: boolean;
|
|
32
|
-
}
|
|
14
|
+
};
|
|
33
15
|
|
|
34
|
-
export type TableCellProps =
|
|
16
|
+
export type TableCellProps = TableCellData & PositionalTableCellProps;
|
|
35
17
|
|
|
36
18
|
const TableCell = ({
|
|
37
|
-
align = 'center',
|
|
38
|
-
checkmarkValue,
|
|
39
|
-
content = '',
|
|
40
19
|
isFirstCellInRow = false,
|
|
41
20
|
isHeader = false,
|
|
42
21
|
isNavigation = false,
|
|
43
22
|
isTopLeftCell = false,
|
|
44
|
-
|
|
45
|
-
openModal,
|
|
46
|
-
rating,
|
|
47
|
-
subContent = '',
|
|
23
|
+
...cellProps
|
|
48
24
|
}: TableCellProps) => {
|
|
49
25
|
// prettier-ignore
|
|
50
26
|
const Tag = isNavigation
|
|
@@ -60,15 +36,6 @@ const TableCell = ({
|
|
|
60
36
|
scope: thScope,
|
|
61
37
|
};
|
|
62
38
|
|
|
63
|
-
const alignClassName = {
|
|
64
|
-
center: 'ta-center jc-center',
|
|
65
|
-
left: 'ta-left jc-start',
|
|
66
|
-
right: 'ta-right',
|
|
67
|
-
}[align];
|
|
68
|
-
|
|
69
|
-
const validRatingValues: number[] = [1, 2, 3];
|
|
70
|
-
const SelectedIcon = rating?.type === 'zap' ? ZapFilledIcon : StarFilledIcon;
|
|
71
|
-
|
|
72
39
|
return (
|
|
73
40
|
<Tag
|
|
74
41
|
{...scope}
|
|
@@ -78,87 +45,14 @@ const TableCell = ({
|
|
|
78
45
|
pl32: isFirstCellInRow,
|
|
79
46
|
})}
|
|
80
47
|
>
|
|
81
|
-
|
|
82
|
-
<
|
|
83
|
-
{
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
<SelectedIcon
|
|
90
|
-
aria-hidden="true"
|
|
91
|
-
key={value}
|
|
92
|
-
color={value <= rating?.value ? 'primary-500' : 'grey-400'}
|
|
93
|
-
className={styles.icon}
|
|
94
|
-
/>
|
|
95
|
-
))}
|
|
96
|
-
</span>
|
|
97
|
-
)}
|
|
98
|
-
|
|
99
|
-
{checkmarkValue !== undefined && (
|
|
100
|
-
<span title={checkmarkValue ? 'Yes' : 'No'}>
|
|
101
|
-
{checkmarkValue ? (
|
|
102
|
-
<CheckIcon
|
|
103
|
-
data-testid="table-cell-boolean-yes"
|
|
104
|
-
size={24}
|
|
105
|
-
aria-hidden
|
|
106
|
-
color="primary-500"
|
|
107
|
-
/>
|
|
108
|
-
) : (
|
|
109
|
-
<XIcon
|
|
110
|
-
data-testid="table-cell-boolean-no"
|
|
111
|
-
size={24}
|
|
112
|
-
aria-hidden
|
|
113
|
-
color="grey-400"
|
|
114
|
-
/>
|
|
115
|
-
)}
|
|
116
|
-
</span>
|
|
117
|
-
)}
|
|
118
|
-
|
|
119
|
-
{content && !isTopLeftCell && (
|
|
120
|
-
<div className="p-p" data-testid="table-cell-content">
|
|
121
|
-
{content}
|
|
122
|
-
</div>
|
|
123
|
-
)}
|
|
124
|
-
|
|
125
|
-
{content && isTopLeftCell && (
|
|
126
|
-
<div
|
|
127
|
-
aria-hidden
|
|
128
|
-
className={classNames(
|
|
129
|
-
'tc-grey-800 p-h2 p--serif',
|
|
130
|
-
styles.topLeftCell
|
|
131
|
-
)}
|
|
132
|
-
>
|
|
133
|
-
{content}
|
|
134
|
-
</div>
|
|
135
|
-
)}
|
|
136
|
-
|
|
137
|
-
{modalContent && openModal && (
|
|
138
|
-
<Button
|
|
139
|
-
className={styles.button}
|
|
140
|
-
hideLabel
|
|
141
|
-
leftIcon={<InfoIcon size={20} />}
|
|
142
|
-
onClick={() => openModal(modalContent)}
|
|
143
|
-
type="button"
|
|
144
|
-
variant="textColor"
|
|
145
|
-
>
|
|
146
|
-
View more info
|
|
147
|
-
</Button>
|
|
148
|
-
)}
|
|
149
|
-
</div>
|
|
150
|
-
|
|
151
|
-
{subContent && (
|
|
152
|
-
<div
|
|
153
|
-
className={classNames(
|
|
154
|
-
'd-flex p-p--small tc-grey-500',
|
|
155
|
-
alignClassName
|
|
156
|
-
)}
|
|
157
|
-
>
|
|
158
|
-
{subContent}
|
|
159
|
-
</div>
|
|
160
|
-
)}
|
|
161
|
-
</div>
|
|
48
|
+
{!cellProps.type && (
|
|
49
|
+
<BaseCell
|
|
50
|
+
{...cellProps}
|
|
51
|
+
contentFontVariant={isTopLeftCell ? 'BIG_WITH_UNDERLINE' : 'NORMAL'}
|
|
52
|
+
/>
|
|
53
|
+
)}
|
|
54
|
+
{cellProps.type === 'CTA' && <CTACell {...cellProps} />}
|
|
55
|
+
{cellProps.type === 'BUTTON' && <ButtonCell {...cellProps} />}
|
|
162
56
|
</Tag>
|
|
163
57
|
);
|
|
164
58
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { render, screen } from '../../../../util/testUtils';
|
|
2
|
-
import { TableContents,
|
|
2
|
+
import { TableContents, TableContentsProps } from './TableContents';
|
|
3
3
|
|
|
4
|
-
const mockData:
|
|
4
|
+
const mockData: TableContentsProps['tableData'] = [
|
|
5
5
|
{
|
|
6
6
|
rows: [
|
|
7
7
|
[{ content: 'Item 1.1.1' }, { content: 'Item 1.1.2' }],
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { render, screen } from '../../../../util/testUtils';
|
|
2
|
-
import { TableSection,
|
|
2
|
+
import { TableSection, TableSectionProps } from './TableSection';
|
|
3
3
|
|
|
4
|
-
const tableCellRows:
|
|
4
|
+
const tableCellRows: TableSectionProps['tableCellRows'] = [
|
|
5
5
|
[{ content: 'Cell 1.1' }, { content: 'Cell 1.2' }, { content: 'Cell 1.3' }],
|
|
6
6
|
[{ content: 'Cell 2.1' }, { content: 'Cell 2.2' }, { content: 'Cell 2.3' }],
|
|
7
7
|
];
|
|
@@ -10,7 +10,7 @@ const mockTitle = 'Test Table';
|
|
|
10
10
|
|
|
11
11
|
const mockOpenModal = jest.fn();
|
|
12
12
|
|
|
13
|
-
const defaultProps:
|
|
13
|
+
const defaultProps: TableSectionProps = {
|
|
14
14
|
tableCellRows,
|
|
15
15
|
title: mockTitle,
|
|
16
16
|
openModal: mockOpenModal,
|
|
@@ -2,8 +2,9 @@ import classNames from 'classnames';
|
|
|
2
2
|
|
|
3
3
|
import styles from './TableSection.module.scss';
|
|
4
4
|
import { TableCell, TableCellProps } from '../TableCell/TableCell';
|
|
5
|
-
import { ReactNode, useCallback } from 'react';
|
|
5
|
+
import React, { ReactNode, useCallback } from 'react';
|
|
6
6
|
import { ModalData, ModalFunction, TableCellRowData } from '../../types';
|
|
7
|
+
import { Alignment } from '../TableCell/BaseCell/BaseCell';
|
|
7
8
|
|
|
8
9
|
export interface TableSectionProps {
|
|
9
10
|
className?: string;
|
|
@@ -53,21 +54,35 @@ const TableSection = ({
|
|
|
53
54
|
<tr>
|
|
54
55
|
{headerRow.map((tableCellProps, cellIndex) => {
|
|
55
56
|
const isFirstCellInRow = cellIndex === 0;
|
|
57
|
+
|
|
58
|
+
const isBaseCell = !tableCellProps.type;
|
|
59
|
+
|
|
60
|
+
let openModal;
|
|
61
|
+
let align: Alignment = 'left';
|
|
62
|
+
|
|
63
|
+
if (isBaseCell) {
|
|
64
|
+
openModal = (body: ReactNode) =>
|
|
65
|
+
handleOpenModal({
|
|
66
|
+
cellIndex,
|
|
67
|
+
body,
|
|
68
|
+
title: tableCellProps?.content,
|
|
69
|
+
});
|
|
70
|
+
align = isFirstCellInRow ? 'left' : 'center';
|
|
71
|
+
}
|
|
72
|
+
|
|
56
73
|
return (
|
|
57
74
|
<TableCell
|
|
58
75
|
key={cellIndex}
|
|
59
76
|
isHeader
|
|
60
77
|
isFirstCellInRow={isFirstCellInRow}
|
|
61
78
|
isTopLeftCell={isFirstCellInRow}
|
|
62
|
-
align={isFirstCellInRow ? 'left' : 'center'}
|
|
63
|
-
openModal={(body) =>
|
|
64
|
-
handleOpenModal({
|
|
65
|
-
cellIndex,
|
|
66
|
-
body,
|
|
67
|
-
title: tableCellProps?.content,
|
|
68
|
-
})
|
|
69
|
-
}
|
|
70
79
|
{...tableCellProps}
|
|
80
|
+
{...(isBaseCell
|
|
81
|
+
? {
|
|
82
|
+
openModal,
|
|
83
|
+
align,
|
|
84
|
+
}
|
|
85
|
+
: {})}
|
|
71
86
|
/>
|
|
72
87
|
);
|
|
73
88
|
})}
|
|
@@ -95,13 +110,25 @@ const TableSection = ({
|
|
|
95
110
|
: undefined,
|
|
96
111
|
});
|
|
97
112
|
|
|
113
|
+
let openModal;
|
|
114
|
+
let align: Alignment = 'left';
|
|
115
|
+
|
|
116
|
+
const isBaseCell = !tableCellProps.type;
|
|
117
|
+
|
|
118
|
+
if (isBaseCell) {
|
|
119
|
+
openModal = onCelInfoClick;
|
|
120
|
+
align = isFirstCellInRow ? 'left' : 'center';
|
|
121
|
+
}
|
|
122
|
+
|
|
98
123
|
return (
|
|
99
124
|
<TableCell
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
125
|
+
{...(isBaseCell
|
|
126
|
+
? {
|
|
127
|
+
openModal,
|
|
128
|
+
align,
|
|
129
|
+
}
|
|
130
|
+
: {})}
|
|
103
131
|
isFirstCellInRow={isFirstCellInRow}
|
|
104
|
-
openModal={onCelInfoClick}
|
|
105
132
|
key={key}
|
|
106
133
|
{...tableCellProps}
|
|
107
134
|
/>
|
|
@@ -1,5 +1,12 @@
|
|
|
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
|
+
export type TableCellData =
|
|
7
|
+
| (BaseCellProps & { type?: undefined })
|
|
8
|
+
| (CTACellProps & { type: 'CTA' })
|
|
9
|
+
| (ButtonCellProps & { type: 'BUTTON' });
|
|
3
10
|
|
|
4
11
|
export type TableSectionType = {
|
|
5
12
|
title?: string;
|
|
@@ -11,7 +18,7 @@ export type ModalData = {
|
|
|
11
18
|
body?: ReactNode;
|
|
12
19
|
};
|
|
13
20
|
|
|
14
|
-
export type TableCellRowData =
|
|
21
|
+
export type TableCellRowData = TableCellData[];
|
|
15
22
|
|
|
16
23
|
export type TableSectionData = {
|
|
17
24
|
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,YAAY,kBAAA,EACZ,aAAa,mBAAA,EACb,kBAAkB,wBAAA;IAEZ,IAAA,KAAoC,QAAQ,CAAC,CAAC,CAAC,EAA9C,aAAa,QAAA,EAAE,gBAAgB,QAAe,CAAC;IAChD,IAAA,KAA8B,QAAQ,EAAW,EAAhD,UAAU,QAAA,EAAE,aAAa,QAAuB,CAAC;IAExD,IAAM,qBAAqB,GAAG,UAAC,QAAkB;QAC/C,IAAI,CAAC,OAAO,EAAE;YACZ,OAAO;SACR;QAED,gBAAgB,CAAC,UAAC,WAAW;YAC3B,aAAa,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC;YAE1B,OAAO,WAAW,IAAI,QAAQ,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;SAC1C,CAAC,CAAC;KACJ,CAAC;IAEF,IAAM,iBAAiB,GAAG,WAAW,CAAC;QACpC,IAAI,CAAC,YAAY,CAAC,OAAO,IAAI,CAAC,OAAO,EAAE;YACrC,OAAO;SACR;QAED,IAAM,UAAU,GAAG,YAAY,CAAC,OAAO,CAAC,UAAU,CAAC;QACnD,IAAM,cAAc,GAAG,YAAY,CAAC,OAAO,CAAC,qBAAqB,EAAE,CAAC,KAAK,CAAC;QAC1E,IAAM,SAAS,GAAG,cAAc,IAAI,aAAa,GAAI,CAAC,CAAC,CAAC;QACxD,IAAM,QAAQ,GAAG,IAAI,CAAC,KAAK,CAAC,UAAU,GAAG,SAAS,GAAG,GAAG,CAAC,GAAG,CAAC,CAAC;QAE9D,aAAa,CAAC,QAAQ,GAAG,aAAa,CAAC,CAAC;QACxC,gBAAgB,CAAC,QAAQ,CAAC,CAAC;KAC3B,EAAE,CAAC,aAAa,EAAE,aAAa,EAAE,YAAY,EAAE,OAAO,CAAC,CAAC,CAAC;IAE3D,IAAM,oBAAoB,GAAGA,eAAQ,CAAC,iBAAiB,EAAE,GAAG,CAAC,CAAC;IAE9D,SAAS,CAAC;QACR,IAAM,SAAS,GAAG,YAAY,CAAC,OAAO,CAAC;QAEvC,SAAS,aAAT,SAAS,uBAAT,SAAS,CAAE,gBAAgB,CAAC,QAAQ,EAAE,oBAAoB,EAAE;YAC1D,OAAO,EAAE,IAAI;SACd,CAAC,CAAC;QAEH,OAAO,SAAS,aAAT,SAAS,uBAAT,SAAS,CAAE,mBAAmB,CAAC,QAAQ,EAAE,iBAAiB,CAAC,CAAC;KACpE,EAAE,CAAC,OAAO,CAAC,CAAC,CAAC;IAEd,SAAS,CAAC;QACR,IAAI,CAAC,OAAO,IAAI,OAAO,UAAU,KAAK,WAAW,EAAE;YACjD,OAAM;SACP;QAED,kBAAkB,aAAlB,kBAAkB,uBAAlB,kBAAkB,CAAG,aAAa,CAAC,CAAC;QAEpC,IAAI,YAAY,CAAC,OAAO,EAAE;YACxB,IAAM,cAAc,GAAG,YAAY,CAAC,OAAO,CAAC,qBAAqB,EAAE,CAAC,KAAK,CAAC;YAC1E,IAAM,SAAS,GAAG,cAAc,GAAG,aAAa,CAAC;YAEjD,YAAY,CAAC,OAAO,CAAC,MAAM,CAAC;gBAC1B,GAAG,EAAE,CAAC;gBACN,IAAI,EAAE,CAAC,SAAS,GAAG,aAAa,KAAK,UAAU,GAAG,GAAG,GAAG,GAAG,CAAC;gBAC5D,QAAQ,EAAE,QAAQ;aACnB,CAAC,CAAC;SACJ;KACF,EAAE,CAAC,OAAO,EAAE,aAAa,CAAC,CAAC,CAAC;IAE7B,OAAO;QACL,aAAa,eAAA;QACb,aAAa,EAAE,qBAAqB;KACrC,CAAA;AACH;;;;"}
|