@sb1/ffe-tables-react 9.0.0 → 10.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.
Files changed (54) hide show
  1. package/es/CellContent.js +28 -0
  2. package/es/Table.js +15 -84
  3. package/es/TableBody.js +28 -0
  4. package/es/TableCaption.js +28 -0
  5. package/es/TableContext.js +34 -0
  6. package/es/TableDataCell.js +30 -0
  7. package/es/TableFoot.js +28 -0
  8. package/es/TableHead.js +28 -0
  9. package/es/TableHeaderCell.js +51 -0
  10. package/es/TableRow.js +28 -0
  11. package/es/TableRowExpandable.js +62 -0
  12. package/es/index.js +9 -2
  13. package/es/texts.js +13 -0
  14. package/es/types.js +1 -0
  15. package/lib/CellContent.js +35 -0
  16. package/lib/Table.js +16 -84
  17. package/lib/TableBody.js +35 -0
  18. package/lib/TableCaption.js +34 -0
  19. package/lib/TableContext.js +61 -0
  20. package/lib/TableDataCell.js +36 -0
  21. package/lib/TableFoot.js +35 -0
  22. package/lib/TableHead.js +35 -0
  23. package/lib/TableHeaderCell.js +80 -0
  24. package/lib/TableRow.js +34 -0
  25. package/lib/TableRowExpandable.js +91 -0
  26. package/lib/index.js +19 -5
  27. package/lib/texts.js +16 -0
  28. package/lib/types.js +4 -0
  29. package/package.json +7 -11
  30. package/es/DefaultTable/DefaultTable.js +0 -154
  31. package/es/DefaultTable/DefaultTable.spec.js +0 -414
  32. package/es/SortableTable/SortableTable.js +0 -141
  33. package/es/SortableTable/SortableTable.spec.js +0 -62
  34. package/es/SortableTable/sort-data.js +0 -31
  35. package/es/SortableTable/sort-data.spec.js +0 -53
  36. package/es/TableParts/TableCell.js +0 -26
  37. package/es/TableParts/TableFooter.js +0 -69
  38. package/es/TableParts/TableHeaders.js +0 -58
  39. package/es/TableParts/TableRow.js +0 -61
  40. package/es/TableParts/TableRowExpandable.js +0 -102
  41. package/es/TableParts/TableRowExpandable.spec.js +0 -65
  42. package/lib/DefaultTable/DefaultTable.js +0 -182
  43. package/lib/DefaultTable/DefaultTable.spec.js +0 -419
  44. package/lib/SortableTable/SortableTable.js +0 -169
  45. package/lib/SortableTable/SortableTable.spec.js +0 -67
  46. package/lib/SortableTable/sort-data.js +0 -33
  47. package/lib/SortableTable/sort-data.spec.js +0 -58
  48. package/lib/TableParts/TableCell.js +0 -31
  49. package/lib/TableParts/TableFooter.js +0 -74
  50. package/lib/TableParts/TableHeaders.js +0 -63
  51. package/lib/TableParts/TableRow.js +0 -66
  52. package/lib/TableParts/TableRowExpandable.js +0 -130
  53. package/lib/TableParts/TableRowExpandable.spec.js +0 -70
  54. package/types/index.d.ts +0 -133
