@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,118 +1,121 @@
|
|
|
1
|
-
import { TableCellProps } from '../TableCell/TableCell';
|
|
2
|
-
import { ReactNode, useState } from 'react';
|
|
3
|
-
import { TableContent } from '../TableContent/TableContent';
|
|
4
|
-
import { ChevronDownIcon, ChevronUpIcon } from '../../../icon';
|
|
5
|
-
import { Card } from '../../../cards/card';
|
|
6
|
-
|
|
7
|
-
import styles from './TableSection.module.scss';
|
|
8
1
|
import classNames from 'classnames';
|
|
9
|
-
import { Collapsible } from './Collapsible';
|
|
10
|
-
import { ModalFunction } from '../../types';
|
|
11
2
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
interface TableSectionData {
|
|
18
|
-
section?: TableSectionType;
|
|
19
|
-
items: TableCellProps[][];
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export type TableData = TableSectionData[];
|
|
3
|
+
import styles from './TableSection.module.scss';
|
|
4
|
+
import { TableCell, TableCellProps } from '../TableCell/TableCell';
|
|
5
|
+
import { ReactNode, useCallback } from 'react';
|
|
6
|
+
import { ModalData, ModalFunction, TableCellRowData } from '../../types';
|
|
23
7
|
|
|
24
8
|
export interface TableSectionProps {
|
|
25
9
|
className?: string;
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
hideDetails?: boolean;
|
|
29
|
-
isMobile?: boolean;
|
|
10
|
+
tableCellRows: TableCellRowData[];
|
|
11
|
+
hideHeader?: boolean;
|
|
30
12
|
openModal?: ModalFunction;
|
|
31
|
-
shouldHideDetails?: boolean;
|
|
32
13
|
title: string;
|
|
14
|
+
width?: number | string;
|
|
33
15
|
}
|
|
34
16
|
|
|
35
17
|
const TableSection = ({
|
|
36
18
|
className,
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
hideDetails,
|
|
40
|
-
isMobile,
|
|
19
|
+
tableCellRows,
|
|
20
|
+
hideHeader,
|
|
41
21
|
openModal,
|
|
42
|
-
shouldHideDetails,
|
|
43
22
|
title,
|
|
23
|
+
width,
|
|
44
24
|
}: TableSectionProps) => {
|
|
45
|
-
const
|
|
46
|
-
|
|
47
|
-
const
|
|
25
|
+
const headerRow = tableCellRows?.[0];
|
|
26
|
+
|
|
27
|
+
const getColumnContentByKey = useCallback(
|
|
28
|
+
(key: number) => tableCellRows?.[0]?.[key]?.content || '',
|
|
29
|
+
[tableCellRows]
|
|
30
|
+
);
|
|
48
31
|
|
|
49
|
-
const
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
}
|
|
32
|
+
const handleOpenModal = ({
|
|
33
|
+
cellIndex,
|
|
34
|
+
body,
|
|
35
|
+
title,
|
|
36
|
+
}: ModalData & {
|
|
37
|
+
cellIndex: number;
|
|
38
|
+
}) =>
|
|
39
|
+
openModal?.({
|
|
40
|
+
body,
|
|
41
|
+
title: title || getColumnContentByKey(cellIndex),
|
|
42
|
+
});
|
|
54
43
|
|
|
55
44
|
return (
|
|
56
|
-
<
|
|
57
|
-
{
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
: isSectionOpen === index || isFirstSection;
|
|
62
|
-
const isVisible = hideDetails ? !shouldHideDetails : true;
|
|
45
|
+
<table
|
|
46
|
+
className={classNames(className, 'w100', styles.table)}
|
|
47
|
+
width={width}
|
|
48
|
+
>
|
|
49
|
+
<caption className="sr-only">{title}</caption>
|
|
63
50
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
51
|
+
{headerRow && (
|
|
52
|
+
<thead className={hideHeader ? 'sr-only' : ''}>
|
|
53
|
+
<tr>
|
|
54
|
+
{headerRow.map((tableCellProps, cellIndex) => {
|
|
55
|
+
const isFirstCellInRow = cellIndex === 0;
|
|
56
|
+
return (
|
|
57
|
+
<TableCell
|
|
58
|
+
key={cellIndex}
|
|
59
|
+
isHeader
|
|
60
|
+
isFirstCellInRow={isFirstCellInRow}
|
|
61
|
+
isTopLeftCell={isFirstCellInRow}
|
|
62
|
+
align={isFirstCellInRow ? 'left' : 'center'}
|
|
63
|
+
openModal={(body) =>
|
|
64
|
+
handleOpenModal({
|
|
65
|
+
cellIndex,
|
|
66
|
+
body,
|
|
67
|
+
title: tableCellProps?.content,
|
|
68
|
+
})
|
|
69
|
+
}
|
|
70
|
+
{...tableCellProps}
|
|
71
|
+
/>
|
|
72
|
+
);
|
|
73
|
+
})}
|
|
74
|
+
</tr>
|
|
75
|
+
</thead>
|
|
76
|
+
)}
|
|
77
|
+
|
|
78
|
+
<tbody>
|
|
79
|
+
{tableCellRows.map((row, rowIndex) => {
|
|
80
|
+
const isSingleCell = row.length === 1;
|
|
81
|
+
|
|
82
|
+
return (
|
|
83
|
+
rowIndex > 0 && (
|
|
84
|
+
<tr key={rowIndex} className={styles.tr}>
|
|
85
|
+
{row.map((tableCellProps, cellIndex) => {
|
|
86
|
+
const key = `${rowIndex}-${cellIndex}`;
|
|
87
|
+
const isFirstCellInRow = cellIndex === 0;
|
|
88
|
+
|
|
89
|
+
const onCelInfoClick = (body: ReactNode) =>
|
|
90
|
+
handleOpenModal({
|
|
91
|
+
cellIndex,
|
|
92
|
+
body,
|
|
93
|
+
title: isFirstCellInRow
|
|
94
|
+
? tableCellProps.content
|
|
95
|
+
: undefined,
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
return (
|
|
99
|
+
<TableCell
|
|
100
|
+
align={
|
|
101
|
+
isFirstCellInRow && !isSingleCell ? 'left' : 'center'
|
|
77
102
|
}
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
icon: 'tc-grey-900',
|
|
83
|
-
}}
|
|
84
|
-
dropShadow={false}
|
|
85
|
-
icon={section?.icon}
|
|
86
|
-
title={section.title}
|
|
87
|
-
titleVariant="medium"
|
|
88
|
-
{...(collapsibleSections
|
|
89
|
-
? {
|
|
90
|
-
onClick: () => handleToggleSection(index),
|
|
91
|
-
}
|
|
92
|
-
: {})}
|
|
103
|
+
isFirstCellInRow={isFirstCellInRow}
|
|
104
|
+
openModal={onCelInfoClick}
|
|
105
|
+
key={key}
|
|
106
|
+
{...tableCellProps}
|
|
93
107
|
/>
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
hideHeader
|
|
103
|
-
openModal={openModal}
|
|
104
|
-
title={`${title}${
|
|
105
|
-
section?.title ? ` - ${section.title}` : ''
|
|
106
|
-
}`}
|
|
107
|
-
width={tableWidth}
|
|
108
|
-
/>
|
|
109
|
-
</Collapsible>
|
|
110
|
-
</div>
|
|
111
|
-
)
|
|
112
|
-
);
|
|
113
|
-
})}
|
|
114
|
-
</div>
|
|
108
|
+
);
|
|
109
|
+
})}
|
|
110
|
+
</tr>
|
|
111
|
+
)
|
|
112
|
+
);
|
|
113
|
+
})}
|
|
114
|
+
</tbody>
|
|
115
|
+
</table>
|
|
115
116
|
);
|
|
116
117
|
};
|
|
117
118
|
|
|
119
|
+
export type { TableCellProps };
|
|
120
|
+
|
|
118
121
|
export { TableSection };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ReactNode } from 'react';
|
|
2
|
-
import { TableCellProps } from './components/TableCell/TableCell';
|
|
2
|
+
import type { TableCellProps } from './components/TableCell/TableCell';
|
|
3
3
|
|
|
4
4
|
export type TableSectionType = {
|
|
5
5
|
title?: string;
|
|
@@ -11,9 +11,13 @@ export type ModalData = {
|
|
|
11
11
|
body?: ReactNode;
|
|
12
12
|
};
|
|
13
13
|
|
|
14
|
-
export
|
|
14
|
+
export type TableCellRowData = TableCellProps[];
|
|
15
|
+
|
|
16
|
+
export type TableSectionData = {
|
|
15
17
|
section?: TableSectionType;
|
|
16
|
-
|
|
17
|
-
}
|
|
18
|
+
rows: TableCellRowData[];
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export type TableData = TableSectionData[];
|
|
18
22
|
|
|
19
23
|
export type ModalFunction = (modalData: ModalData) => void;
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { TableCellProps } from '../TableCell/TableCell';
|
|
2
|
-
import { ModalFunction } from '../../types';
|
|
3
|
-
export interface TableContentProps {
|
|
4
|
-
className?: string;
|
|
5
|
-
data: TableCellProps[][];
|
|
6
|
-
hideHeader?: boolean;
|
|
7
|
-
openModal?: ModalFunction;
|
|
8
|
-
title: string;
|
|
9
|
-
width?: number | string;
|
|
10
|
-
}
|
|
11
|
-
declare const TableContent: ({ className, data, hideHeader, openModal, title, width, }: TableContentProps) => JSX.Element;
|
|
12
|
-
export type { TableCellProps };
|
|
13
|
-
export { TableContent };
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Collapsible-ac67187a.js","sources":["../../../src/lib/hooks/useMediaQuery.ts","../../../src/lib/components/table/components/TableSection/Collapsible.tsx"],"sourcesContent":["import { useEffect, useState } from 'react';\n\n// USAGE:\n// const isMobile = useMediaQuery('BELOW_MOBILE');\n\nexport const breakpointsArray = [\n 'ABOVE_MOBILE',\n 'ABOVE_TABLET',\n 'ABOVE_DESKTOP',\n 'BELOW_MOBILE',\n 'BELOW_TABLET',\n 'BELOW_DESKTOP',\n] as const;\n\nexport type Breakpoint = typeof breakpointsArray[number];\nexport type BreakpointData = { initialValue: boolean; queryString: string };\n\nexport const breakpointLookup = (breakpoint: Breakpoint): BreakpointData => {\n switch (breakpoint) {\n case 'BELOW_MOBILE':\n default:\n return {\n initialValue: window.innerWidth <= 544, // 34rem = 544px = mobile breakpoint}\n queryString: '(max-width: 34rem)',\n };\n case 'BELOW_TABLET':\n return {\n initialValue: window.innerWidth <= 720, // 45rem = 720px = tablet breakpoint\n queryString: '(max-width: 45rem)',\n };\n case 'BELOW_DESKTOP':\n return {\n initialValue: window.innerWidth <= 1024, // 64rem = 1024px = desktop breakpoint\n queryString: '(max-width: 64rem)',\n };\n case 'ABOVE_MOBILE':\n return {\n initialValue: window.innerWidth >= 544, // 34rem = 544px = mobile breakpoint}\n queryString: '(min-width: 34rem)',\n };\n case 'ABOVE_TABLET':\n return {\n initialValue: window.innerWidth >= 720, // 45rem = 720px = tablet breakpoint\n queryString: '(min-width: 45rem)',\n };\n case 'ABOVE_DESKTOP':\n return {\n initialValue: window.innerWidth >= 1024, // 64rem = 1024px = desktop breakpoint\n queryString: '(min-width: 64rem)',\n };\n }\n};\n\nexport const useMediaQuery = (breakpoint: Breakpoint) => {\n const { initialValue, queryString } = breakpointLookup(breakpoint);\n\n const [matchesBreakpoint, setMatchesBreakpoint] = useState(initialValue);\n\n useEffect(() => {\n const mediaQuery = window.matchMedia(queryString);\n\n const updateMediaQuery = (e: MediaQueryListEvent) =>\n setMatchesBreakpoint(e.matches);\n\n mediaQuery.addEventListener('change', updateMediaQuery);\n\n return () => {\n mediaQuery.removeEventListener('change', updateMediaQuery);\n };\n }, [queryString]);\n\n return matchesBreakpoint;\n};\n","import { ReactNode } from \"react\";\nimport AnimateHeight from \"react-animate-height\";\nimport { useMediaQuery } from \"../../../../hooks/useMediaQuery\";\n\ninterface CollapsibleProps {\n children: ReactNode;\n isExpanded?: boolean;\n isMobile?: boolean;\n}\n \nexport const Collapsible = ({ children, isExpanded }: CollapsibleProps) => {\n const isDesktop = useMediaQuery('ABOVE_DESKTOP');\n\n if (!isDesktop) {\n return (\n <div>\n {isExpanded ? children : null}\n </div>\n );\n }\n\n return (\n <AnimateHeight\n duration={300}\n height={isExpanded ? 'auto' : 0}\n >\n <div>{children}</div>\n </AnimateHeight>\n );\n}\n"],"names":["_jsx"],"mappings":";;;;AAiBO,IAAM,gBAAgB,GAAG,UAAC,UAAsB;IACrD,QAAQ,UAAU;QAChB,KAAK,cAAc,CAAC;QACpB;YACE,O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E,gBAAgB,CAAC,CAAC;SAC5D,CAAC;KACH,EAAE,CAAC,WAAW,CAAC,CAAC,CAAC;IAElB,OAAO,iBAAiB,CAAC;AAC3B;;IC9Da,WAAW,GAAG,UAAC,EAA0C;QAAxC,QAAQ,cAAA,EAAE,UAAU,gBAAA;IAChD,IAAM,SAAS,GAAG,aAAa,CAAC,eAAe,CAAC,CAAC;IAEjD,IAAI,CAAC,SAAS,EAAE;QACd,QACEA,uBACG,UAAU,GAAG,QAAQ,GAAG,IAAI,GACzB,EACN;KACH;IAED,QACEA,IAAC,aAAa,IACZ,QAAQ,EAAE,GAAG,EACb,MAAM,EAAE,UAAU,GAAG,MAAM,GAAG,CAAC,YAE/BA,uBAAM,QAAQ,GAAO,GACP,EAChB;AACJ;;;;"}
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
import { a as __assign } from '../../../../tslib.es6-a39f91fc.js';
|
|
2
|
-
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
3
|
-
import { c as classNames } from '../../../../index-6ea95111.js';
|
|
4
|
-
import { s as styleInject } from '../../../../style-inject.es-1f59c1d0.js';
|
|
5
|
-
import { TableCell } from '../TableCell/TableCell.js';
|
|
6
|
-
import { useCallback } from 'react';
|
|
7
|
-
import '../../../button/index.js';
|
|
8
|
-
import '../../../icon/icons/Check.js';
|
|
9
|
-
import '../../../icon/IconWrapper/IconWrapper.js';
|
|
10
|
-
import '../../../icon/icons/Info.js';
|
|
11
|
-
import '../../../icon/icons/StarFilled.js';
|
|
12
|
-
import '../../../icon/icons/X.js';
|
|
13
|
-
import '../../../icon/icons/ZapFilled.js';
|
|
14
|
-
|
|
15
|
-
var css_248z = ".TableContent-module_table__28VKr {\n border-collapse: collapse;\n table-layout: fixed;\n}\n@media (min-width: 34rem) {\n .TableContent-module_table__28VKr {\n min-width: 845px;\n }\n}\n\n.TableContent-module_tr__gIdML {\n min-height: 72px;\n}";
|
|
16
|
-
var styles = {"table":"TableContent-module_table__28VKr","tr":"TableContent-module_tr__gIdML"};
|
|
17
|
-
styleInject(css_248z);
|
|
18
|
-
|
|
19
|
-
var TableContent = function (_a) {
|
|
20
|
-
var className = _a.className, data = _a.data, hideHeader = _a.hideHeader, openModal = _a.openModal, title = _a.title, width = _a.width;
|
|
21
|
-
var headerRow = data === null || data === void 0 ? void 0 : data[0];
|
|
22
|
-
var getColumnContentByKey = useCallback(function (key) { var _a, _b; return ((_b = (_a = data === null || data === void 0 ? void 0 : data[0]) === null || _a === void 0 ? void 0 : _a[key]) === null || _b === void 0 ? void 0 : _b.content) || ''; }, [data]);
|
|
23
|
-
var handleOpenModal = function (_a) {
|
|
24
|
-
var cellIndex = _a.cellIndex, body = _a.body, title = _a.title;
|
|
25
|
-
return openModal === null || openModal === void 0 ? void 0 : openModal({
|
|
26
|
-
body: body,
|
|
27
|
-
title: title || getColumnContentByKey(cellIndex),
|
|
28
|
-
});
|
|
29
|
-
};
|
|
30
|
-
return (jsxs("table", { className: classNames(className, 'w100', styles.table), width: width, children: [jsx("caption", { className: "sr-only", children: title }), headerRow && (jsx("thead", { className: hideHeader ? 'sr-only' : '', children: jsx("tr", { children: headerRow.map(function (tableCellProps, cellIndex) {
|
|
31
|
-
var isFirstCellInRow = cellIndex === 0;
|
|
32
|
-
return (jsx(TableCell, __assign({ isHeader: true, isFirstCellInRow: isFirstCellInRow, isTopLeftCell: isFirstCellInRow, align: isFirstCellInRow ? 'left' : 'center', openModal: function (body) {
|
|
33
|
-
return handleOpenModal({
|
|
34
|
-
cellIndex: cellIndex,
|
|
35
|
-
body: body,
|
|
36
|
-
title: tableCellProps === null || tableCellProps === void 0 ? void 0 : tableCellProps.content,
|
|
37
|
-
});
|
|
38
|
-
} }, tableCellProps), cellIndex));
|
|
39
|
-
}) }) })), jsx("tbody", { children: data.map(function (row, rowIndex) {
|
|
40
|
-
var isSingleCell = row.length === 1;
|
|
41
|
-
return (rowIndex > 0 && (jsx("tr", { className: styles.tr, children: row.map(function (tableCellProps, cellIndex) {
|
|
42
|
-
var key = "".concat(rowIndex, "-").concat(cellIndex);
|
|
43
|
-
var isFirstCellInRow = cellIndex === 0;
|
|
44
|
-
var onCelInfoClick = function (body) {
|
|
45
|
-
return handleOpenModal({
|
|
46
|
-
cellIndex: cellIndex,
|
|
47
|
-
body: body,
|
|
48
|
-
title: isFirstCellInRow
|
|
49
|
-
? tableCellProps.content
|
|
50
|
-
: undefined,
|
|
51
|
-
});
|
|
52
|
-
};
|
|
53
|
-
return (jsx(TableCell, __assign({ align: isFirstCellInRow && !isSingleCell ? 'left' : 'center', isFirstCellInRow: isFirstCellInRow, openModal: onCelInfoClick }, tableCellProps), key));
|
|
54
|
-
}) }, rowIndex)));
|
|
55
|
-
}) })] }));
|
|
56
|
-
};
|
|
57
|
-
|
|
58
|
-
export { TableContent };
|
|
59
|
-
//# sourceMappingURL=TableContent.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"TableContent.js","sources":["../../../../../../../src/lib/components/table/components/TableContent/TableContent.tsx"],"sourcesContent":["import classNames from 'classnames';\n\nimport styles from './TableContent.module.scss';\nimport { TableCell, TableCellProps } from '../TableCell/TableCell';\nimport { ReactNode, useCallback } from 'react';\nimport { ModalData, ModalFunction } from '../../types';\n\nexport interface TableContentProps {\n className?: string;\n data: TableCellProps[][];\n hideHeader?: boolean;\n openModal?: ModalFunction;\n title: string;\n width?: number | string;\n}\n\nconst TableContent = ({\n className,\n data,\n hideHeader,\n openModal,\n title,\n width,\n}: TableContentProps) => {\n const headerRow = data?.[0];\n\n const getColumnContentByKey = useCallback(\n (key: number) => data?.[0]?.[key]?.content || '',\n [data]\n );\n\n const handleOpenModal = ({\n cellIndex,\n body,\n title,\n }: ModalData & {\n cellIndex: number;\n }) =>\n openModal?.({\n body,\n title: title || getColumnContentByKey(cellIndex),\n });\n\n return (\n <table\n className={classNames(className, 'w100', styles.table)}\n width={width}\n >\n <caption className=\"sr-only\">{title}</caption>\n\n {headerRow && (\n <thead className={hideHeader ? 'sr-only' : ''}>\n <tr>\n {headerRow.map((tableCellProps, cellIndex) => {\n const isFirstCellInRow = cellIndex === 0;\n return (\n <TableCell\n key={cellIndex}\n isHeader\n isFirstCellInRow={isFirstCellInRow}\n isTopLeftCell={isFirstCellInRow}\n align={isFirstCellInRow ? 'left' : 'center'}\n openModal={(body) =>\n handleOpenModal({\n cellIndex,\n body,\n title: tableCellProps?.content,\n })\n }\n {...tableCellProps}\n />\n );\n })}\n </tr>\n </thead>\n )}\n\n <tbody>\n {data.map((row, rowIndex) => {\n const isSingleCell = row.length === 1;\n\n return (\n rowIndex > 0 && (\n <tr key={rowIndex} className={styles.tr}>\n {row.map((tableCellProps, cellIndex) => {\n const key = `${rowIndex}-${cellIndex}`;\n const isFirstCellInRow = cellIndex === 0;\n\n const onCelInfoClick = (body: ReactNode) =>\n handleOpenModal({\n cellIndex,\n body,\n title: isFirstCellInRow\n ? tableCellProps.content\n : undefined,\n });\n\n return (\n <TableCell\n align={\n isFirstCellInRow && !isSingleCell ? 'left' : 'center'\n }\n isFirstCellInRow={isFirstCellInRow}\n openModal={onCelInfoClick}\n key={key}\n {...tableCellProps}\n />\n );\n })}\n </tr>\n )\n );\n })}\n </tbody>\n </table>\n );\n};\n\nexport type { TableCellProps };\n\nexport { TableContent };\n"],"names":["_jsxs","_jsx"],"mappings":";;;;;;;;;;;;;;;;;;IAgBM,YAAY,GAAG,UAAC,EAOF;QANlB,SAAS,eAAA,EACT,IAAI,UAAA,EACJ,UAAU,gBAAA,EACV,SAAS,eAAA,EACT,KAAK,WAAA,EACL,KAAK,WAAA;IAEL,IAAM,SAAS,GAAG,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAG,CAAC,CAAC,CAAC;IAE5B,IAAM,qBAAqB,GAAG,WAAW,CACvC,UAAC,GAAW,gBAAK,OAAA,CAAA,MAAA,MAAA,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAG,CAAC,CAAC,0CAAG,GAAG,CAAC,0CAAE,OAAO,KAAI,EAAE,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,CAAC,UAAC,cAAc,EAAE,SAAS;4BACjC,IAAM,GAAG,GAAG,UAAG,QAAQ,cAAI,SAAS,CAAE,CAAC;4BACvC,IAAM,gBAAgB,GAAG,SAAS,KAAK,CAAC,CAAC;4BAEzC,IAAM,cAAc,GAAG,UAAC,IAAe;gCACrC,OAAA,eAAe,CAAC;oCACd,SAAS,WAAA;oCACT,IAAI,MAAA;oCACJ,KAAK,EAAE,gBAAgB;0CACnB,cAAc,CAAC,OAAO;0CACtB,SAAS;iCACd,CAAC;6BAAA,CAAC;4BAEL,QACEA,IAAC,SAAS,aACR,KAAK,EACH,gBAAgB,IAAI,CAAC,YAAY,GAAG,MAAM,GAAG,QAAQ,EAEvD,gBAAgB,EAAE,gBAAgB,EAClC,SAAS,EAAE,cAAc,IAErB,cAAc,GADb,GAAG,CAER,EACF;yBACH,CAAC,IAzBK,QAAQ,CA0BZ,CACN,EACD;iBACH,CAAC,GACI,IACF,EACR;AACJ;;;;"}
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import { a as __assign } from '../../../../tslib.es6-a39f91fc.js';
|
|
2
|
-
import { jsx } from 'react/jsx-runtime';
|
|
3
|
-
import { c as customRender, s as screen } from '../../../../customRender-d03c10b6.js';
|
|
4
|
-
import { TableContent } from './TableContent.js';
|
|
5
|
-
import 'react';
|
|
6
|
-
import 'react-dom';
|
|
7
|
-
import '../../../../_commonjsHelpers-4730bd53.js';
|
|
8
|
-
import 'react-dom/test-utils';
|
|
9
|
-
import '../../../../index-6ea95111.js';
|
|
10
|
-
import '../../../../style-inject.es-1f59c1d0.js';
|
|
11
|
-
import '../TableCell/TableCell.js';
|
|
12
|
-
import '../../../button/index.js';
|
|
13
|
-
import '../../../icon/icons/Check.js';
|
|
14
|
-
import '../../../icon/IconWrapper/IconWrapper.js';
|
|
15
|
-
import '../../../icon/icons/Info.js';
|
|
16
|
-
import '../../../icon/icons/StarFilled.js';
|
|
17
|
-
import '../../../icon/icons/X.js';
|
|
18
|
-
import '../../../icon/icons/ZapFilled.js';
|
|
19
|
-
|
|
20
|
-
var mockData = [
|
|
21
|
-
[{ content: 'Cell 1.1' }, { content: 'Cell 1.2' }, { content: 'Cell 1.3' }],
|
|
22
|
-
[{ content: 'Cell 2.1' }, { content: 'Cell 2.2' }, { content: 'Cell 2.3' }],
|
|
23
|
-
];
|
|
24
|
-
var mockTitle = 'Test Table';
|
|
25
|
-
var mockOpenModal = jest.fn();
|
|
26
|
-
var defaultProps = {
|
|
27
|
-
data: mockData,
|
|
28
|
-
title: mockTitle,
|
|
29
|
-
openModal: mockOpenModal,
|
|
30
|
-
};
|
|
31
|
-
describe('TableContent', function () {
|
|
32
|
-
it('renders the table caption', function () {
|
|
33
|
-
customRender(jsx(TableContent, __assign({}, defaultProps)));
|
|
34
|
-
expect(screen.getByText(mockTitle)).toBeInTheDocument();
|
|
35
|
-
});
|
|
36
|
-
it('renders the table with correct data', function () {
|
|
37
|
-
customRender(jsx(TableContent, __assign({}, defaultProps)));
|
|
38
|
-
expect(screen.getByText('Cell 1.1')).toBeInTheDocument();
|
|
39
|
-
expect(screen.getByText('Cell 1.2')).toBeInTheDocument();
|
|
40
|
-
expect(screen.getByText('Cell 1.3')).toBeInTheDocument();
|
|
41
|
-
expect(screen.getByText('Cell 2.1')).toBeInTheDocument();
|
|
42
|
-
expect(screen.getByText('Cell 2.2')).toBeInTheDocument();
|
|
43
|
-
expect(screen.getByText('Cell 2.3')).toBeInTheDocument();
|
|
44
|
-
});
|
|
45
|
-
it('should render table headers', function () {
|
|
46
|
-
var container = customRender(jsx(TableContent, __assign({}, defaultProps))).container;
|
|
47
|
-
var thElements = container.querySelectorAll('th');
|
|
48
|
-
expect(thElements.length).toBe(4);
|
|
49
|
-
expect(thElements[0]).toHaveTextContent('Cell 1.1');
|
|
50
|
-
expect(thElements[3]).toHaveTextContent('Cell 2.1');
|
|
51
|
-
});
|
|
52
|
-
it('should render table data cells', function () {
|
|
53
|
-
var container = customRender(jsx(TableContent, __assign({}, defaultProps))).container;
|
|
54
|
-
var tdElements = container.querySelectorAll('td');
|
|
55
|
-
expect(tdElements.length).toBe(2);
|
|
56
|
-
expect(tdElements[0]).toHaveTextContent('Cell 2.2');
|
|
57
|
-
expect(tdElements[1]).toHaveTextContent('Cell 2.3');
|
|
58
|
-
});
|
|
59
|
-
});
|
|
60
|
-
//# sourceMappingURL=TableContent.test.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"TableContent.test.js","sources":["../../../../../../../src/lib/components/table/components/TableContent/TableContent.test.tsx"],"sourcesContent":["import { render, screen } from '../../../../util/testUtils';\nimport { TableContent, TableContentProps } from './TableContent';\n\nconst mockData: TableContentProps['data'] = [\n [{ content: 'Cell 1.1' }, { content: 'Cell 1.2' }, { content: 'Cell 1.3' }],\n [{ content: 'Cell 2.1' }, { content: 'Cell 2.2' }, { content: 'Cell 2.3' }],\n];\n\nconst mockTitle = 'Test Table';\n\nconst mockOpenModal = jest.fn();\n\nconst defaultProps: TableContentProps = {\n data: mockData,\n title: mockTitle,\n openModal: mockOpenModal,\n};\n\ndescribe('TableContent', () => {\n it('renders the table caption', () => {\n render(<TableContent {...defaultProps} />);\n\n expect(screen.getByText(mockTitle)).toBeInTheDocument();\n });\n\n it('renders the table with correct data', () => {\n render(<TableContent {...defaultProps} />);\n\n expect(screen.getByText('Cell 1.1')).toBeInTheDocument();\n expect(screen.getByText('Cell 1.2')).toBeInTheDocument();\n expect(screen.getByText('Cell 1.3')).toBeInTheDocument();\n\n expect(screen.getByText('Cell 2.1')).toBeInTheDocument();\n expect(screen.getByText('Cell 2.2')).toBeInTheDocument();\n expect(screen.getByText('Cell 2.3')).toBeInTheDocument();\n });\n\n it('should render table headers', () => {\n const { container } = render(<TableContent {...defaultProps} />);\n\n const thElements = container.querySelectorAll('th');\n\n expect(thElements.length).toBe(4);\n expect(thElements[0]).toHaveTextContent('Cell 1.1');\n expect(thElements[3]).toHaveTextContent('Cell 2.1');\n });\n\n it('should render table data cells', () => {\n const { container } = render(<TableContent {...defaultProps} />);\n\n const tdElements = container.querySelectorAll('td');\n expect(tdElements.length).toBe(2);\n expect(tdElements[0]).toHaveTextContent('Cell 2.2');\n expect(tdElements[1]).toHaveTextContent('Cell 2.3');\n });\n});\n"],"names":["render","_jsx"],"mappings":";;;;;;;;;;;;;;;;;;;AAGA,IAAM,QAAQ,GAA8B;IAC1C,CAAC,EAAE,OAAO,EAAE,UAAU,EAAE,EAAE,EAAE,OAAO,EAAE,UAAU,EAAE,EAAE,EAAE,OAAO,EAAE,UAAU,EAAE,CAAC;IAC3E,CAAC,EAAE,OAAO,EAAE,UAAU,EAAE,EAAE,EAAE,OAAO,EAAE,UAAU,EAAE,EAAE,EAAE,OAAO,EAAE,UAAU,EAAE,CAAC;CAC5E,CAAC;AAEF,IAAM,SAAS,GAAG,YAAY,CAAC;AAE/B,IAAM,aAAa,GAAG,IAAI,CAAC,EAAE,EAAE,CAAC;AAEhC,IAAM,YAAY,GAAsB;IACtC,IAAI,EAAE,QAAQ;IACd,KAAK,EAAE,SAAS;IAChB,SAAS,EAAE,aAAa;CACzB,CAAC;AAEF,QAAQ,CAAC,cAAc,EAAE;IACvB,EAAE,CAAC,2BAA2B,EAAE;QAC9BA,YAAM,CAACC,IAAC,YAAY,eAAK,YAAY,EAAI,CAAC,CAAC;QAE3C,MAAM,CAAC,MAAM,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC,CAAC,iBAAiB,EAAE,CAAC;KACzD,CAAC,CAAC;IAEH,EAAE,CAAC,qCAAqC,EAAE;QACxCD,YAAM,CAACC,IAAC,YAAY,eAAK,YAAY,EAAI,CAAC,CAAC;QAE3C,MAAM,CAAC,MAAM,CAAC,SAAS,CAAC,UAAU,CAAC,CAAC,CAAC,iBAAiB,EAAE,CAAC;QACzD,MAAM,CAAC,MAAM,CAAC,SAAS,CAAC,UAAU,CAAC,CAAC,CAAC,iBAAiB,EAAE,CAAC;QACzD,MAAM,CAAC,MAAM,CAAC,SAAS,CAAC,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D,CAAC,CAAC;AACL,CAAC,CAAC"}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { TableCellProps } from '../TableCell/TableCell';
|
|
2
|
-
import { ModalFunction } from '../../types';
|
|
3
|
-
export interface TableContentProps {
|
|
4
|
-
className?: string;
|
|
5
|
-
data: TableCellProps[][];
|
|
6
|
-
hideHeader?: boolean;
|
|
7
|
-
openModal?: ModalFunction;
|
|
8
|
-
title: string;
|
|
9
|
-
width?: number | string;
|
|
10
|
-
}
|
|
11
|
-
declare const TableContent: ({ className, data, hideHeader, openModal, title, width, }: TableContentProps) => JSX.Element;
|
|
12
|
-
export type { TableCellProps };
|
|
13
|
-
export { TableContent };
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
import { render, screen } from '../../../../util/testUtils';
|
|
2
|
-
import { TableContent, TableContentProps } from './TableContent';
|
|
3
|
-
|
|
4
|
-
const mockData: TableContentProps['data'] = [
|
|
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' }],
|
|
7
|
-
];
|
|
8
|
-
|
|
9
|
-
const mockTitle = 'Test Table';
|
|
10
|
-
|
|
11
|
-
const mockOpenModal = jest.fn();
|
|
12
|
-
|
|
13
|
-
const defaultProps: TableContentProps = {
|
|
14
|
-
data: mockData,
|
|
15
|
-
title: mockTitle,
|
|
16
|
-
openModal: mockOpenModal,
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
describe('TableContent', () => {
|
|
20
|
-
it('renders the table caption', () => {
|
|
21
|
-
render(<TableContent {...defaultProps} />);
|
|
22
|
-
|
|
23
|
-
expect(screen.getByText(mockTitle)).toBeInTheDocument();
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
it('renders the table with correct data', () => {
|
|
27
|
-
render(<TableContent {...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();
|
|
32
|
-
|
|
33
|
-
expect(screen.getByText('Cell 2.1')).toBeInTheDocument();
|
|
34
|
-
expect(screen.getByText('Cell 2.2')).toBeInTheDocument();
|
|
35
|
-
expect(screen.getByText('Cell 2.3')).toBeInTheDocument();
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
it('should render table headers', () => {
|
|
39
|
-
const { container } = render(<TableContent {...defaultProps} />);
|
|
40
|
-
|
|
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
|
-
});
|
|
47
|
-
|
|
48
|
-
it('should render table data cells', () => {
|
|
49
|
-
const { container } = render(<TableContent {...defaultProps} />);
|
|
50
|
-
|
|
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');
|
|
55
|
-
});
|
|
56
|
-
});
|
|
@@ -1,121 +0,0 @@
|
|
|
1
|
-
import classNames from 'classnames';
|
|
2
|
-
|
|
3
|
-
import styles from './TableContent.module.scss';
|
|
4
|
-
import { TableCell, TableCellProps } from '../TableCell/TableCell';
|
|
5
|
-
import { ReactNode, useCallback } from 'react';
|
|
6
|
-
import { ModalData, ModalFunction } from '../../types';
|
|
7
|
-
|
|
8
|
-
export interface TableContentProps {
|
|
9
|
-
className?: string;
|
|
10
|
-
data: TableCellProps[][];
|
|
11
|
-
hideHeader?: boolean;
|
|
12
|
-
openModal?: ModalFunction;
|
|
13
|
-
title: string;
|
|
14
|
-
width?: number | string;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
const TableContent = ({
|
|
18
|
-
className,
|
|
19
|
-
data,
|
|
20
|
-
hideHeader,
|
|
21
|
-
openModal,
|
|
22
|
-
title,
|
|
23
|
-
width,
|
|
24
|
-
}: TableContentProps) => {
|
|
25
|
-
const headerRow = data?.[0];
|
|
26
|
-
|
|
27
|
-
const getColumnContentByKey = useCallback(
|
|
28
|
-
(key: number) => data?.[0]?.[key]?.content || '',
|
|
29
|
-
[data]
|
|
30
|
-
);
|
|
31
|
-
|
|
32
|
-
const handleOpenModal = ({
|
|
33
|
-
cellIndex,
|
|
34
|
-
body,
|
|
35
|
-
title,
|
|
36
|
-
}: ModalData & {
|
|
37
|
-
cellIndex: number;
|
|
38
|
-
}) =>
|
|
39
|
-
openModal?.({
|
|
40
|
-
body,
|
|
41
|
-
title: title || getColumnContentByKey(cellIndex),
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
return (
|
|
45
|
-
<table
|
|
46
|
-
className={classNames(className, 'w100', styles.table)}
|
|
47
|
-
width={width}
|
|
48
|
-
>
|
|
49
|
-
<caption className="sr-only">{title}</caption>
|
|
50
|
-
|
|
51
|
-
{headerRow && (
|
|
52
|
-
<thead className={hideHeader ? 'sr-only' : ''}>
|
|
53
|
-
<tr>
|
|
54
|
-
{headerRow.map((tableCellProps, cellIndex) => {
|
|
55
|
-
const isFirstCellInRow = cellIndex === 0;
|
|
56
|
-
return (
|
|
57
|
-
<TableCell
|
|
58
|
-
key={cellIndex}
|
|
59
|
-
isHeader
|
|
60
|
-
isFirstCellInRow={isFirstCellInRow}
|
|
61
|
-
isTopLeftCell={isFirstCellInRow}
|
|
62
|
-
align={isFirstCellInRow ? 'left' : 'center'}
|
|
63
|
-
openModal={(body) =>
|
|
64
|
-
handleOpenModal({
|
|
65
|
-
cellIndex,
|
|
66
|
-
body,
|
|
67
|
-
title: tableCellProps?.content,
|
|
68
|
-
})
|
|
69
|
-
}
|
|
70
|
-
{...tableCellProps}
|
|
71
|
-
/>
|
|
72
|
-
);
|
|
73
|
-
})}
|
|
74
|
-
</tr>
|
|
75
|
-
</thead>
|
|
76
|
-
)}
|
|
77
|
-
|
|
78
|
-
<tbody>
|
|
79
|
-
{data.map((row, rowIndex) => {
|
|
80
|
-
const isSingleCell = row.length === 1;
|
|
81
|
-
|
|
82
|
-
return (
|
|
83
|
-
rowIndex > 0 && (
|
|
84
|
-
<tr key={rowIndex} className={styles.tr}>
|
|
85
|
-
{row.map((tableCellProps, cellIndex) => {
|
|
86
|
-
const key = `${rowIndex}-${cellIndex}`;
|
|
87
|
-
const isFirstCellInRow = cellIndex === 0;
|
|
88
|
-
|
|
89
|
-
const onCelInfoClick = (body: ReactNode) =>
|
|
90
|
-
handleOpenModal({
|
|
91
|
-
cellIndex,
|
|
92
|
-
body,
|
|
93
|
-
title: isFirstCellInRow
|
|
94
|
-
? tableCellProps.content
|
|
95
|
-
: undefined,
|
|
96
|
-
});
|
|
97
|
-
|
|
98
|
-
return (
|
|
99
|
-
<TableCell
|
|
100
|
-
align={
|
|
101
|
-
isFirstCellInRow && !isSingleCell ? 'left' : 'center'
|
|
102
|
-
}
|
|
103
|
-
isFirstCellInRow={isFirstCellInRow}
|
|
104
|
-
openModal={onCelInfoClick}
|
|
105
|
-
key={key}
|
|
106
|
-
{...tableCellProps}
|
|
107
|
-
/>
|
|
108
|
-
);
|
|
109
|
-
})}
|
|
110
|
-
</tr>
|
|
111
|
-
)
|
|
112
|
-
);
|
|
113
|
-
})}
|
|
114
|
-
</tbody>
|
|
115
|
-
</table>
|
|
116
|
-
);
|
|
117
|
-
};
|
|
118
|
-
|
|
119
|
-
export type { TableCellProps };
|
|
120
|
-
|
|
121
|
-
export { TableContent };
|
/package/dist/cjs/lib/components/table/components/{TableSection → TableContents}/Collapsible.d.ts
RENAMED
|
File without changes
|
|
File without changes
|
/package/dist/esm/components/table/components/{TableSection → TableContents}/Collapsible.js.map
RENAMED
|
File without changes
|
/package/dist/esm/lib/components/table/components/{TableSection → TableContents}/Collapsible.d.ts
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|