@sproutsocial/seeds-react-table 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintignore +6 -0
- package/.eslintrc.js +4 -0
- package/.turbo/turbo-build.log +53 -0
- package/CHANGELOG.md +7 -0
- package/dist/TableCell-B8GMRlv7.d.mts +13 -0
- package/dist/TableCell-CN71R1B5.d.ts +13 -0
- package/dist/TableCellTypes-Cp-8r7l1.d.mts +21 -0
- package/dist/TableCellTypes-Cp-8r7l1.d.ts +21 -0
- package/dist/TableHeaderCell-DnwlruQg.d.ts +12 -0
- package/dist/TableHeaderCell-DsJpGb2j.d.mts +12 -0
- package/dist/TableHeaderCellTypes-CH_zzW6X.d.ts +25 -0
- package/dist/TableHeaderCellTypes-CsJQBwu2.d.mts +25 -0
- package/dist/TableTypes-Dg7QrcGt.d.ts +37 -0
- package/dist/TableTypes-jS0O3bwQ.d.mts +37 -0
- package/dist/esm/chunk-67DCEN4G.js +140 -0
- package/dist/esm/chunk-67DCEN4G.js.map +1 -0
- package/dist/esm/chunk-XJMS6762.js +62 -0
- package/dist/esm/chunk-XJMS6762.js.map +1 -0
- package/dist/esm/index.js +106 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/tableCell.js +9 -0
- package/dist/esm/tableCell.js.map +1 -0
- package/dist/esm/tableHeaderCell.js +11 -0
- package/dist/esm/tableHeaderCell.js.map +1 -0
- package/dist/esm/tableRowAccordion.js +110 -0
- package/dist/esm/tableRowAccordion.js.map +1 -0
- package/dist/index.d.mts +32 -0
- package/dist/index.d.ts +32 -0
- package/dist/index.js +327 -0
- package/dist/index.js.map +1 -0
- package/dist/tableCell.d.mts +9 -0
- package/dist/tableCell.d.ts +9 -0
- package/dist/tableCell.js +98 -0
- package/dist/tableCell.js.map +1 -0
- package/dist/tableHeaderCell.d.mts +10 -0
- package/dist/tableHeaderCell.d.ts +10 -0
- package/dist/tableHeaderCell.js +177 -0
- package/dist/tableHeaderCell.js.map +1 -0
- package/dist/tableRowAccordion.d.mts +25 -0
- package/dist/tableRowAccordion.d.ts +25 -0
- package/dist/tableRowAccordion.js +200 -0
- package/dist/tableRowAccordion.js.map +1 -0
- package/jest.config.js +9 -0
- package/package.json +65 -0
- package/src/Table.stories.tsx +403 -0
- package/src/Table.tsx +111 -0
- package/src/TableCell/TableCell.stories.tsx +30 -0
- package/src/TableCell/TableCell.tsx +44 -0
- package/src/TableCell/TableCellTypes.ts +30 -0
- package/src/TableCell/__tests__/TabelCell.test.tsx +36 -0
- package/src/TableCell/__tests__/TableCell.typetest.tsx +34 -0
- package/src/TableCell/index.ts +5 -0
- package/src/TableCell/styles.ts +16 -0
- package/src/TableHeaderCell/TableHeaderCell.stories.tsx +46 -0
- package/src/TableHeaderCell/TableHeaderCell.tsx +120 -0
- package/src/TableHeaderCell/TableHeaderCellTypes.ts +26 -0
- package/src/TableHeaderCell/__tests__/TableHeaderCell.test.tsx +28 -0
- package/src/TableHeaderCell/__tests__/TableHeaderCell.typetest.tsx +31 -0
- package/src/TableHeaderCell/constants.ts +4 -0
- package/src/TableHeaderCell/index.ts +6 -0
- package/src/TableHeaderCell/styles.ts +46 -0
- package/src/TableRowAccordion/TableRowAccordion.stories.tsx +63 -0
- package/src/TableRowAccordion/TableRowAccordion.tsx +75 -0
- package/src/TableRowAccordion/TableRowAccordionTypes.ts +20 -0
- package/src/TableRowAccordion/__tests__/TableRowAccordion.test.tsx +104 -0
- package/src/TableRowAccordion/__tests__/TableRowAccordion.typetest.tsx +51 -0
- package/src/TableRowAccordion/index.ts +5 -0
- package/src/TableRowAccordion/styles.ts +25 -0
- package/src/TableTypes.ts +54 -0
- package/src/__tests__/Table.test.tsx +106 -0
- package/src/__tests__/Table.typetest.tsx +145 -0
- package/src/index.ts +5 -0
- package/src/styles.ts +21 -0
- package/styled.d.ts +7 -0
- package/tsconfig.json +9 -0
- package/tsup.config.ts +17 -0
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import TableRowAccordion from "../TableRowAccordion";
|
|
3
|
+
|
|
4
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
5
|
+
function TableRowAccordionTypes() {
|
|
6
|
+
const testCells = [
|
|
7
|
+
{
|
|
8
|
+
id: "1",
|
|
9
|
+
content: "🍔 Bacon Smokehouse Burger",
|
|
10
|
+
},
|
|
11
|
+
{
|
|
12
|
+
id: "2",
|
|
13
|
+
content: "840",
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
id: "3",
|
|
17
|
+
content: "45g",
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
id: "4",
|
|
21
|
+
content: "62g",
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
id: "5",
|
|
25
|
+
content: "46g",
|
|
26
|
+
},
|
|
27
|
+
];
|
|
28
|
+
|
|
29
|
+
const testDetail = (
|
|
30
|
+
<img
|
|
31
|
+
src="//i.kym-cdn.com/entries/icons/mobile/000/013/564/doge.jpg"
|
|
32
|
+
alt="doge"
|
|
33
|
+
/>
|
|
34
|
+
);
|
|
35
|
+
|
|
36
|
+
const defaultProps = {
|
|
37
|
+
id: "1",
|
|
38
|
+
cells: testCells,
|
|
39
|
+
detail: testDetail,
|
|
40
|
+
onToggle: jest.fn(),
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
return (
|
|
44
|
+
<>
|
|
45
|
+
<TableRowAccordion {...defaultProps} isExpanded />
|
|
46
|
+
<TableRowAccordion {...defaultProps} isExpanded={false} />
|
|
47
|
+
{/* @ts-expect-error - test that missing required props is rejected */}
|
|
48
|
+
<TableRowAccordion />
|
|
49
|
+
</>
|
|
50
|
+
);
|
|
51
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import styled, { css } from "styled-components";
|
|
2
|
+
import { COMMON } from "@sproutsocial/seeds-react-system-props";
|
|
3
|
+
|
|
4
|
+
const Container = styled.tbody`
|
|
5
|
+
border-bottom: 1px solid
|
|
6
|
+
${(props) => props.theme.colors.container.border.base};
|
|
7
|
+
|
|
8
|
+
${COMMON}
|
|
9
|
+
`;
|
|
10
|
+
|
|
11
|
+
export const Detail = styled.tr<{ isExpanded: boolean }>`
|
|
12
|
+
display: none;
|
|
13
|
+
|
|
14
|
+
${(props) =>
|
|
15
|
+
props.isExpanded &&
|
|
16
|
+
css`
|
|
17
|
+
display: table-row;
|
|
18
|
+
`}
|
|
19
|
+
`;
|
|
20
|
+
|
|
21
|
+
export const Trigger = styled.div`
|
|
22
|
+
cursor: pointer;
|
|
23
|
+
`;
|
|
24
|
+
|
|
25
|
+
export default Container;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import type {
|
|
3
|
+
TypeEnumSortDirections,
|
|
4
|
+
TypeTableHeaderCellProps,
|
|
5
|
+
} from "./TableHeaderCell";
|
|
6
|
+
import type { TypeTableCellProps } from "./TableCell/TableCellTypes";
|
|
7
|
+
import type { TypeSystemCommonProps } from "@sproutsocial/seeds-react-system-props";
|
|
8
|
+
|
|
9
|
+
export interface TypePassthroughProps {
|
|
10
|
+
children: React.ReactNode;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export interface TypeTableRow {
|
|
14
|
+
/** Table Row Id */
|
|
15
|
+
id: string;
|
|
16
|
+
|
|
17
|
+
/** Array for TableCells to render */
|
|
18
|
+
cells: TypeTableCellProps[];
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// eslint-disable-next-line @typescript-eslint/no-empty-interface
|
|
22
|
+
export interface TypeTableHeadProp
|
|
23
|
+
extends Omit<
|
|
24
|
+
TypeTableHeaderCellProps,
|
|
25
|
+
"onSort" | "sortId" | "sortDirection"
|
|
26
|
+
> {}
|
|
27
|
+
|
|
28
|
+
export interface TypeTableProps
|
|
29
|
+
extends TypeSystemCommonProps,
|
|
30
|
+
Omit<React.ComponentPropsWithoutRef<"table">, keyof TypeSystemCommonProps> {
|
|
31
|
+
/** Array of TableHeaderCells to render */
|
|
32
|
+
head?: TypeTableHeadProp[];
|
|
33
|
+
|
|
34
|
+
/** Array of TableRows to render */
|
|
35
|
+
rows?: TypeTableRow[];
|
|
36
|
+
|
|
37
|
+
/** Callback for Sorting Table Columns (optional) */
|
|
38
|
+
onSort?: (id: string) => void;
|
|
39
|
+
|
|
40
|
+
/** Controls which column is being sorted (optional) */
|
|
41
|
+
sortId?: string;
|
|
42
|
+
|
|
43
|
+
/** Controls the current sort direction (optional) */
|
|
44
|
+
sortDirection?: TypeEnumSortDirections;
|
|
45
|
+
|
|
46
|
+
/** Custom row render for flexibilty */
|
|
47
|
+
rowRender?: (row: TypeTableRow) => React.ReactNode;
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Including children will overwrite all head, rows, rowRender, and sorting props
|
|
51
|
+
* Should be used for manually rendering tables and ignoring data props
|
|
52
|
+
*/
|
|
53
|
+
children?: React.ReactNode;
|
|
54
|
+
}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import {
|
|
3
|
+
render,
|
|
4
|
+
fireEvent,
|
|
5
|
+
screen,
|
|
6
|
+
} from "@sproutsocial/seeds-react-testing-library";
|
|
7
|
+
import { Table } from "../Table";
|
|
8
|
+
describe("The Table Component", () => {
|
|
9
|
+
it("renders table headers", () => {
|
|
10
|
+
render(
|
|
11
|
+
<Table
|
|
12
|
+
head={[
|
|
13
|
+
{
|
|
14
|
+
id: "food_item",
|
|
15
|
+
content: "Food Item",
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
id: "calories",
|
|
19
|
+
content: "Calories",
|
|
20
|
+
},
|
|
21
|
+
]}
|
|
22
|
+
/>
|
|
23
|
+
);
|
|
24
|
+
expect(
|
|
25
|
+
screen.getAllByDataQaLabel({
|
|
26
|
+
"table-header-cell": "",
|
|
27
|
+
})
|
|
28
|
+
).toBeTruthy();
|
|
29
|
+
expect(
|
|
30
|
+
screen.getAllByDataQaLabel({
|
|
31
|
+
"table-header-cell": "",
|
|
32
|
+
}).length
|
|
33
|
+
).toEqual(2);
|
|
34
|
+
});
|
|
35
|
+
it("renders table rows and cells", () => {
|
|
36
|
+
render(
|
|
37
|
+
<Table
|
|
38
|
+
rows={[
|
|
39
|
+
{
|
|
40
|
+
id: "1",
|
|
41
|
+
cells: [
|
|
42
|
+
{
|
|
43
|
+
id: "1",
|
|
44
|
+
content: "Bacon Smokehouse Burger",
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
id: "2",
|
|
48
|
+
content: "62g",
|
|
49
|
+
},
|
|
50
|
+
],
|
|
51
|
+
},
|
|
52
|
+
]}
|
|
53
|
+
/>
|
|
54
|
+
);
|
|
55
|
+
const allRows = screen.getAllByDataQaLabel({
|
|
56
|
+
"table-row": "",
|
|
57
|
+
});
|
|
58
|
+
const allCells = screen.getAllByDataQaLabel({
|
|
59
|
+
"table-cell": "",
|
|
60
|
+
});
|
|
61
|
+
expect(allRows).toBeTruthy();
|
|
62
|
+
expect(allRows.length).toEqual(1);
|
|
63
|
+
expect(allCells).toBeTruthy();
|
|
64
|
+
expect(allCells.length).toEqual(2);
|
|
65
|
+
});
|
|
66
|
+
it("allows for table headers to be sortable", () => {
|
|
67
|
+
const callback = jest.fn();
|
|
68
|
+
render(
|
|
69
|
+
<Table
|
|
70
|
+
head={[
|
|
71
|
+
{
|
|
72
|
+
id: "food_item",
|
|
73
|
+
content: "Food Item",
|
|
74
|
+
isSortable: true,
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
id: "calories",
|
|
78
|
+
content: "Calories",
|
|
79
|
+
},
|
|
80
|
+
]}
|
|
81
|
+
onSort={callback}
|
|
82
|
+
sortId={undefined}
|
|
83
|
+
sortDirection="ASC"
|
|
84
|
+
/>
|
|
85
|
+
);
|
|
86
|
+
fireEvent.click(
|
|
87
|
+
// @ts-ignore - data-qa-label is a custom attribute
|
|
88
|
+
screen.getAllByDataQaLabel({
|
|
89
|
+
"table-header-cell": "",
|
|
90
|
+
})[0]
|
|
91
|
+
);
|
|
92
|
+
expect(callback).toBeCalledWith("food_item");
|
|
93
|
+
});
|
|
94
|
+
it("renders the children if present", () => {
|
|
95
|
+
render(
|
|
96
|
+
<Table>
|
|
97
|
+
<tbody>
|
|
98
|
+
<tr>
|
|
99
|
+
<td>Child</td>
|
|
100
|
+
</tr>
|
|
101
|
+
</tbody>
|
|
102
|
+
</Table>
|
|
103
|
+
);
|
|
104
|
+
expect(screen.getByText("Child")).toBeInTheDocument();
|
|
105
|
+
});
|
|
106
|
+
});
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { Table } from "../Table";
|
|
3
|
+
import TableRowAccordion from "../TableRowAccordion";
|
|
4
|
+
import { SORT_DIRECTIONS } from "../TableHeaderCell/constants";
|
|
5
|
+
|
|
6
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
7
|
+
function TableTypes() {
|
|
8
|
+
const columns = [
|
|
9
|
+
{
|
|
10
|
+
id: "1",
|
|
11
|
+
content: "Food Item",
|
|
12
|
+
},
|
|
13
|
+
{
|
|
14
|
+
id: "2",
|
|
15
|
+
content: "Calories",
|
|
16
|
+
isSortable: true,
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
id: "3",
|
|
20
|
+
content: "Total Fat: (69% DV*)",
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
id: "4",
|
|
24
|
+
content: "Total Carbs: (21% DV*)",
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
id: "5",
|
|
28
|
+
content: "Protein",
|
|
29
|
+
},
|
|
30
|
+
];
|
|
31
|
+
|
|
32
|
+
const rows = [
|
|
33
|
+
{
|
|
34
|
+
id: "baconsmokehouse",
|
|
35
|
+
cells: [
|
|
36
|
+
{
|
|
37
|
+
id: "1",
|
|
38
|
+
content: "🍔 Bacon Smokehouse Burger",
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
id: "2",
|
|
42
|
+
content: "840",
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
id: "3",
|
|
46
|
+
content: "45g",
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
id: "4",
|
|
50
|
+
content: "62g",
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
id: "5",
|
|
54
|
+
content: "46g",
|
|
55
|
+
},
|
|
56
|
+
],
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
id: "Big-Mac",
|
|
60
|
+
cells: [
|
|
61
|
+
{
|
|
62
|
+
id: "1",
|
|
63
|
+
content: "🍔 Big Mac",
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
id: "2",
|
|
67
|
+
content: "540",
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
id: "3",
|
|
71
|
+
content: "28g",
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
id: "4",
|
|
75
|
+
content: "46g",
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
id: "5",
|
|
79
|
+
content: "25g",
|
|
80
|
+
},
|
|
81
|
+
],
|
|
82
|
+
},
|
|
83
|
+
];
|
|
84
|
+
|
|
85
|
+
// @ts-ignore - I'm not sure what this is supposed to be
|
|
86
|
+
const testCustomRow = (row) => {
|
|
87
|
+
return (
|
|
88
|
+
<TableRowAccordion
|
|
89
|
+
key={row.id}
|
|
90
|
+
id={row.id}
|
|
91
|
+
cells={row.cells}
|
|
92
|
+
isExpanded={row.id === "baconsmokehouse"}
|
|
93
|
+
onToggle={jest.fn()}
|
|
94
|
+
detail={
|
|
95
|
+
row.id === "baconsmokehouse" ? (
|
|
96
|
+
<img
|
|
97
|
+
width="100%"
|
|
98
|
+
src="https://www.mcdonalds.com/content/dam/usa/nutrition/items/hero/desktop/t-mcdonalds-baconsmokehouse.jpg"
|
|
99
|
+
alt="doge"
|
|
100
|
+
/>
|
|
101
|
+
) : (
|
|
102
|
+
<img
|
|
103
|
+
width="100%"
|
|
104
|
+
src="https://www.mcdonalds.com/content/dam/usa/nutrition/items/hero/desktop/t-mcdonalds-Big-Mac.jpg"
|
|
105
|
+
alt="doge"
|
|
106
|
+
/>
|
|
107
|
+
)
|
|
108
|
+
}
|
|
109
|
+
/>
|
|
110
|
+
);
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
return (
|
|
114
|
+
<>
|
|
115
|
+
<Table head={columns} rows={rows} rowRender={testCustomRow} />
|
|
116
|
+
<Table
|
|
117
|
+
head={columns}
|
|
118
|
+
rows={rows}
|
|
119
|
+
onSort={jest.fn()}
|
|
120
|
+
sortDirection={SORT_DIRECTIONS.ASC}
|
|
121
|
+
sortId="2"
|
|
122
|
+
/>
|
|
123
|
+
<Table>
|
|
124
|
+
<Table.TableHead>
|
|
125
|
+
<Table.TableRow>
|
|
126
|
+
{columns.map(({ id, content }) => (
|
|
127
|
+
<Table.HeaderCell id={id}>{content} </Table.HeaderCell>
|
|
128
|
+
))}
|
|
129
|
+
</Table.TableRow>
|
|
130
|
+
</Table.TableHead>
|
|
131
|
+
<Table.TableBody>
|
|
132
|
+
{rows.map(({ cells }) => (
|
|
133
|
+
<Table.TableRow>
|
|
134
|
+
{cells.map(({ id, content }) => (
|
|
135
|
+
<Table.Cell id={id}>{content} </Table.Cell>
|
|
136
|
+
))}
|
|
137
|
+
</Table.TableRow>
|
|
138
|
+
))}
|
|
139
|
+
</Table.TableBody>
|
|
140
|
+
</Table>
|
|
141
|
+
{/* @ts-expect-error - test that invalid head is rejected */}
|
|
142
|
+
<Table head="invalid" />
|
|
143
|
+
</>
|
|
144
|
+
);
|
|
145
|
+
}
|
package/src/index.ts
ADDED
package/src/styles.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import styled from "styled-components";
|
|
2
|
+
import { COMMON } from "@sproutsocial/seeds-react-system-props";
|
|
3
|
+
|
|
4
|
+
const Container = styled.table`
|
|
5
|
+
width: 100%;
|
|
6
|
+
border-collapse: collapse;
|
|
7
|
+
|
|
8
|
+
thead {
|
|
9
|
+
vertical-align: bottom;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
tr,
|
|
13
|
+
thead {
|
|
14
|
+
border-bottom: 1px solid
|
|
15
|
+
${(props) => props.theme.colors.container.border.base};
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
${COMMON}
|
|
19
|
+
`;
|
|
20
|
+
|
|
21
|
+
export default Container;
|
package/styled.d.ts
ADDED
package/tsconfig.json
ADDED
package/tsup.config.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { defineConfig } from "tsup";
|
|
2
|
+
|
|
3
|
+
export default defineConfig((options) => ({
|
|
4
|
+
entry: {
|
|
5
|
+
index: "src/index.ts",
|
|
6
|
+
tableCell: "src/TableCell/index.ts",
|
|
7
|
+
tableHeaderCell: "src/TableHeaderCell/index.ts",
|
|
8
|
+
tableRowAccordion: "src/TableRowAccordion/index.ts",
|
|
9
|
+
},
|
|
10
|
+
format: ["cjs", "esm"],
|
|
11
|
+
clean: true,
|
|
12
|
+
legacyOutput: true,
|
|
13
|
+
dts: options.dts,
|
|
14
|
+
external: ["react"],
|
|
15
|
+
sourcemap: true,
|
|
16
|
+
metafile: options.metafile,
|
|
17
|
+
}));
|