@@ -1,141 +0,0 @@
1
- var __extends = (this && this.__extends) || (function () {
2
- var extendStatics = function (d, b) {
3
- extendStatics = Object.setPrototypeOf ||
4
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
5
- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
6
- return extendStatics(d, b);
7
- };
8
- return function (d, b) {
9
- if (typeof b !== "function" && b !== null)
10
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
11
- extendStatics(d, b);
12
- function __() { this.constructor = d; }
13
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
14
- };
15
- })();
16
- var __assign = (this && this.__assign) || function () {
17
- __assign = Object.assign || function(t) {
18
- for (var s, i = 1, n = arguments.length; i < n; i++) {
19
- s = arguments[i];
20
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
21
- t[p] = s[p];
22
- }
23
- return t;
24
- };
25
- return __assign.apply(this, arguments);
26
- };
27
- import { Icon } from '@sb1/ffe-icons-react';
28
- import classNames from 'classnames';
29
- import equal from 'deep-equal';
30
- import PropTypes from 'prop-types';
31
- import React, { Component } from 'react';
32
- import Table from '../Table';
33
- import sortData from './sort-data';
34
- import memoize from 'memoize-one';
35
- var SortableTable = /** @class */ (function (_super) {
36
- __extends(SortableTable, _super);
37
- function SortableTable(props) {
38
- var _this = _super.call(this, props) || this;
39
- _this.sort = function (columns, data, sortBy, descending) {
40
- var _a = _this.props.onSort, onSort = _a === void 0 ? function () { } : _a;
41
- var tableData = sortData(columns, data, sortBy, descending);
42
- onSort({
43
- sortBy: sortBy,
44
- descending: descending,
45
- tableData: tableData,
46
- });
47
- return tableData;
48
- };
49
- _this.sortTableData = memoize(function (columns, data, sortBy, descending) {
50
- return sortBy ? _this.sort(columns, data, sortBy, descending) : data;
51
- });
52
- var sortBy = props.sortBy, _a = props.descending, descending = _a === void 0 ? false : _a;
53
- _this.state = {
54
- sortBy: sortBy,
55
- descending: descending,
56
- };
57
- return _this;
58
- }
59
- SortableTable.prototype.sortStateHasChanged = function (nextState) {
60
- return (nextState.sortBy !== this.state.sortBy ||
61
- nextState.descending !== this.state.descending);
62
- };
63
- SortableTable.prototype.shouldComponentUpdate = function (nextProps, nextState) {
64
- return (!equal(nextProps, this.props) || this.sortStateHasChanged(nextState));
65
- };
66
- SortableTable.prototype.tableHeaderClicked = function (columnKey) {
67
- this.setState(function (prevState) {
68
- var descending = columnKey === prevState.sortBy ? !prevState.descending : false;
69
- return {
70
- sortBy: columnKey,
71
- descending: descending,
72
- };
73
- });
74
- };
75
- SortableTable.prototype.handleKeyPress = function (columnKey, event) {
76
- if (event.key === 'Enter' || event.key === ' ') {
77
- this.tableHeaderClicked(columnKey);
78
- event.preventDefault();
79
- }
80
- };
81
- SortableTable.prototype.getAriaSort = function (column) {
82
- if (this.state.sortBy !== column.key) {
83
- return 'none';
84
- }
85
- return this.state.descending ? 'descending' : 'ascending';
86
- };
87
- SortableTable.prototype.decorateSortableTableHeader = function (column) {
88
- var _this = this;
89
- if (column.header === '') {
90
- return React.createElement("span", { className: "ffe-sortable-table__header" });
91
- }
92
- if (column.notSortable) {
93
- return column.header;
94
- }
95
- return (React.createElement("span", { tabIndex: "0", onKeyDown: function (event) { return _this.handleKeyPress(column.key, event); }, className: classNames('ffe-sortable-table__header', {
96
- 'ffe-sortable-table__header--active': this.state.sortBy === column.key,
97
- }), role: "button", onClick: this.tableHeaderClicked.bind(this, column.key) },
98
- column.header,
99
- React.createElement(Icon, { className: classNames('icon', 'ffe-sortable-table__sort-arrow', {
100
- 'ffe-sortable-table__sort-arrow--descending': this.state.sortBy === column.key &&
101
- this.state.descending,
102
- }), fileUrl: "data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIGhlaWdodD0iMjQiIHZpZXdCb3g9IjAgLTk2MCA5NjAgOTYwIiB3aWR0aD0iMjQiPjxwYXRoIGQ9Ik00NjAuODA4LTM5My4wNCAzMzQuNzYzLTUxOS4wODRxLTIuNjA4LTIuNjA4LTQuMTA4LTUuODI0LTEuNS0zLjIxNy0xLjUtNi44OTMgMC03LjM1MiA0Ljk3Mi0xMi43NzUgNC45NzEtNS40MjMgMTMuMTA1LTUuNDIzaDI2NS41MzZxOC4xMzQgMCAxMy4xMDUgNS40NzUgNC45NzIgNS40NzYgNC45NzIgMTIuNzc2IDAgMS44MjYtNS42MTYgMTIuNjcyTDQ5OS4xOTItMzkzLjAzOXEtNC4zNDYgNC4zNDYtOC45ODUgNi4zNDYtNC42NCAyLTEwLjIwNyAyLTUuNTY3IDAtMTAuMjA3LTItNC42MzktMi04Ljk4NS02LjM0N1oiLz48L3N2Zz4=", size: "md" })));
103
- };
104
- SortableTable.prototype.render = function () {
105
- var _this = this;
106
- var sortableColumns = this.props.columns.map(function (column) {
107
- return __assign(__assign({}, column), { ariaSort: _this.getAriaSort(column), header: _this.decorateSortableTableHeader(column) });
108
- });
109
- var caption = this.props.caption;
110
- var _a = this.props, expandedContentMapper = _a.expandedContentMapper, condensed = _a.condensed, columnLayoutMobile = _a.columnLayoutMobile, smallHeader = _a.smallHeader, alignLeft = _a.alignLeft, breakpoint = _a.breakpoint, limit = _a.limit, offset = _a.offset, srOnlyCaption = _a.srOnlyCaption, className = _a.className, rowRender = _a.rowRender, headerRender = _a.headerRender, footerRender = _a.footerRender, columns = _a.columns, data = _a.data;
111
- var _b = this.state, sortBy = _b.sortBy, descending = _b.descending;
112
- if (srOnlyCaption && sortBy) {
113
- caption = caption.concat(' ', sortBy, ' ', descending ? 'descending' : 'ascending');
114
- }
115
- var tableData = this.sortTableData(columns, data, sortBy, descending);
116
- return (React.createElement(Table, { caption: caption, srOnlyCaption: srOnlyCaption, expandedContentMapper: expandedContentMapper, columnLayoutMobile: columnLayoutMobile, columns: sortableColumns, data: tableData, condensed: condensed, smallHeader: smallHeader, alignLeft: alignLeft, breakpoint: breakpoint, limit: limit, offset: offset, sort: { sortBy: sortBy, descending: descending }, className: className, rowRender: rowRender, headerRender: headerRender, footerRender: footerRender }));
117
- };
118
- return SortableTable;
119
- }(Component));
120
- SortableTable.propTypes = {
121
- caption: PropTypes.node,
122
- srOnlyCaption: PropTypes.bool,
123
- expandedContentMapper: PropTypes.func,
124
- offset: PropTypes.number,
125
- limit: PropTypes.number,
126
- columnLayoutMobile: PropTypes.bool,
127
- condensed: PropTypes.bool,
128
- smallHeader: PropTypes.bool,
129
- alignLeft: PropTypes.bool,
130
- breakpoint: PropTypes.oneOf(['sm', 'none']),
131
- columns: PropTypes.arrayOf(PropTypes.object).isRequired,
132
- data: PropTypes.arrayOf(PropTypes.object).isRequired,
133
- sortBy: PropTypes.string,
134
- descending: PropTypes.bool,
135
- onSort: PropTypes.func,
136
- rowRender: PropTypes.func,
137
- headerRender: PropTypes.func,
138
- footerRender: PropTypes.func,
139
- className: PropTypes.string,
140
- };
141
- export default SortableTable;
@@ -1,62 +0,0 @@
1
- import React from 'react';
2
- import SortableTable from './SortableTable';
3
- import { render, screen } from '@testing-library/react';
4
- describe('<SortableTable>', function () {
5
- var columns = [
6
- { header: 'Name', key: 'name' },
7
- { header: 'Age', key: 'age' },
8
- { header: 'Employee-id', key: 'id' },
9
- { header: '', key: 'button' },
10
- ];
11
- var data = [
12
- {
13
- name: 'Zombie Mountain',
14
- age: 36,
15
- id: 2,
16
- button: React.createElement("button", null, "poke"),
17
- },
18
- {
19
- name: 'Daenerys Targaryen',
20
- age: 16,
21
- id: 4,
22
- button: React.createElement("button", null, "poke"),
23
- },
24
- { name: 'Ned Stark', age: 48, id: 3, button: React.createElement("button", null, "poke") },
25
- { name: 'Jon Snow', age: 20, id: 1, button: React.createElement("button", null, "poke") },
26
- ];
27
- it('should show right amount of th tags', function () {
28
- render(React.createElement(SortableTable, { columns: columns, data: data }));
29
- expect(screen.getAllByRole('columnheader')).toHaveLength(columns.length);
30
- });
31
- it('should render a row for each data array entry', function () {
32
- var container = render(React.createElement(SortableTable, { columns: columns, data: data })).container;
33
- expect(container.querySelectorAll('tbody tr')).toHaveLength(data.length);
34
- });
35
- it('should set data-th property on each cell rendered', function () {
36
- var container = render(React.createElement(SortableTable, { columns: columns, data: data })).container;
37
- expect(container.querySelectorAll('[data-th]')).toHaveLength(data.length * columns.length);
38
- });
39
- it('should add `aria-sort` property', function () {
40
- var container = render(React.createElement(SortableTable, { columns: columns, data: data })).container;
41
- expect(container.querySelectorAll('[aria-sort]')).toHaveLength(columns.length);
42
- });
43
- it('should not show sorting arrow if header is blank string', function () {
44
- var container = render(React.createElement(SortableTable, { columns: columns, data: data })).container;
45
- expect(container.querySelectorAll('.ffe-sortable-table__sort-arrow')
46
- .length).toBe(columns.length - 1);
47
- });
48
- it('should show buttons in table when passing in buttons in data', function () {
49
- var container = render(React.createElement(SortableTable, { columns: columns, data: data })).container;
50
- expect(container.querySelectorAll('button').length).toBe(data.length);
51
- });
52
- describe('condensed', function () {
53
- it('should by default not be condensed', function () {
54
- var container = render(React.createElement(SortableTable, { columns: columns, data: data })).container;
55
- expect(container.querySelectorAll('.ffe-table--condensed')).toHaveLength(0);
56
- });
57
- it('can be condensed', function () {
58
- var container = render(React.createElement(SortableTable, { condensed: true, columns: columns, data: data })).container;
59
- expect(container.querySelectorAll('.ffe-table--condensed')).toHaveLength(1);
60
- });
61
- });
62
- });
@@ -1,31 +0,0 @@
1
- var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
2
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
3
- if (ar || !(i in from)) {
4
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
5
- ar[i] = from[i];
6
- }
7
- }
8
- return to.concat(ar || Array.prototype.slice.call(from));
9
- };
10
- export default (function (columns, data, sortBy, descending) {
11
- var sortedData = __spreadArray([], data, true);
12
- var compare = function (data1, data2) {
13
- if (!isNaN(data1[sortBy])) {
14
- return data1[sortBy] - data2[sortBy];
15
- }
16
- if (!data1[sortBy]) {
17
- return data2[sortBy] ? 1 : 0;
18
- }
19
- return data1[sortBy].localeCompare(data2[sortBy]);
20
- };
21
- var column = columns.find(function (col) { return col.key === sortBy; });
22
- var customCompare = column && typeof column.compare === 'function' ? column.compare : null;
23
- if (customCompare) {
24
- compare = function (data1, data2) { return customCompare(data1[sortBy], data2[sortBy]); };
25
- }
26
- sortedData.sort(compare);
27
- if (descending) {
28
- sortedData.reverse();
29
- }
30
- return sortedData;
31
- });
@@ -1,53 +0,0 @@
1
- import sortData from './sort-data';
2
- var columns = [
3
- { key: 'name', header: 'Name' },
4
- { key: 'age', header: 'Age' },
5
- { key: 'id', header: 'Employee-id' },
6
- {
7
- key: 'rand',
8
- header: 'A random number with thousand separator needs a custom compare',
9
- compare: function (a, b) { return a.replace(/\s/g, '') - b.replace(/\s/g, ''); },
10
- },
11
- ];
12
- var data = [
13
- { name: 'Zombie Mountain', age: 36, id: 2, rand: '69 873' },
14
- { name: 'Daenerys Targaryen', age: 16, id: 4, rand: '9 156' },
15
- { name: 'Ned Stark', age: 48, id: 3, rand: '3 863 914' },
16
- { name: 'Jon Snow', age: 20, id: 1, rand: '145 678' },
17
- ];
18
- describe('sortData', function () {
19
- it('should sort data in descending order', function () {
20
- var ascendingTableData = sortData(columns, data, 'age', true);
21
- for (var i = 1; i > ascendingTableData.length; i++) {
22
- expect(ascendingTableData[i].id).toBeLessThan(ascendingTableData[i - 1].id);
23
- }
24
- });
25
- it('should sort data in ascending order', function () {
26
- var ascendingTableData = sortData(columns, data, 'age', false);
27
- for (var i = 1; i > ascendingTableData.length; i++) {
28
- expect(ascendingTableData[i].id).toBeGreaterThan(ascendingTableData[i - 1].id);
29
- }
30
- });
31
- it('should sort data based on `sortBy` parameter', function () {
32
- var tableData = sortData(columns, data, 'age', true);
33
- expect(tableData[0].age).toBe(48);
34
- expect(tableData[1].age).toBe(36);
35
- expect(tableData[2].age).toBe(20);
36
- expect(tableData[3].age).toBe(16);
37
- });
38
- it('should sort data even though an attribute is not set', function () {
39
- data[3] = { name: 'Jon Snow', id: 1, rand: '145 678' }; // no age key
40
- var tableData = sortData(columns, data, 'age', false);
41
- expect(tableData[0].age).toBe(16);
42
- expect(tableData[1].age).toBe(36);
43
- expect(tableData[2].age).toBe(48);
44
- expect(tableData[3].age).toBe(undefined);
45
- });
46
- it('should sort data with a custom compare function when provided', function () {
47
- var tableData = sortData(columns, data, 'rand', false);
48
- expect(tableData[0].rand).toBe('9 156');
49
- expect(tableData[1].rand).toBe('69 873');
50
- expect(tableData[2].rand).toBe('145 678');
51
- expect(tableData[3].rand).toBe('3 863 914');
52
- });
53
- });
@@ -1,26 +0,0 @@
1
- import React from 'react';
2
- import PropTypes from 'prop-types';
3
- import classNames from 'classnames';
4
- var TableCell = function (props) {
5
- var alignRight = props.alignRight, alignTop = props.alignTop, children = props.children, columnHeader = props.columnHeader, contentClasses = props.contentClasses, tdClasses = props.tdClasses;
6
- var dataTh = '';
7
- if (columnHeader) {
8
- if (typeof columnHeader === 'string') {
9
- dataTh = columnHeader;
10
- }
11
- else if (columnHeader.props && columnHeader.props.children) {
12
- dataTh = React.Children.toArray(columnHeader.props.children)[0];
13
- }
14
- }
15
- return (React.createElement("td", { className: classNames('ffe-table__cell', { 'ffe-table__cell--top': alignTop }, tdClasses), "data-th": dataTh },
16
- React.createElement("span", { className: classNames('ffe-table__content', { 'ffe-table__content--text-right': alignRight }, contentClasses) }, children)));
17
- };
18
- TableCell.propTypes = {
19
- alignRight: PropTypes.bool,
20
- alignTop: PropTypes.bool,
21
- children: PropTypes.any,
22
- columnHeader: PropTypes.oneOfType([PropTypes.string, PropTypes.node]),
23
- contentClasses: PropTypes.string,
24
- tdClasses: PropTypes.string,
25
- };
26
- export default TableCell;
@@ -1,69 +0,0 @@
1
- var __assign = (this && this.__assign) || function () {
2
- __assign = Object.assign || function(t) {
3
- for (var s, i = 1, n = arguments.length; i < n; i++) {
4
- s = arguments[i];
5
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
6
- t[p] = s[p];
7
- }
8
- return t;
9
- };
10
- return __assign.apply(this, arguments);
11
- };
12
- import React from 'react';
13
- import PropTypes from 'prop-types';
14
- import TableCell from './TableCell';
15
- import classNames from 'classnames';
16
- var TableFooter = function (_a) {
17
- var columns = _a.columns, footerRender = _a.footerRender, dataWindow = _a.dataWindow;
18
- var footerContent = columns.map(function (column, index) {
19
- if (column === null) {
20
- return React.createElement("td", { key: index });
21
- }
22
- var className = classNames({ 'ffe-table--hide-sm': column.hideOnMobile }, { 'ffe-table--hide-md': column.hideOnSmallTablet }, { 'ffe-table--hide-lg': column.hideOnTablet }, { 'ffe-table--hide-xlg': column.hideOnDesktop });
23
- var dataTh = '';
24
- var columnHeader = column.header;
25
- if (columnHeader) {
26
- if (typeof columnHeader === 'string') {
27
- dataTh = columnHeader;
28
- }
29
- else if (columnHeader.props && columnHeader.props.children) {
30
- dataTh = React.Children.toArray(columnHeader.props.children)[0];
31
- }
32
- }
33
- var tdProps = {
34
- className: classNames('ffe-table__cell', { 'ffe-table__cell--top': column.alignTop }, className),
35
- 'data-th': dataTh,
36
- key: index,
37
- };
38
- var spanProps = {
39
- className: classNames('ffe-table__content', {
40
- 'ffe-table__content--text-right': column.alignRight,
41
- }),
42
- };
43
- if (typeof column.columnFooterRender === 'function') {
44
- return column.columnFooterRender(column.footer, dataWindow, tdProps, spanProps, columns, index);
45
- }
46
- return (React.createElement(TableCell, { key: index, columnHeader: column.header, alignRight: column.alignRight, alignTop: column.alignTop, tdClasses: className }, column.footer));
47
- });
48
- var trProps = { className: 'ffe-table__row', children: footerContent };
49
- var trDefault = React.createElement("tr", __assign({}, trProps));
50
- var footerRendered = typeof footerRender === 'function'
51
- ? footerRender(trProps, columns)
52
- : trDefault;
53
- return React.createElement("tfoot", { className: "ffe-table__footer" }, footerRendered);
54
- };
55
- TableFooter.propTypes = {
56
- columns: PropTypes.arrayOf(PropTypes.shape({
57
- alignRight: PropTypes.bool,
58
- alignTop: PropTypes.bool,
59
- footer: PropTypes.any,
60
- header: PropTypes.node.isRequired,
61
- hideOnDesktop: PropTypes.bool,
62
- hideOnMobile: PropTypes.bool,
63
- hideOnSmallTablet: PropTypes.bool,
64
- hideOnTablet: PropTypes.bool,
65
- })),
66
- footerRender: PropTypes.func,
67
- dataWindow: PropTypes.array,
68
- };
69
- export default TableFooter;
@@ -1,58 +0,0 @@
1
- var __assign = (this && this.__assign) || function () {
2
- __assign = Object.assign || function(t) {
3
- for (var s, i = 1, n = arguments.length; i < n; i++) {
4
- s = arguments[i];
5
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
6
- t[p] = s[p];
7
- }
8
- return t;
9
- };
10
- return __assign.apply(this, arguments);
11
- };
12
- import React from 'react';
13
- import PropTypes from 'prop-types';
14
- import classNames from 'classnames';
15
- var TableHeaders = function (_a) {
16
- var columns = _a.columns, headerRender = _a.headerRender, dataWindow = _a.dataWindow;
17
- var headerContent = columns.map(function (column, index) {
18
- if (column === null) {
19
- return React.createElement("th", { key: index });
20
- }
21
- var thProps = {
22
- key: index,
23
- className: classNames('ffe-table__heading', { 'ffe-table--hide-sm': column.hideOnMobile }, { 'ffe-table--hide-md': column.hideOnSmallTablet }, { 'ffe-table--hide-lg': column.hideOnTablet }, { 'ffe-table--hide-xlg': column.hideOnDesktop }),
24
- 'aria-sort': column.ariaSort,
25
- scope: 'col',
26
- };
27
- var spanProps = {
28
- className: classNames('ffe-table__content', {
29
- 'ffe-table__content--text-right': column.alignRight,
30
- }),
31
- };
32
- var thContentDefault = React.createElement("span", __assign({}, spanProps), column.header);
33
- if (typeof column.columnHeaderRender === 'function') {
34
- return column.columnHeaderRender(column.header, dataWindow, spanProps, thProps, columns, index);
35
- }
36
- return (React.createElement("th", __assign({ key: thProps.key }, thProps), thContentDefault));
37
- });
38
- var trProps = { className: 'ffe-table__row', children: headerContent };
39
- var trDefault = React.createElement("tr", __assign({}, trProps));
40
- var headerRendered = typeof headerRender === 'function'
41
- ? headerRender(trProps, columns)
42
- : trDefault;
43
- return React.createElement("thead", { className: "ffe-table__head" }, headerRendered);
44
- };
45
- TableHeaders.propTypes = {
46
- columns: PropTypes.arrayOf(PropTypes.shape({
47
- alignRight: PropTypes.bool,
48
- header: PropTypes.node.isRequired,
49
- hideOnDesktop: PropTypes.bool,
50
- hideOnMobile: PropTypes.bool,
51
- hideOnSmallTablet: PropTypes.bool,
52
- hideOnTablet: PropTypes.bool,
53
- key: PropTypes.string.isRequired,
54
- })),
55
- headerRender: PropTypes.func,
56
- dataWindow: PropTypes.array,
57
- };
58
- export default TableHeaders;
@@ -1,61 +0,0 @@
1
- var __assign = (this && this.__assign) || function () {
2
- __assign = Object.assign || function(t) {
3
- for (var s, i = 1, n = arguments.length; i < n; i++) {
4
- s = arguments[i];
5
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
6
- t[p] = s[p];
7
- }
8
- return t;
9
- };
10
- return __assign.apply(this, arguments);
11
- };
12
- import React from 'react';
13
- import PropTypes from 'prop-types';
14
- import classNames from 'classnames';
15
- import TableCell from './TableCell';
16
- var TableRow = function (props) {
17
- var cells = props.cells, columns = props.columns, onClick = props.onClick, onKeyDown = props.onKeyDown, trClasses = props.trClasses, expandable = props.expandable, expanded = props.expanded, rowRender = props.rowRender, rowIndex = props.rowIndex;
18
- var expandableProps = expandable && {
19
- 'aria-expanded': expanded,
20
- onClick: onClick,
21
- onKeyDown: onKeyDown,
22
- role: 'button',
23
- tabIndex: '0',
24
- };
25
- var rowContent = columns.map(function (column, index) {
26
- return (React.createElement(TableCell, { alignRight: column.alignRight, alignTop: column.alignTop, columnHeader: column.header, key: index, tdClasses: classNames({
27
- 'ffe-table__cell--collapsed': column.key === 'expandIcon',
28
- }, { 'ffe-table--hide-sm': column.hideOnMobile }, { 'ffe-table--hide-md': column.hideOnSmallTablet }, { 'ffe-table--hide-lg': column.hideOnTablet }, { 'ffe-table--hide-xlg': column.hideOnDesktop }) }, column.cellRender
29
- ? column.cellRender(cells[column.key], column, props, index)
30
- : cells[column.key]));
31
- });
32
- var trprops = __assign(__assign({ className: classNames('ffe-table__row', trClasses) }, expandableProps), { onClick: onClick, children: rowContent });
33
- if (typeof rowRender === 'function') {
34
- return rowRender(trprops, props, rowIndex);
35
- }
36
- return React.createElement("tr", __assign({}, trprops), rowContent);
37
- };
38
- TableRow.propTypes = {
39
- cells: PropTypes.object.isRequired,
40
- columns: PropTypes.arrayOf(PropTypes.shape({
41
- alignRight: PropTypes.bool,
42
- alignTop: PropTypes.bool,
43
- header: PropTypes.any,
44
- hideOnDesktop: PropTypes.bool,
45
- hideOnMobile: PropTypes.bool,
46
- hideOnSmallTablet: PropTypes.bool,
47
- hideOnTablet: PropTypes.bool,
48
- key: PropTypes.string,
49
- cellRender: PropTypes.func,
50
- })).isRequired,
51
- expandable: PropTypes.bool,
52
- expanded: PropTypes.bool,
53
- onClick: PropTypes.func,
54
- rowRender: PropTypes.func,
55
- headerRender: PropTypes.func,
56
- footerRender: PropTypes.func,
57
- onKeyDown: PropTypes.func,
58
- trClasses: PropTypes.string,
59
- rowIndex: PropTypes.number,
60
- };
61
- export default TableRow;
@@ -1,102 +0,0 @@
1
- var __extends = (this && this.__extends) || (function () {
2
- var extendStatics = function (d, b) {
3
- extendStatics = Object.setPrototypeOf ||
4
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
5
- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
6
- return extendStatics(d, b);
7
- };
8
- return function (d, b) {
9
- if (typeof b !== "function" && b !== null)
10
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
11
- extendStatics(d, b);
12
- function __() { this.constructor = d; }
13
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
14
- };
15
- })();
16
- var __assign = (this && this.__assign) || function () {
17
- __assign = Object.assign || function(t) {
18
- for (var s, i = 1, n = arguments.length; i < n; i++) {
19
- s = arguments[i];
20
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
21
- t[p] = s[p];
22
- }
23
- return t;
24
- };
25
- return __assign.apply(this, arguments);
26
- };
27
- import { Icon } from '@sb1/ffe-icons-react';
28
- import classNames from 'classnames';
29
- import PropTypes from 'prop-types';
30
- import React, { Component } from 'react';
31
- import { polyfill } from 'react-lifecycles-compat';
32
- import shallowEqual from 'shallow-equals';
33
- import TableRow from './TableRow';
34
- var TableRowExpandable = /** @class */ (function (_super) {
35
- __extends(TableRowExpandable, _super);
36
- function TableRowExpandable(props) {
37
- var _this = _super.call(this, props) || this;
38
- _this.handleKeyPress = _this.handleKeyPress.bind(_this);
39
- _this.toggleExpand = _this.toggleExpand.bind(_this);
40
- _this.state = {
41
- expanded: !!props.defaultExpanded,
42
- sort: props.sort,
43
- };
44
- _this.rowRef = React.createRef();
45
- return _this;
46
- }
47
- TableRowExpandable.prototype.componentDidMount = function () {
48
- if (this.props.scrollToOnMount && this.rowRef.current) {
49
- this.rowRef.current.scrollIntoView();
50
- }
51
- };
52
- TableRowExpandable.getDerivedStateFromProps = function (nextProps, prevState) {
53
- if ((!nextProps.children && prevState.expanded) ||
54
- !shallowEqual(nextProps.sort, prevState.sort)) {
55
- return {
56
- expanded: false,
57
- sort: nextProps.sort,
58
- };
59
- }
60
- return null;
61
- };
62
- TableRowExpandable.prototype.toggleExpand = function () {
63
- this.setState(function (prevState) { return ({ expanded: !prevState.expanded }); });
64
- };
65
- TableRowExpandable.prototype.handleKeyPress = function (event) {
66
- if ((event.key === 'Enter' || event.key === ' ') &&
67
- event.target.tagName === 'TR') {
68
- this.setState(function (prevState) { return ({ expanded: !prevState.expanded }); });
69
- event.preventDefault();
70
- }
71
- };
72
- TableRowExpandable.prototype.render = function () {
73
- var _a = this.props, cells = _a.cells, columns = _a.columns, children = _a.children, rowRender = _a.rowRender, rowIndex = _a.rowIndex;
74
- var unexpandable = !children;
75
- return (React.createElement("tbody", { ref: this.rowRef },
76
- React.createElement(TableRow, { cells: __assign(__assign({}, cells), { expandIcon: unexpandable ? (' ') : (React.createElement(Icon, { className: classNames('ffe-table__expand-icon', {
77
- 'ffe-table__expand-icon--expanded': this.state.expanded,
78
- }), fileUrl: "data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIGhlaWdodD0iMjQiIHZpZXdCb3g9IjAgLTk2MCA5NjAgOTYwIiB3aWR0aD0iMjQiPjxwYXRoIGQ9Ik00ODAtMzczLjUzOXEtNy4yMzEgMC0xMy40NjEtMi4zMDgtNi4yMzEtMi4zMDgtMTEuODQ2LTcuOTIzTDI3NC45MjQtNTYzLjUzOXEtOC4zMDgtOC4zMDctOC41LTIwLjg4NC0uMTkzLTEyLjU3NyA4LjUtMjEuMjY5IDguNjkyLTguNjkyIDIxLjA3Ni04LjY5MnQyMS4wNzYgOC42OTJMNDgwLTQ0Mi43NjhsMTYyLjkyNC0xNjIuOTI0cTguMzA3LTguMzA3IDIwLjg4NC04LjUgMTIuNTc2LS4xOTIgMjEuMjY4IDguNSA4LjY5MyA4LjY5MiA4LjY5MyAyMS4wNzcgMCAxMi4zODQtOC42OTMgMjEuMDc2TDUwNS4zMDctMzgzLjc3cS01LjYxNSA1LjYxNS0xMS44NDYgNy45MjMtNi4yMyAyLjMwOC0xMy40NjEgMi4zMDhaIi8+PC9zdmc+", size: "md" })) }), trClasses: classNames({ 'ffe-table__row-expandable': !unexpandable }, {
79
- 'ffe-table__row-expandable--expanded': this.state.expanded,
80
- }), columns: columns, onClick: this.toggleExpand, onKeyDown: this.handleKeyPress, expandable: !unexpandable, expanded: this.state.expanded, rowRender: rowRender, rowIndex: rowIndex }),
81
- React.createElement("tr", { role: "presentation", "aria-hidden": String(!this.state.expanded), className: classNames('ffe-table__row', 'ffe-table__row-expandable-content', {
82
- 'ffe-table__row-expandable-content--expanded': this.state.expanded,
83
- }, { 'ffe-table__row--collapsed': !this.state.expanded }) },
84
- React.createElement("td", { colSpan: columns.length, className: "ffe-table__cell-expandable-content" },
85
- React.createElement("div", null, this.state.expanded && children)))));
86
- };
87
- return TableRowExpandable;
88
- }(Component));
89
- TableRowExpandable.propTypes = {
90
- children: PropTypes.node,
91
- cells: PropTypes.object.isRequired,
92
- columns: PropTypes.array.isRequired,
93
- sort: PropTypes.object,
94
- rowRender: PropTypes.func,
95
- headerRender: PropTypes.func,
96
- footerRender: PropTypes.func,
97
- rowIndex: PropTypes.number,
98
- defaultExpanded: PropTypes.bool,
99
- scrollToOnMount: PropTypes.bool,
100
- };
101
- polyfill(TableRowExpandable);
102
- export default TableRowExpandable;