@popsure/dirty-swan 0.54.1 → 0.54.2
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 +21 -21
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/lib/components/table/Table.d.ts +3 -4
- package/dist/cjs/lib/components/table/Table.stories.d.ts +5 -4
- package/dist/cjs/lib/components/table/components/TableContents/TableContents.d.ts +13 -0
- package/dist/cjs/lib/components/table/components/TableSection/TableSection.d.ts +6 -17
- package/dist/cjs/lib/components/table/types.d.ts +6 -4
- package/dist/esm/{Collapsible-ac67187a.js → Collapsible-a355828b.js} +1 -1
- package/dist/esm/Collapsible-a355828b.js.map +1 -0
- package/dist/esm/components/table/Table.js +7 -7
- package/dist/esm/components/table/Table.js.map +1 -1
- package/dist/esm/components/table/Table.stories.js +9 -9
- package/dist/esm/components/table/Table.stories.js.map +1 -1
- package/dist/esm/components/table/Table.test.js +13 -13
- package/dist/esm/components/table/Table.test.js.map +1 -1
- package/dist/esm/components/table/components/TableCell/TableCell.js +1 -1
- package/dist/esm/components/table/components/{TableSection → TableContents}/Collapsible.js +1 -1
- package/dist/esm/components/table/components/TableContents/TableContents.js +56 -0
- package/dist/esm/components/table/components/TableContents/TableContents.js.map +1 -0
- package/dist/esm/components/table/components/TableContents/TableContents.test.js +82 -0
- package/dist/esm/components/table/components/TableContents/TableContents.test.js.map +1 -0
- package/dist/esm/components/table/components/TableControls/TableControls.js +1 -1
- package/dist/esm/components/table/components/TableSection/TableSection.js +41 -38
- package/dist/esm/components/table/components/TableSection/TableSection.js.map +1 -1
- package/dist/esm/components/table/components/TableSection/TableSection.test.js +34 -56
- package/dist/esm/components/table/components/TableSection/TableSection.test.js.map +1 -1
- package/dist/esm/index.js +2 -2
- package/dist/esm/lib/components/table/Table.d.ts +3 -4
- package/dist/esm/lib/components/table/Table.stories.d.ts +5 -4
- package/dist/esm/lib/components/table/components/TableContents/TableContents.d.ts +13 -0
- package/dist/esm/lib/components/table/components/TableSection/TableSection.d.ts +6 -17
- package/dist/esm/lib/components/table/types.d.ts +6 -4
- package/package.json +1 -1
- package/src/lib/components/table/Table.stories.tsx +13 -13
- package/src/lib/components/table/Table.test.tsx +11 -11
- package/src/lib/components/table/Table.tsx +11 -13
- package/src/lib/components/table/components/TableCell/TableCell.module.scss +1 -0
- package/src/lib/components/table/components/TableContents/TableContents.module.scss +10 -0
- package/src/lib/components/table/components/TableContents/TableContents.test.tsx +86 -0
- package/src/lib/components/table/components/TableContents/TableContents.tsx +106 -0
- package/src/lib/components/table/components/TableControls/TableControls.module.scss +2 -1
- package/src/lib/components/table/components/TableSection/TableSection.module.scss +13 -8
- package/src/lib/components/table/components/TableSection/TableSection.test.tsx +38 -64
- package/src/lib/components/table/components/TableSection/TableSection.tsx +97 -94
- package/src/lib/components/table/types.ts +8 -4
- package/dist/cjs/lib/components/table/components/TableContent/TableContent.d.ts +0 -13
- package/dist/esm/Collapsible-ac67187a.js.map +0 -1
- package/dist/esm/components/table/components/TableContent/TableContent.js +0 -59
- package/dist/esm/components/table/components/TableContent/TableContent.js.map +0 -1
- package/dist/esm/components/table/components/TableContent/TableContent.test.js +0 -60
- package/dist/esm/components/table/components/TableContent/TableContent.test.js.map +0 -1
- package/dist/esm/lib/components/table/components/TableContent/TableContent.d.ts +0 -13
- package/src/lib/components/table/components/TableContent/TableContent.module.scss +0 -15
- package/src/lib/components/table/components/TableContent/TableContent.test.tsx +0 -56
- package/src/lib/components/table/components/TableContent/TableContent.tsx +0 -121
- /package/dist/cjs/lib/components/table/components/{TableSection → TableContents}/Collapsible.d.ts +0 -0
- /package/dist/cjs/lib/components/table/components/{TableContent/TableContent.test.d.ts → TableContents/TableContents.test.d.ts} +0 -0
- /package/dist/esm/components/table/components/{TableSection → TableContents}/Collapsible.js.map +0 -0
- /package/dist/esm/lib/components/table/components/{TableSection → TableContents}/Collapsible.d.ts +0 -0
- /package/dist/esm/lib/components/table/components/{TableContent/TableContent.test.d.ts → TableContents/TableContents.test.d.ts} +0 -0
- /package/src/lib/components/table/components/{TableSection → TableContents}/Collapsible.tsx +0 -0
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { Table,
|
|
1
|
+
import { Table, TableProps } from './Table';
|
|
2
2
|
import { DentalPlusIcon, PlaneIcon } from '../icon';
|
|
3
|
+
import { TableData } from './types';
|
|
3
4
|
|
|
4
5
|
const initialData: TableData = [
|
|
5
6
|
{
|
|
6
|
-
|
|
7
|
+
rows: [
|
|
7
8
|
[
|
|
8
9
|
{ content: 'Our plans' },
|
|
9
10
|
{ content: 'Surgery', modalContent: 'More info on surgery' },
|
|
@@ -41,7 +42,7 @@ const initialData: TableData = [
|
|
|
41
42
|
icon: <DentalPlusIcon size={24} noMargin />,
|
|
42
43
|
title: 'Dental',
|
|
43
44
|
},
|
|
44
|
-
|
|
45
|
+
rows: [
|
|
45
46
|
[
|
|
46
47
|
{ content: 'Regular vet visits & medication' },
|
|
47
48
|
{ content: 'No' },
|
|
@@ -67,7 +68,7 @@ const initialData: TableData = [
|
|
|
67
68
|
title: 'Travel',
|
|
68
69
|
icon: <PlaneIcon size={24} noMargin />,
|
|
69
70
|
},
|
|
70
|
-
|
|
71
|
+
rows: [
|
|
71
72
|
[
|
|
72
73
|
{ content: 'Regular vet visits & medication' },
|
|
73
74
|
{ content: 'No', checkmarkValue: false },
|
|
@@ -136,7 +137,7 @@ const story = {
|
|
|
136
137
|
},
|
|
137
138
|
},
|
|
138
139
|
args: {
|
|
139
|
-
|
|
140
|
+
tableData: initialData,
|
|
140
141
|
collapsibleSections: false,
|
|
141
142
|
hideDetails: false,
|
|
142
143
|
stickyHeaderTopOffset: 0,
|
|
@@ -151,7 +152,7 @@ const story = {
|
|
|
151
152
|
|
|
152
153
|
export const TableStory = ({
|
|
153
154
|
collapsibleSections,
|
|
154
|
-
|
|
155
|
+
tableData,
|
|
155
156
|
hideDetails,
|
|
156
157
|
stickyHeaderTopOffset,
|
|
157
158
|
textOverrides,
|
|
@@ -159,7 +160,7 @@ export const TableStory = ({
|
|
|
159
160
|
}: TableProps) => (
|
|
160
161
|
<Table
|
|
161
162
|
collapsibleSections={collapsibleSections}
|
|
162
|
-
|
|
163
|
+
tableData={tableData}
|
|
163
164
|
hideDetails={hideDetails}
|
|
164
165
|
stickyHeaderTopOffset={stickyHeaderTopOffset}
|
|
165
166
|
textOverrides={textOverrides}
|
|
@@ -176,17 +177,16 @@ type TableData = {
|
|
|
176
177
|
title?: string;
|
|
177
178
|
icon?: ReactNode;
|
|
178
179
|
};
|
|
179
|
-
|
|
180
|
+
rows: {
|
|
180
181
|
align?: 'center' | 'left' | 'right';
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
182
|
+
checkmarkValue?: boolean;
|
|
183
|
+
content?: ReactNode;
|
|
184
|
+
modalContent?: ReactNode;
|
|
185
|
+
subContent?: ReactNode;
|
|
185
186
|
rating?: {
|
|
186
187
|
value: number;
|
|
187
188
|
type: 'zap' | 'star';
|
|
188
189
|
}
|
|
189
|
-
text?: ReactNode;
|
|
190
190
|
openModal?: (modalContent: ReactNode) => void;
|
|
191
191
|
}[][];
|
|
192
192
|
}[];
|
|
@@ -2,20 +2,20 @@ import { render, screen } from '../../util/testUtils';
|
|
|
2
2
|
import { Table } from './Table';
|
|
3
3
|
import { TableSectionData } from './types';
|
|
4
4
|
|
|
5
|
-
const
|
|
5
|
+
const tableData: TableSectionData[] = [
|
|
6
6
|
{
|
|
7
7
|
section: {
|
|
8
8
|
title: 'Section 1',
|
|
9
9
|
icon: <span>Icon 1</span>,
|
|
10
10
|
},
|
|
11
|
-
|
|
11
|
+
rows: [[{ content: 'Item 1' }, { content: 'Item 2' }]],
|
|
12
12
|
},
|
|
13
13
|
{
|
|
14
14
|
section: {
|
|
15
15
|
title: 'Section 2',
|
|
16
16
|
icon: <span>Icon 2</span>,
|
|
17
17
|
},
|
|
18
|
-
|
|
18
|
+
rows: [
|
|
19
19
|
[
|
|
20
20
|
{ content: 'Item 3' },
|
|
21
21
|
{ content: 'Item 4', modalContent: 'Additional item' },
|
|
@@ -26,7 +26,7 @@ const data: TableSectionData[] = [
|
|
|
26
26
|
|
|
27
27
|
describe('Table', () => {
|
|
28
28
|
it('renders the table with sections and items', () => {
|
|
29
|
-
render(<Table
|
|
29
|
+
render(<Table tableData={tableData} title="Test Table" />);
|
|
30
30
|
|
|
31
31
|
expect(screen.getByText('Section 1')).toBeInTheDocument();
|
|
32
32
|
expect(screen.getByText('Section 2')).toBeInTheDocument();
|
|
@@ -38,28 +38,28 @@ describe('Table', () => {
|
|
|
38
38
|
});
|
|
39
39
|
|
|
40
40
|
it('renders the table without sections', () => {
|
|
41
|
-
const dataWithoutSections = [{
|
|
41
|
+
const dataWithoutSections = [{ rows: tableData[0].rows }];
|
|
42
42
|
|
|
43
|
-
render(<Table
|
|
43
|
+
render(<Table tableData={dataWithoutSections} title="Test Table" />);
|
|
44
44
|
|
|
45
45
|
expect(screen.getAllByText('Item 1')[0]).toBeVisible();
|
|
46
46
|
expect(screen.getAllByText('Item 2')[0]).toBeVisible();
|
|
47
47
|
});
|
|
48
48
|
|
|
49
49
|
it('hides the show/hide details button if hideDetails is false', () => {
|
|
50
|
-
render(<Table
|
|
50
|
+
render(<Table tableData={tableData} hideDetails title="Test Table" />);
|
|
51
51
|
|
|
52
52
|
expect(screen.queryByTestId('show-hide-details')).toBeInTheDocument();
|
|
53
53
|
});
|
|
54
54
|
|
|
55
55
|
it('shows the show/hide details button if hideDetails is true', () => {
|
|
56
|
-
render(<Table
|
|
56
|
+
render(<Table tableData={tableData} hideDetails title="Test Table" />);
|
|
57
57
|
|
|
58
58
|
expect(screen.getByTestId('show-hide-details')).toBeInTheDocument();
|
|
59
59
|
});
|
|
60
60
|
|
|
61
61
|
it('hides the sections if hideDetails is true', () => {
|
|
62
|
-
render(<Table
|
|
62
|
+
render(<Table tableData={tableData} hideDetails title="Test Table" />);
|
|
63
63
|
|
|
64
64
|
expect(screen.queryByText('Section 2')).not.toBeInTheDocument();
|
|
65
65
|
expect(screen.getByTestId('show-hide-details')).toBeInTheDocument();
|
|
@@ -67,7 +67,7 @@ describe('Table', () => {
|
|
|
67
67
|
|
|
68
68
|
it('hides the sections if hideDetails is true and shows if clicking on button', async () => {
|
|
69
69
|
const { user } = render(
|
|
70
|
-
<Table
|
|
70
|
+
<Table tableData={tableData} hideDetails title="Test Table" />
|
|
71
71
|
);
|
|
72
72
|
|
|
73
73
|
expect(screen.getByText('Show details')).toBeVisible();
|
|
@@ -79,7 +79,7 @@ describe('Table', () => {
|
|
|
79
79
|
});
|
|
80
80
|
|
|
81
81
|
it('shows a modal when clicking on info icon', async () => {
|
|
82
|
-
const { user } = render(<Table
|
|
82
|
+
const { user } = render(<Table tableData={tableData} title="Test Table" />);
|
|
83
83
|
|
|
84
84
|
await user.click(screen.getByText('View more info'));
|
|
85
85
|
|
|
@@ -6,25 +6,23 @@ import { Card } from '../cards/card';
|
|
|
6
6
|
|
|
7
7
|
import styles from './Table.module.scss';
|
|
8
8
|
import { useMediaQuery } from '../../hooks/useMediaQuery';
|
|
9
|
-
import {
|
|
9
|
+
import { TableContents } from './components/TableContents/TableContents';
|
|
10
10
|
import classNames from 'classnames';
|
|
11
11
|
import { useTableNavigation } from './utils/useTableNavigation/useTableNavigation';
|
|
12
12
|
import { TableControls } from './components/TableControls/TableControls';
|
|
13
|
-
import {
|
|
13
|
+
import { TableSection } from './components/TableSection/TableSection';
|
|
14
14
|
import { useScrollSync } from './utils/useScrollSync/useScrollSync';
|
|
15
|
-
import { ModalData, ModalFunction,
|
|
15
|
+
import { ModalData, ModalFunction, TableData } from './types';
|
|
16
16
|
|
|
17
17
|
type TextOverrides = {
|
|
18
18
|
showDetails?: string;
|
|
19
19
|
hideDetails?: string;
|
|
20
20
|
};
|
|
21
21
|
|
|
22
|
-
export type TableData = TableSectionData[];
|
|
23
|
-
|
|
24
22
|
export interface TableProps {
|
|
25
23
|
className?: string;
|
|
26
24
|
collapsibleSections?: boolean;
|
|
27
|
-
|
|
25
|
+
tableData: TableData;
|
|
28
26
|
hideDetails?: boolean;
|
|
29
27
|
onModalOpen?: ModalFunction;
|
|
30
28
|
onSelectionChanged?: (index: number) => void;
|
|
@@ -41,7 +39,7 @@ const defaultTextOverrides = {
|
|
|
41
39
|
const Table = ({
|
|
42
40
|
className,
|
|
43
41
|
collapsibleSections,
|
|
44
|
-
|
|
42
|
+
tableData,
|
|
45
43
|
hideDetails,
|
|
46
44
|
onModalOpen,
|
|
47
45
|
onSelectionChanged,
|
|
@@ -55,7 +53,7 @@ const Table = ({
|
|
|
55
53
|
const [shouldHideDetails, setShouldHideDetails] = useState(true);
|
|
56
54
|
const containerRef = useRef<HTMLDivElement | null>(null);
|
|
57
55
|
const headerRef = useRef<HTMLDivElement | null>(null);
|
|
58
|
-
const columnsLength =
|
|
56
|
+
const columnsLength = tableData[0].rows[0].length;
|
|
59
57
|
|
|
60
58
|
useScrollSync(headerRef, containerRef, !isMobile);
|
|
61
59
|
|
|
@@ -66,7 +64,7 @@ const Table = ({
|
|
|
66
64
|
onSelectionChanged,
|
|
67
65
|
});
|
|
68
66
|
|
|
69
|
-
const currentActiveSection =
|
|
67
|
+
const currentActiveSection = tableData?.[0]?.rows?.[0]?.[activeSection];
|
|
70
68
|
|
|
71
69
|
const handleOpenModal: ModalFunction = ({ body, title }) => {
|
|
72
70
|
onModalOpen?.({ body, title });
|
|
@@ -100,8 +98,8 @@ const Table = ({
|
|
|
100
98
|
style={{ top: `${stickyHeaderTopOffset}px` }}
|
|
101
99
|
>
|
|
102
100
|
<div className={styles.container} ref={headerRef}>
|
|
103
|
-
<
|
|
104
|
-
|
|
101
|
+
<TableSection
|
|
102
|
+
tableCellRows={[tableData?.[0]?.rows?.[0]]}
|
|
105
103
|
title={title}
|
|
106
104
|
className={className}
|
|
107
105
|
openModal={handleOpenModal}
|
|
@@ -111,8 +109,8 @@ const Table = ({
|
|
|
111
109
|
)}
|
|
112
110
|
|
|
113
111
|
<div ref={containerRef} className={classNames(styles.container, 'pb8')}>
|
|
114
|
-
<
|
|
115
|
-
|
|
112
|
+
<TableContents
|
|
113
|
+
tableData={tableData}
|
|
116
114
|
title={title}
|
|
117
115
|
className={className}
|
|
118
116
|
collapsibleSections={collapsibleSections}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { render, screen } from '../../../../util/testUtils';
|
|
2
|
+
import { TableContents, TableSectionProps } from './TableContents';
|
|
3
|
+
|
|
4
|
+
const mockData: TableSectionProps['tableData'] = [
|
|
5
|
+
{
|
|
6
|
+
rows: [
|
|
7
|
+
[{ content: 'Item 1.1.1' }, { content: 'Item 1.1.2' }],
|
|
8
|
+
[{ content: 'Item 1.2.1' }, { content: 'Item 1.2.2' }],
|
|
9
|
+
],
|
|
10
|
+
},
|
|
11
|
+
{
|
|
12
|
+
section: {
|
|
13
|
+
title: 'Section 2',
|
|
14
|
+
},
|
|
15
|
+
rows: [
|
|
16
|
+
[{ content: 'Item 2.1.1' }, { content: 'Item 2.1.2' }],
|
|
17
|
+
[{ content: 'Item 2.2.1' }, { content: 'Item 2.2.2' }],
|
|
18
|
+
],
|
|
19
|
+
},
|
|
20
|
+
];
|
|
21
|
+
|
|
22
|
+
describe('TableContents', () => {
|
|
23
|
+
it('renders the table sections with sections', () => {
|
|
24
|
+
render(
|
|
25
|
+
<TableContents collapsibleSections tableData={mockData} title="Table" />
|
|
26
|
+
);
|
|
27
|
+
|
|
28
|
+
expect(screen.getByText('Section 2')).toBeInTheDocument();
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
it('renders the table sections with sections data', () => {
|
|
32
|
+
render(
|
|
33
|
+
<TableContents collapsibleSections tableData={mockData} title="Table" />
|
|
34
|
+
);
|
|
35
|
+
|
|
36
|
+
expect(screen.getByText('Item 1.2.1')).toBeInTheDocument();
|
|
37
|
+
expect(screen.getByText('Item 1.2.2')).toBeInTheDocument();
|
|
38
|
+
expect(screen.getByText('Item 2.1.2')).toBeInTheDocument();
|
|
39
|
+
expect(screen.getByText('Item 2.2.1')).toBeInTheDocument();
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it('hides the table sections when hideDetails and shouldHideDetails is true', () => {
|
|
43
|
+
render(
|
|
44
|
+
<TableContents
|
|
45
|
+
hideDetails
|
|
46
|
+
shouldHideDetails
|
|
47
|
+
tableData={mockData}
|
|
48
|
+
title="Table"
|
|
49
|
+
/>
|
|
50
|
+
);
|
|
51
|
+
|
|
52
|
+
expect(screen.queryByText('Section 2')).not.toBeInTheDocument();
|
|
53
|
+
expect(screen.queryByText('Item 2.1.1')).not.toBeInTheDocument();
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
it('hides the table sections details when collapsibleSections is true', () => {
|
|
57
|
+
render(
|
|
58
|
+
<TableContents
|
|
59
|
+
collapsibleSections
|
|
60
|
+
isMobile
|
|
61
|
+
tableData={mockData}
|
|
62
|
+
title="Table"
|
|
63
|
+
/>
|
|
64
|
+
);
|
|
65
|
+
|
|
66
|
+
expect(screen.getByText('Section 2')).toBeVisible();
|
|
67
|
+
expect(screen.queryByText('Item 2.1.1')).not.toBeVisible();
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
it('shows the table sections when hideDetails is collapsibleSections true has expanded ', async () => {
|
|
71
|
+
const { user } = render(
|
|
72
|
+
<TableContents
|
|
73
|
+
collapsibleSections
|
|
74
|
+
isMobile
|
|
75
|
+
tableData={mockData}
|
|
76
|
+
title="Table"
|
|
77
|
+
/>
|
|
78
|
+
);
|
|
79
|
+
|
|
80
|
+
expect(screen.queryByText('Item 2.1.1')).not.toBeVisible();
|
|
81
|
+
|
|
82
|
+
await user.click(screen.getByText('Section 2'));
|
|
83
|
+
|
|
84
|
+
expect(screen.getByText('Item 2.1.1')).toBeVisible();
|
|
85
|
+
});
|
|
86
|
+
});
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { useState } from 'react';
|
|
2
|
+
import { TableSection } from '../TableSection/TableSection';
|
|
3
|
+
import { ChevronDownIcon, ChevronUpIcon } from '../../../icon';
|
|
4
|
+
import { Card } from '../../../cards/card';
|
|
5
|
+
|
|
6
|
+
import styles from './TableContents.module.scss';
|
|
7
|
+
import classNames from 'classnames';
|
|
8
|
+
import { Collapsible } from './Collapsible';
|
|
9
|
+
import { ModalFunction, TableData } from '../../types';
|
|
10
|
+
|
|
11
|
+
export interface TableContentsProps {
|
|
12
|
+
className?: string;
|
|
13
|
+
collapsibleSections?: boolean;
|
|
14
|
+
tableData: TableData;
|
|
15
|
+
hideDetails?: boolean;
|
|
16
|
+
isMobile?: boolean;
|
|
17
|
+
openModal?: ModalFunction;
|
|
18
|
+
shouldHideDetails?: boolean;
|
|
19
|
+
title: string;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const TableContents = ({
|
|
23
|
+
className,
|
|
24
|
+
collapsibleSections,
|
|
25
|
+
tableData,
|
|
26
|
+
hideDetails,
|
|
27
|
+
isMobile,
|
|
28
|
+
openModal,
|
|
29
|
+
shouldHideDetails,
|
|
30
|
+
title,
|
|
31
|
+
}: TableContentsProps) => {
|
|
32
|
+
const [isSectionOpen, setOpenSection] = useState<number | null>(null);
|
|
33
|
+
const firstHeadRow = tableData?.[0]?.rows?.[0];
|
|
34
|
+
const tableWidth = isMobile ? `${firstHeadRow?.length * 50}%` : '';
|
|
35
|
+
const handleToggleSection = (index: number) => {
|
|
36
|
+
setOpenSection((currentSection) =>
|
|
37
|
+
currentSection === index ? null : index
|
|
38
|
+
);
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
return (
|
|
42
|
+
<div style={{ width: tableWidth }}>
|
|
43
|
+
{tableData.map(({ rows, section = {} }, index) => {
|
|
44
|
+
const isFirstSection = index === 0;
|
|
45
|
+
const isExpanded = !collapsibleSections
|
|
46
|
+
? true
|
|
47
|
+
: isSectionOpen === index || isFirstSection;
|
|
48
|
+
const isVisible = hideDetails ? !shouldHideDetails : true;
|
|
49
|
+
|
|
50
|
+
return (
|
|
51
|
+
(isFirstSection || isVisible) && (
|
|
52
|
+
<div key={index}>
|
|
53
|
+
{section?.title && (
|
|
54
|
+
<div className={styles.cardWrapper}>
|
|
55
|
+
<div className={classNames(styles.card, 'p8')}>
|
|
56
|
+
<Card
|
|
57
|
+
actionIcon={
|
|
58
|
+
isExpanded ? (
|
|
59
|
+
<ChevronUpIcon size={24} />
|
|
60
|
+
) : (
|
|
61
|
+
<ChevronDownIcon size={24} />
|
|
62
|
+
)
|
|
63
|
+
}
|
|
64
|
+
aria-expanded={isExpanded ? 'true' : 'false'}
|
|
65
|
+
aria-hidden
|
|
66
|
+
classNames={{
|
|
67
|
+
wrapper: 'bg-grey-200',
|
|
68
|
+
icon: 'tc-grey-900',
|
|
69
|
+
}}
|
|
70
|
+
dropShadow={false}
|
|
71
|
+
icon={section?.icon}
|
|
72
|
+
title={section.title}
|
|
73
|
+
titleVariant="medium"
|
|
74
|
+
{...(collapsibleSections
|
|
75
|
+
? {
|
|
76
|
+
onClick: () => handleToggleSection(index),
|
|
77
|
+
}
|
|
78
|
+
: {})}
|
|
79
|
+
/>
|
|
80
|
+
</div>
|
|
81
|
+
</div>
|
|
82
|
+
)}
|
|
83
|
+
|
|
84
|
+
<Collapsible isExpanded={isExpanded} isMobile={isMobile}>
|
|
85
|
+
<TableSection
|
|
86
|
+
className={classNames(className, 'mb24')}
|
|
87
|
+
tableCellRows={
|
|
88
|
+
isFirstSection ? rows : [firstHeadRow, ...rows]
|
|
89
|
+
}
|
|
90
|
+
hideHeader
|
|
91
|
+
openModal={openModal}
|
|
92
|
+
title={`${title}${
|
|
93
|
+
section?.title ? ` - ${section.title}` : ''
|
|
94
|
+
}`}
|
|
95
|
+
width={tableWidth}
|
|
96
|
+
/>
|
|
97
|
+
</Collapsible>
|
|
98
|
+
</div>
|
|
99
|
+
)
|
|
100
|
+
);
|
|
101
|
+
})}
|
|
102
|
+
</div>
|
|
103
|
+
);
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
export { TableContents };
|
|
@@ -1,10 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
@use '../../../../scss/public/colors' as *;
|
|
2
|
+
@use '../../../../scss/public/grid' as *;
|
|
3
|
+
|
|
4
|
+
.table {
|
|
5
|
+
border-collapse: collapse;
|
|
6
|
+
table-layout: fixed;
|
|
7
|
+
|
|
8
|
+
@include p-size-tablet {
|
|
9
|
+
min-width: 845px;
|
|
10
|
+
}
|
|
3
11
|
}
|
|
4
12
|
|
|
5
|
-
.
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
right: 0;
|
|
9
|
-
z-index: 3;
|
|
10
|
-
}
|
|
13
|
+
.tr {
|
|
14
|
+
min-height: 72px;
|
|
15
|
+
}
|
|
@@ -1,82 +1,56 @@
|
|
|
1
1
|
import { render, screen } from '../../../../util/testUtils';
|
|
2
|
-
import { TableSection,
|
|
2
|
+
import { TableSection, TableContentProps } from './TableSection';
|
|
3
3
|
|
|
4
|
-
const
|
|
5
|
-
{
|
|
6
|
-
|
|
7
|
-
[{ content: 'Item 1.1.1' }, { content: 'Item 1.1.2' }],
|
|
8
|
-
[{ content: 'Item 1.2.1' }, { content: 'Item 1.2.2' }],
|
|
9
|
-
],
|
|
10
|
-
},
|
|
11
|
-
{
|
|
12
|
-
section: {
|
|
13
|
-
title: 'Section 2',
|
|
14
|
-
},
|
|
15
|
-
items: [
|
|
16
|
-
[{ content: 'Item 2.1.1' }, { content: 'Item 2.1.2' }],
|
|
17
|
-
[{ content: 'Item 2.2.1' }, { content: 'Item 2.2.2' }],
|
|
18
|
-
],
|
|
19
|
-
},
|
|
4
|
+
const tableCellRows: TableContentProps['tableCellRows'] = [
|
|
5
|
+
[{ content: 'Cell 1.1' }, { content: 'Cell 1.2' }, { content: 'Cell 1.3' }],
|
|
6
|
+
[{ content: 'Cell 2.1' }, { content: 'Cell 2.2' }, { content: 'Cell 2.3' }],
|
|
20
7
|
];
|
|
21
8
|
|
|
22
|
-
|
|
23
|
-
it('renders the table sections with sections', () => {
|
|
24
|
-
render(<TableSection collapsibleSections data={mockData} title="Table" />);
|
|
25
|
-
|
|
26
|
-
expect(screen.getByText('Section 2')).toBeInTheDocument();
|
|
27
|
-
});
|
|
9
|
+
const mockTitle = 'Test Table';
|
|
28
10
|
|
|
29
|
-
|
|
30
|
-
render(<TableSection collapsibleSections data={mockData} title="Table" />);
|
|
11
|
+
const mockOpenModal = jest.fn();
|
|
31
12
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
13
|
+
const defaultProps: TableContentProps = {
|
|
14
|
+
tableCellRows,
|
|
15
|
+
title: mockTitle,
|
|
16
|
+
openModal: mockOpenModal,
|
|
17
|
+
};
|
|
37
18
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
hideDetails
|
|
42
|
-
shouldHideDetails
|
|
43
|
-
data={mockData}
|
|
44
|
-
title="Table"
|
|
45
|
-
/>
|
|
46
|
-
);
|
|
19
|
+
describe('TableSection', () => {
|
|
20
|
+
it('renders the table caption', () => {
|
|
21
|
+
render(<TableSection {...defaultProps} />);
|
|
47
22
|
|
|
48
|
-
expect(screen.
|
|
49
|
-
expect(screen.queryByText('Item 2.1.1')).not.toBeInTheDocument();
|
|
23
|
+
expect(screen.getByText(mockTitle)).toBeInTheDocument();
|
|
50
24
|
});
|
|
51
25
|
|
|
52
|
-
it('
|
|
53
|
-
render(
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
title="Table"
|
|
59
|
-
/>
|
|
60
|
-
);
|
|
26
|
+
it('renders the table with correct data', () => {
|
|
27
|
+
render(<TableSection {...defaultProps} />);
|
|
28
|
+
|
|
29
|
+
expect(screen.getByText('Cell 1.1')).toBeInTheDocument();
|
|
30
|
+
expect(screen.getByText('Cell 1.2')).toBeInTheDocument();
|
|
31
|
+
expect(screen.getByText('Cell 1.3')).toBeInTheDocument();
|
|
61
32
|
|
|
62
|
-
expect(screen.getByText('
|
|
63
|
-
expect(screen.
|
|
33
|
+
expect(screen.getByText('Cell 2.1')).toBeInTheDocument();
|
|
34
|
+
expect(screen.getByText('Cell 2.2')).toBeInTheDocument();
|
|
35
|
+
expect(screen.getByText('Cell 2.3')).toBeInTheDocument();
|
|
64
36
|
});
|
|
65
37
|
|
|
66
|
-
it('
|
|
67
|
-
const {
|
|
68
|
-
<TableSection
|
|
69
|
-
collapsibleSections
|
|
70
|
-
isMobile
|
|
71
|
-
data={mockData}
|
|
72
|
-
title="Table"
|
|
73
|
-
/>
|
|
74
|
-
);
|
|
38
|
+
it('should render table headers', () => {
|
|
39
|
+
const { container } = render(<TableSection {...defaultProps} />);
|
|
75
40
|
|
|
76
|
-
|
|
41
|
+
const thElements = container.querySelectorAll('th');
|
|
42
|
+
|
|
43
|
+
expect(thElements.length).toBe(4);
|
|
44
|
+
expect(thElements[0]).toHaveTextContent('Cell 1.1');
|
|
45
|
+
expect(thElements[3]).toHaveTextContent('Cell 2.1');
|
|
46
|
+
});
|
|
77
47
|
|
|
78
|
-
|
|
48
|
+
it('should render table data cells', () => {
|
|
49
|
+
const { container } = render(<TableSection {...defaultProps} />);
|
|
79
50
|
|
|
80
|
-
|
|
51
|
+
const tdElements = container.querySelectorAll('td');
|
|
52
|
+
expect(tdElements.length).toBe(2);
|
|
53
|
+
expect(tdElements[0]).toHaveTextContent('Cell 2.2');
|
|
54
|
+
expect(tdElements[1]).toHaveTextContent('Cell 2.3');
|
|
81
55
|
});
|
|
82
56
|
});
|