@sb1/ffe-tables-react 8.0.38 → 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 +10 -14
  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
@@ -0,0 +1,28 @@
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
+ var __rest = (this && this.__rest) || function (s, e) {
13
+ var t = {};
14
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
15
+ t[p] = s[p];
16
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
17
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
18
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
19
+ t[p[i]] = s[p[i]];
20
+ }
21
+ return t;
22
+ };
23
+ import React from 'react';
24
+ import classNames from 'classnames';
25
+ export var CellContent = function (_a) {
26
+ var className = _a.className, rest = __rest(_a, ["className"]);
27
+ return (React.createElement("div", __assign({ className: classNames('ffe-table__cell-content', className) }, rest)));
28
+ };
package/es/Table.js CHANGED
@@ -21,87 +21,18 @@ var __rest = (this && this.__rest) || function (s, e) {
21
21
  return t;
22
22
  };
23
23
  import React from 'react';
24
- import { node, bool, func, number, oneOf, oneOfType, arrayOf, shape, string, } from 'prop-types';
25
- import DefaultTable from './DefaultTable/DefaultTable';
26
- import SortableTable from './SortableTable/SortableTable';
27
- var Table = function (props) {
28
- var sortable = props.sortable, rest = __rest(props, ["sortable"]);
29
- if (sortable) {
30
- return React.createElement(SortableTable, __assign({}, rest));
31
- }
32
- return React.createElement(DefaultTable, __assign({}, rest));
33
- };
34
- Table.propTypes = {
35
- caption: node,
36
- /** Make the caption only visible for screen readers */
37
- srOnlyCaption: bool,
38
- /** A mapping function that returns a renderable node that will be rendered for each expandable row */
39
- expandedContentMapper: func,
40
- sortable: bool,
41
- /** A string reference to a column key to set an initial sort of the table */
42
- sortBy: string,
43
- /** Used in conjunction with sortBy */
44
- descending: bool,
45
- /** When paginated, lets you set the number of rows to offset from the beginning */
46
- offset: number,
47
- /** Limits the number of rows to show on one page. Decides whether or not to paginate your table */
48
- limit: number,
49
- /** Makes your table condensed - for pages that show a lot of data */
50
- condensed: bool,
51
- /** Set to true if you want the row headings to be narrower on smalls screens */
52
- smallHeader: bool,
53
- /** Removes left cell padding from the first column */
54
- alignLeft: bool,
55
- /** Show your table as a regular column based table on small devices */
56
- columnLayoutMobile: bool,
57
- /** Decide if your table rows should break into a vertical view on small or no devices */
58
- breakpoint: oneOf(['sm', 'none']),
59
- /**
60
- * Override rendering of rows with a prop
61
- * rowRender={(props, rowcontent, trprops, index)=>{return <tr {...trprops}>{rowcontent}</tr>}}
62
- */
63
- rowRender: func,
64
- /**
65
- * Override rendering of headers with a prop
66
- * headerRender={(props, rowcontent, trprops) => {return <tr {...trprops}>{rowcontent}</tr>}}
67
- */
68
- headerRender: func,
69
- /**
70
- * Override rendering of footer with a prop
71
- * footerRender={(props, rowcontent, trprops) => {return <tr {...trprops}>{rowcontent}</tr>}}
72
- */
73
- footerRender: func,
74
- /**
75
- * An array of objects with keys equal to the columns array's key value, and value equal to whatever you
76
- * want in your cell. These are basically an array of rows
77
- **/
78
- data: arrayOf(shape({
79
- /** A unique ID for each row of data. Required for sorting */
80
- id: oneOfType([string, number]),
81
- })),
82
- /** An array of objects with a key describing your column, and a header describing that column */
83
- columns: arrayOf(shape({
84
- /** The column header. Required, but may be an empty string. */
85
- header: node.isRequired,
86
- /** The column key used in the `data` array's objects */
87
- key: string.isRequired,
88
- /** Content shown in the table footer */
89
- footer: node,
90
- alignRight: bool,
91
- alignTop: bool,
92
- hideOnDesktop: bool,
93
- hideOnTablet: bool,
94
- hideOnSmallTablet: bool,
95
- hideOnMobile: bool,
96
- /** Custom comparator function for sorting this column */
97
- compare: func,
98
- /** Disable column from sorting. Not needed if heading is an empty string */
99
- notSortable: bool,
100
- cellRender: func,
101
- columnHeaderRender: func,
102
- columnFooterRender: func,
103
- }).isRequired),
104
- /** Class names set in addition to the ffe tables classes. */
105
- className: string,
106
- };
107
- export default Table;
24
+ import classNames from 'classnames';
25
+ import { TableProvider, TableContext, } from './TableContext';
26
+ export var Table = React.forwardRef(function (_a, ref) {
27
+ var className = _a.className, initialSort = _a.initialSort, children = _a.children, rest = __rest(_a, ["className", "initialSort", "children"]);
28
+ return (React.createElement(TableProvider, { initialSort: initialSort },
29
+ React.createElement(TableContext.Consumer, null, function (_a) {
30
+ var activeSortOrder = _a.activeSortOrder, activeSortKey = _a.activeSortKey;
31
+ return (React.createElement("table", __assign({ className: classNames('ffe-table', className), ref: ref }, rest), typeof children === 'function'
32
+ ? children({
33
+ activeSortOrder: activeSortOrder,
34
+ activeSortKey: activeSortKey,
35
+ })
36
+ : children));
37
+ })));
38
+ });
@@ -0,0 +1,28 @@
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
+ var __rest = (this && this.__rest) || function (s, e) {
13
+ var t = {};
14
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
15
+ t[p] = s[p];
16
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
17
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
18
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
19
+ t[p[i]] = s[p[i]];
20
+ }
21
+ return t;
22
+ };
23
+ import React from 'react';
24
+ import classNames from 'classnames';
25
+ export var TableBody = function (_a) {
26
+ var className = _a.className, rest = __rest(_a, ["className"]);
27
+ return (React.createElement("tbody", __assign({ className: classNames('ffe-table__body', className) }, rest)));
28
+ };
@@ -0,0 +1,28 @@
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
+ var __rest = (this && this.__rest) || function (s, e) {
13
+ var t = {};
14
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
15
+ t[p] = s[p];
16
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
17
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
18
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
19
+ t[p[i]] = s[p[i]];
20
+ }
21
+ return t;
22
+ };
23
+ import React from 'react';
24
+ import classNames from 'classnames';
25
+ export var TableCaption = React.forwardRef(function (_a, ref) {
26
+ var className = _a.className, rest = __rest(_a, ["className"]);
27
+ return (React.createElement("caption", __assign({ className: classNames('ffe-table__caption', className), ref: ref }, rest)));
28
+ });
@@ -0,0 +1,34 @@
1
+ import React, { useState } from 'react';
2
+ import { ariaSortOrders } from './types';
3
+ export var TableContext = React.createContext({
4
+ updateSort: function () { return null; },
5
+ getSort: function () { return 'none'; },
6
+ });
7
+ var getNextSort = function (sort) {
8
+ if (sort === void 0) { sort = 'none'; }
9
+ return sort
10
+ ? ariaSortOrders[(ariaSortOrders.indexOf(sort) + 1) % ariaSortOrders.length]
11
+ : 'none';
12
+ };
13
+ export var TableProvider = function (_a) {
14
+ var _b;
15
+ var initialSort = _a.initialSort, children = _a.children;
16
+ var _c = useState((_b = initialSort === null || initialSort === void 0 ? void 0 : initialSort.sortOrder) !== null && _b !== void 0 ? _b : 'none'), activeSortOrder = _c[0], setActiveSortOrder = _c[1];
17
+ var _d = useState(initialSort === null || initialSort === void 0 ? void 0 : initialSort.sortKey), activeSortKey = _d[0], setActiveSortKey = _d[1];
18
+ var updateSort = function (sortKey) {
19
+ if (sortKey === activeSortKey) {
20
+ setActiveSortOrder(getNextSort(activeSortOrder));
21
+ }
22
+ else {
23
+ setActiveSortKey(sortKey);
24
+ setActiveSortOrder(getNextSort('none'));
25
+ }
26
+ };
27
+ var getSort = function (sortKey) {
28
+ if (sortKey === activeSortKey) {
29
+ return activeSortOrder;
30
+ }
31
+ return 'none';
32
+ };
33
+ return (React.createElement(TableContext.Provider, { value: { activeSortOrder: activeSortOrder, activeSortKey: activeSortKey, updateSort: updateSort, getSort: getSort } }, children));
34
+ };
@@ -0,0 +1,30 @@
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
+ var __rest = (this && this.__rest) || function (s, e) {
13
+ var t = {};
14
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
15
+ t[p] = s[p];
16
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
17
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
18
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
19
+ t[p[i]] = s[p[i]];
20
+ }
21
+ return t;
22
+ };
23
+ import React from 'react';
24
+ import classNames from 'classnames';
25
+ import { CellContent } from './CellContent';
26
+ export var TableDataCell = React.forwardRef(function (_a, ref) {
27
+ var className = _a.className, children = _a.children, rest = __rest(_a, ["className", "children"]);
28
+ return (React.createElement("td", __assign({ className: classNames('ffe-table__td', className), ref: ref }, rest),
29
+ React.createElement(CellContent, null, children)));
30
+ });
@@ -0,0 +1,28 @@
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
+ var __rest = (this && this.__rest) || function (s, e) {
13
+ var t = {};
14
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
15
+ t[p] = s[p];
16
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
17
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
18
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
19
+ t[p[i]] = s[p[i]];
20
+ }
21
+ return t;
22
+ };
23
+ import React from 'react';
24
+ import classNames from 'classnames';
25
+ export var TableFoot = function (_a) {
26
+ var className = _a.className, rest = __rest(_a, ["className"]);
27
+ return (React.createElement("tfoot", __assign({ className: classNames('ffe-table__foot', className) }, rest)));
28
+ };
@@ -0,0 +1,28 @@
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
+ var __rest = (this && this.__rest) || function (s, e) {
13
+ var t = {};
14
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
15
+ t[p] = s[p];
16
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
17
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
18
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
19
+ t[p[i]] = s[p[i]];
20
+ }
21
+ return t;
22
+ };
23
+ import React from 'react';
24
+ import classNames from 'classnames';
25
+ export var TableHead = function (_a) {
26
+ var className = _a.className, rest = __rest(_a, ["className"]);
27
+ return (React.createElement("thead", __assign({ className: classNames('ffe-table__head', className) }, rest)));
28
+ };
@@ -0,0 +1,51 @@
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
+ var __rest = (this && this.__rest) || function (s, e) {
13
+ var t = {};
14
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
15
+ t[p] = s[p];
16
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
17
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
18
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
19
+ t[p[i]] = s[p[i]];
20
+ }
21
+ return t;
22
+ };
23
+ import React, { useContext, useRef } from 'react';
24
+ import classNames from 'classnames';
25
+ import { Icon } from '@sb1/ffe-icons-react';
26
+ import { TableContext } from './TableContext';
27
+ import { CellContent } from './CellContent';
28
+ // name Keyboard Arrow Up (weight 400)
29
+ var arrowUpIcon = 'data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIGhlaWdodD0iMjQiIHZpZXdCb3g9IjAgLTk2MCA5NjAgOTYwIiB3aWR0aD0iMjQiPjxwYXRoIGQ9Ik00ODAtNTI4IDMyNC0zNzJxLTExIDExLTI4IDExdC0yOC0xMXEtMTEtMTEtMTEtMjh0MTEtMjhsMTg0LTE4NHExMi0xMiAyOC0xMnQyOCAxMmwxODQgMTg0cTExIDExIDExIDI4dC0xMSAyOHEtMTEgMTEtMjggMTF0LTI4LTExTDQ4MC01MjhaIi8+PC9zdmc+';
30
+ // name id Unfold More (weight 400)
31
+ var unfoldIcon = 'data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIGhlaWdodD0iMjQiIHZpZXdCb3g9IjAgLTk2MCA5NjAgOTYwIiB3aWR0aD0iMjQiPjxwYXRoIGQ9Im00ODAtMjM2IDkzLTkzcTEyLTEyIDI5LTEydDI5IDEycTEyIDEyIDEyIDI5dC0xMiAyOUw1MDgtMTQ4cS02IDYtMTMgOC41dC0xNSAyLjVxLTggMC0xNS0yLjV0LTEzLTguNUwzMjktMjcxcS0xMi0xMi0xMi0yOXQxMi0yOXExMi0xMiAyOS0xMnQyOSAxMmw5MyA5M1ptMC00ODQtOTMgOTNxLTEyIDEyLTI5IDEydC0yOS0xMnEtMTItMTItMTItMjl0MTItMjlsMTIzLTEyM3E2LTYgMTMtOC41dDE1LTIuNXE4IDAgMTUgMi41dDEzIDguNWwxMjMgMTIzcTEyIDEyIDEyIDI5dC0xMiAyOXEtMTIgMTItMjkgMTJ0LTI5LTEybC05My05M1oiLz48L3N2Zz4=';
32
+ export var TableHeaderCell = React.forwardRef(function (_a, ref) {
33
+ var className = _a.className, sortKey = _a.sortKey, children = _a.children, onClick = _a.onClick, rest = __rest(_a, ["className", "sortKey", "children", "onClick"]);
34
+ var _b = useContext(TableContext), updateSort = _b.updateSort, getSort = _b.getSort;
35
+ var sortButtonRef = useRef(null);
36
+ var ariaSort = sortKey ? getSort(sortKey) : undefined;
37
+ return (React.createElement("th", __assign({ className: classNames('ffe-table__th', { 'ffe-table__th--sortable': sortKey }, {
38
+ 'ffe-table__th--sortable-ascending': ariaSort === 'ascending',
39
+ }, {
40
+ 'ffe-table__th--sortable-descending': ariaSort === 'descending',
41
+ }, className), "aria-sort": ariaSort, onClick: function (e) {
42
+ var _a, _b;
43
+ if (!((_a = sortButtonRef.current) === null || _a === void 0 ? void 0 : _a.contains(e.target))) {
44
+ (_b = sortButtonRef.current) === null || _b === void 0 ? void 0 : _b.click();
45
+ }
46
+ onClick === null || onClick === void 0 ? void 0 : onClick(e);
47
+ }, ref: ref }, rest), sortKey ? (React.createElement(CellContent, null,
48
+ React.createElement("button", { className: "ffe-table__sort-button", type: "button", onClick: function () { return updateSort(sortKey); }, ref: sortButtonRef },
49
+ React.createElement("span", null, children),
50
+ React.createElement(Icon, { fileUrl: ariaSort === 'none' ? unfoldIcon : arrowUpIcon, size: "md" })))) : (React.createElement(CellContent, null, children))));
51
+ });
package/es/TableRow.js ADDED
@@ -0,0 +1,28 @@
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
+ var __rest = (this && this.__rest) || function (s, e) {
13
+ var t = {};
14
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
15
+ t[p] = s[p];
16
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
17
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
18
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
19
+ t[p[i]] = s[p[i]];
20
+ }
21
+ return t;
22
+ };
23
+ import React from 'react';
24
+ import classNames from 'classnames';
25
+ export var TableRow = React.forwardRef(function (_a, ref) {
26
+ var className = _a.className, rest = __rest(_a, ["className"]);
27
+ return (React.createElement("tr", __assign({ className: classNames('ffe-table__tr', className), ref: ref }, rest)));
28
+ });
@@ -0,0 +1,62 @@
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
+ var __rest = (this && this.__rest) || function (s, e) {
13
+ var t = {};
14
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
15
+ t[p] = s[p];
16
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
17
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
18
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
19
+ t[p[i]] = s[p[i]];
20
+ }
21
+ return t;
22
+ };
23
+ import React, { useRef, useState } from 'react';
24
+ import classNames from 'classnames';
25
+ import { Icon } from '@sb1/ffe-icons-react';
26
+ import { Collapse } from '@sb1/ffe-collapse-react';
27
+ import { txt } from './texts';
28
+ import { v4 as uuid } from 'uuid';
29
+ import { CellContent } from './CellContent';
30
+ export var TableRowExpandable = React.forwardRef(function (_a, ref) {
31
+ var className = _a.className, expandContent = _a.expandContent, children = _a.children, _b = _a.locale, locale = _b === void 0 ? 'nb' : _b, onClick = _a.onClick, rest = __rest(_a, ["className", "expandContent", "children", "locale", "onClick"]);
32
+ var _c = useState(false), isOpen = _c[0], setIsOpen = _c[1];
33
+ var expandoRowId = useRef("check-".concat(uuid())).current;
34
+ var _d = useState(false), isAnimating = _d[0], setIsAnimating = _d[1];
35
+ var expandButtonRef = useRef(null);
36
+ return (React.createElement(React.Fragment, null,
37
+ React.createElement("tr", __assign({ className: classNames('ffe-table__tr', 'ffe-table__tr--expand', {
38
+ 'ffe-table__tr--expand-open': isOpen,
39
+ }, className), onClick: function (e) {
40
+ var _a, _b;
41
+ if (!((_a = expandButtonRef.current) === null || _a === void 0 ? void 0 : _a.contains(e.target))) {
42
+ (_b = expandButtonRef.current) === null || _b === void 0 ? void 0 : _b.click();
43
+ }
44
+ onClick === null || onClick === void 0 ? void 0 : onClick(e);
45
+ }, ref: ref }, rest),
46
+ children,
47
+ React.createElement("td", null,
48
+ React.createElement(CellContent, null,
49
+ React.createElement("button", { className: classNames('ffe-table__expand-button', {
50
+ 'ffe-table__expand-button--open': isOpen,
51
+ }), ref: expandButtonRef, type: "button", "aria-label": isOpen
52
+ ? txt[locale].showLess
53
+ : txt[locale].showMore, "aria-controls": expandoRowId, "aria-expanded": isOpen, onClick: function () {
54
+ setIsOpen(function (prev) { return !prev; });
55
+ setIsAnimating(true);
56
+ } },
57
+ React.createElement(Icon, { fileUrl: "data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIGhlaWdodD0iMjQiIHZpZXdCb3g9IjAgLTk2MCA5NjAgOTYwIiB3aWR0aD0iMjQiPjxwYXRoIGQ9Ik00ODAtMzczLjUzOXEtNy4yMzEgMC0xMy40NjEtMi4zMDgtNi4yMzEtMi4zMDgtMTEuODQ2LTcuOTIzTDI3NC45MjQtNTYzLjUzOXEtOC4zMDgtOC4zMDctOC41LTIwLjg4NC0uMTkzLTEyLjU3NyA4LjUtMjEuMjY5IDguNjkyLTguNjkyIDIxLjA3Ni04LjY5MnQyMS4wNzYgOC42OTJMNDgwLTQ0Mi43NjhsMTYyLjkyNC0xNjIuOTI0cTguMzA3LTguMzA3IDIwLjg4NC04LjUgMTIuNTc2LS4xOTIgMjEuMjY4IDguNSA4LjY5MyA4LjY5MiA4LjY5MyAyMS4wNzcgMCAxMi4zODQtOC42OTMgMjEuMDc2TDUwNS4zMDctMzgzLjc3cS01LjYxNSA1LjYxNS0xMS44NDYgNy45MjMtNi4yMyAyLjMwOC0xMy40NjEgMi4zMDhaIi8+PC9zdmc+", size: "md" }))))),
58
+ React.createElement("tr", { "aria-hidden": !isAnimating && !isOpen, id: expandoRowId },
59
+ React.createElement("td", { colSpan: 9999 },
60
+ React.createElement(Collapse, { isOpen: isOpen, onRest: function () { return setIsAnimating(false); } },
61
+ React.createElement(CellContent, { className: "ffe-table__expand-content" }, expandContent))))));
62
+ });
package/es/index.js CHANGED
@@ -1,2 +1,9 @@
1
- import Table from './Table';
2
- export default Table;
1
+ export { Table } from './Table';
2
+ export { TableBody } from './TableBody';
3
+ export { TableDataCell } from './TableDataCell';
4
+ export { TableFoot } from './TableFoot';
5
+ export { TableHead } from './TableHead';
6
+ export { TableHeaderCell } from './TableHeaderCell';
7
+ export { TableRow } from './TableRow';
8
+ export { TableCaption } from './TableCaption';
9
+ export { TableRowExpandable, } from './TableRowExpandable';
package/es/texts.js ADDED
@@ -0,0 +1,13 @@
1
+ var nb = {
2
+ showMore: 'Vis mer',
3
+ showLess: 'Vis mindre',
4
+ };
5
+ var nn = {
6
+ showMore: 'Vis meir',
7
+ showLess: 'Vis mindre',
8
+ };
9
+ var en = {
10
+ showMore: 'Show more',
11
+ showLess: 'Show less',
12
+ };
13
+ export var txt = { nb: nb, nn: nn, en: en };
package/es/types.js ADDED
@@ -0,0 +1 @@
1
+ export var ariaSortOrders = ['none', 'ascending', 'descending'];
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
13
+ var __rest = (this && this.__rest) || function (s, e) {
14
+ var t = {};
15
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
16
+ t[p] = s[p];
17
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
18
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
19
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
20
+ t[p[i]] = s[p[i]];
21
+ }
22
+ return t;
23
+ };
24
+ var __importDefault = (this && this.__importDefault) || function (mod) {
25
+ return (mod && mod.__esModule) ? mod : { "default": mod };
26
+ };
27
+ Object.defineProperty(exports, "__esModule", { value: true });
28
+ exports.CellContent = void 0;
29
+ var react_1 = __importDefault(require("react"));
30
+ var classnames_1 = __importDefault(require("classnames"));
31
+ var CellContent = function (_a) {
32
+ var className = _a.className, rest = __rest(_a, ["className"]);
33
+ return (react_1.default.createElement("div", __assign({ className: (0, classnames_1.default)('ffe-table__cell-content', className) }, rest)));
34
+ };
35
+ exports.CellContent = CellContent;
package/lib/Table.js CHANGED
@@ -25,88 +25,20 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
25
25
  return (mod && mod.__esModule) ? mod : { "default": mod };
26
26
  };
27
27
  Object.defineProperty(exports, "__esModule", { value: true });
28
+ exports.Table = void 0;
28
29
  var react_1 = __importDefault(require("react"));
29
- var prop_types_1 = require("prop-types");
30
- var DefaultTable_1 = __importDefault(require("./DefaultTable/DefaultTable"));
31
- var SortableTable_1 = __importDefault(require("./SortableTable/SortableTable"));
32
- var Table = function (props) {
33
- var sortable = props.sortable, rest = __rest(props, ["sortable"]);
34
- if (sortable) {
35
- return react_1.default.createElement(SortableTable_1.default, __assign({}, rest));
36
- }
37
- return react_1.default.createElement(DefaultTable_1.default, __assign({}, rest));
38
- };
39
- Table.propTypes = {
40
- caption: prop_types_1.node,
41
- /** Make the caption only visible for screen readers */
42
- srOnlyCaption: prop_types_1.bool,
43
- /** A mapping function that returns a renderable node that will be rendered for each expandable row */
44
- expandedContentMapper: prop_types_1.func,
45
- sortable: prop_types_1.bool,
46
- /** A string reference to a column key to set an initial sort of the table */
47
- sortBy: prop_types_1.string,
48
- /** Used in conjunction with sortBy */
49
- descending: prop_types_1.bool,
50
- /** When paginated, lets you set the number of rows to offset from the beginning */
51
- offset: prop_types_1.number,
52
- /** Limits the number of rows to show on one page. Decides whether or not to paginate your table */
53
- limit: prop_types_1.number,
54
- /** Makes your table condensed - for pages that show a lot of data */
55
- condensed: prop_types_1.bool,
56
- /** Set to true if you want the row headings to be narrower on smalls screens */
57
- smallHeader: prop_types_1.bool,
58
- /** Removes left cell padding from the first column */
59
- alignLeft: prop_types_1.bool,
60
- /** Show your table as a regular column based table on small devices */
61
- columnLayoutMobile: prop_types_1.bool,
62
- /** Decide if your table rows should break into a vertical view on small or no devices */
63
- breakpoint: (0, prop_types_1.oneOf)(['sm', 'none']),
64
- /**
65
- * Override rendering of rows with a prop
66
- * rowRender={(props, rowcontent, trprops, index)=>{return <tr {...trprops}>{rowcontent}</tr>}}
67
- */
68
- rowRender: prop_types_1.func,
69
- /**
70
- * Override rendering of headers with a prop
71
- * headerRender={(props, rowcontent, trprops) => {return <tr {...trprops}>{rowcontent}</tr>}}
72
- */
73
- headerRender: prop_types_1.func,
74
- /**
75
- * Override rendering of footer with a prop
76
- * footerRender={(props, rowcontent, trprops) => {return <tr {...trprops}>{rowcontent}</tr>}}
77
- */
78
- footerRender: prop_types_1.func,
79
- /**
80
- * An array of objects with keys equal to the columns array's key value, and value equal to whatever you
81
- * want in your cell. These are basically an array of rows
82
- **/
83
- data: (0, prop_types_1.arrayOf)((0, prop_types_1.shape)({
84
- /** A unique ID for each row of data. Required for sorting */
85
- id: (0, prop_types_1.oneOfType)([prop_types_1.string, prop_types_1.number]),
86
- })),
87
- /** An array of objects with a key describing your column, and a header describing that column */
88
- columns: (0, prop_types_1.arrayOf)((0, prop_types_1.shape)({
89
- /** The column header. Required, but may be an empty string. */
90
- header: prop_types_1.node.isRequired,
91
- /** The column key used in the `data` array's objects */
92
- key: prop_types_1.string.isRequired,
93
- /** Content shown in the table footer */
94
- footer: prop_types_1.node,
95
- alignRight: prop_types_1.bool,
96
- alignTop: prop_types_1.bool,
97
- hideOnDesktop: prop_types_1.bool,
98
- hideOnTablet: prop_types_1.bool,
99
- hideOnSmallTablet: prop_types_1.bool,
100
- hideOnMobile: prop_types_1.bool,
101
- /** Custom comparator function for sorting this column */
102
- compare: prop_types_1.func,
103
- /** Disable column from sorting. Not needed if heading is an empty string */
104
- notSortable: prop_types_1.bool,
105
- cellRender: prop_types_1.func,
106
- columnHeaderRender: prop_types_1.func,
107
- columnFooterRender: prop_types_1.func,
108
- }).isRequired),
109
- /** Class names set in addition to the ffe tables classes. */
110
- className: prop_types_1.string,
111
- };
112
- exports.default = Table;
30
+ var classnames_1 = __importDefault(require("classnames"));
31
+ var TableContext_1 = require("./TableContext");
32
+ exports.Table = react_1.default.forwardRef(function (_a, ref) {
33
+ var className = _a.className, initialSort = _a.initialSort, children = _a.children, rest = __rest(_a, ["className", "initialSort", "children"]);
34
+ return (react_1.default.createElement(TableContext_1.TableProvider, { initialSort: initialSort },
35
+ react_1.default.createElement(TableContext_1.TableContext.Consumer, null, function (_a) {
36
+ var activeSortOrder = _a.activeSortOrder, activeSortKey = _a.activeSortKey;
37
+ return (react_1.default.createElement("table", __assign({ className: (0, classnames_1.default)('ffe-table', className), ref: ref }, rest), typeof children === 'function'
38
+ ? children({
39
+ activeSortOrder: activeSortOrder,
40
+ activeSortKey: activeSortKey,
41
+ })
42
+ : children));
43
+ })));
44
+ });