@sb1/ffe-tables-react 8.0.30 → 8.0.32
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/es/DefaultTable/DefaultTable.js +144 -197
- package/es/DefaultTable/DefaultTable.spec.js +441 -0
- package/es/SortableTable/SortableTable.js +127 -187
- package/es/SortableTable/SortableTable.spec.js +68 -0
- package/es/SortableTable/sort-data.js +28 -29
- package/es/SortableTable/sort-data.spec.js +53 -0
- package/es/Table.js +101 -83
- package/es/TableParts/TableCell.js +19 -31
- package/es/TableParts/TableFooter.js +61 -72
- package/es/TableParts/TableHeaders.js +52 -59
- package/es/TableParts/TableRow.js +54 -74
- package/es/TableParts/TableRowExpandable.js +90 -128
- package/es/TableParts/TableRowExpandable.spec.js +99 -0
- package/es/index.js +1 -1
- package/lib/DefaultTable/DefaultTable.js +176 -210
- package/lib/DefaultTable/DefaultTable.spec.js +446 -0
- package/lib/SortableTable/SortableTable.js +160 -201
- package/lib/SortableTable/SortableTable.spec.js +73 -0
- package/lib/SortableTable/sort-data.js +30 -35
- package/lib/SortableTable/sort-data.spec.js +58 -0
- package/lib/Table.js +108 -92
- package/lib/TableParts/TableCell.js +26 -40
- package/lib/TableParts/TableFooter.js +69 -82
- package/lib/TableParts/TableHeaders.js +58 -67
- package/lib/TableParts/TableRow.js +62 -84
- package/lib/TableParts/TableRowExpandable.js +123 -142
- package/lib/TableParts/TableRowExpandable.spec.js +104 -0
- package/lib/index.js +6 -8
- package/package.json +7 -7
- package/es/index.d.js +0 -1
- package/lib/index.d.js +0 -6
|
@@ -1,88 +1,66 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
var
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
onKeyDown = props.onKeyDown,
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
'ffe-table__cell--collapsed': column.key === 'expandIcon'
|
|
43
|
-
}, {
|
|
44
|
-
'ffe-table--hide-sm': column.hideOnMobile
|
|
45
|
-
}, {
|
|
46
|
-
'ffe-table--hide-md': column.hideOnSmallTablet
|
|
47
|
-
}, {
|
|
48
|
-
'ffe-table--hide-lg': column.hideOnTablet
|
|
49
|
-
}, {
|
|
50
|
-
'ffe-table--hide-xlg': column.hideOnDesktop
|
|
51
|
-
})
|
|
52
|
-
}, column.cellRender ? column.cellRender(cells[column.key], column, props, index) : cells[column.key]);
|
|
53
|
-
});
|
|
54
|
-
var trprops = _objectSpread(_objectSpread({
|
|
55
|
-
className: (0, _classnames.default)('ffe-table__row', trClasses)
|
|
56
|
-
}, expandableProps), {}, {
|
|
57
|
-
onClick: onClick,
|
|
58
|
-
children: rowContent
|
|
59
|
-
});
|
|
60
|
-
if (typeof rowRender === 'function') {
|
|
61
|
-
return rowRender(trprops, props, rowIndex);
|
|
62
|
-
}
|
|
63
|
-
return /*#__PURE__*/_react.default.createElement("tr", trprops, rowContent);
|
|
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 __importDefault = (this && this.__importDefault) || function (mod) {
|
|
14
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
var react_1 = __importDefault(require("react"));
|
|
18
|
+
var prop_types_1 = __importDefault(require("prop-types"));
|
|
19
|
+
var classnames_1 = __importDefault(require("classnames"));
|
|
20
|
+
var TableCell_1 = __importDefault(require("./TableCell"));
|
|
21
|
+
var TableRow = function (props) {
|
|
22
|
+
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;
|
|
23
|
+
var expandableProps = expandable && {
|
|
24
|
+
'aria-expanded': expanded,
|
|
25
|
+
onClick: onClick,
|
|
26
|
+
onKeyDown: onKeyDown,
|
|
27
|
+
role: 'button',
|
|
28
|
+
tabIndex: '0',
|
|
29
|
+
};
|
|
30
|
+
var rowContent = columns.map(function (column, index) {
|
|
31
|
+
return (react_1.default.createElement(TableCell_1.default, { alignRight: column.alignRight, alignTop: column.alignTop, columnHeader: column.header, key: index, tdClasses: (0, classnames_1.default)({
|
|
32
|
+
'ffe-table__cell--collapsed': column.key === 'expandIcon',
|
|
33
|
+
}, { '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
|
|
34
|
+
? column.cellRender(cells[column.key], column, props, index)
|
|
35
|
+
: cells[column.key]));
|
|
36
|
+
});
|
|
37
|
+
var trprops = __assign(__assign({ className: (0, classnames_1.default)('ffe-table__row', trClasses) }, expandableProps), { onClick: onClick, children: rowContent });
|
|
38
|
+
if (typeof rowRender === 'function') {
|
|
39
|
+
return rowRender(trprops, props, rowIndex);
|
|
40
|
+
}
|
|
41
|
+
return react_1.default.createElement("tr", __assign({}, trprops), rowContent);
|
|
64
42
|
};
|
|
65
43
|
TableRow.propTypes = {
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
44
|
+
cells: prop_types_1.default.object.isRequired,
|
|
45
|
+
columns: prop_types_1.default.arrayOf(prop_types_1.default.shape({
|
|
46
|
+
alignRight: prop_types_1.default.bool,
|
|
47
|
+
alignTop: prop_types_1.default.bool,
|
|
48
|
+
header: prop_types_1.default.any,
|
|
49
|
+
hideOnDesktop: prop_types_1.default.bool,
|
|
50
|
+
hideOnMobile: prop_types_1.default.bool,
|
|
51
|
+
hideOnSmallTablet: prop_types_1.default.bool,
|
|
52
|
+
hideOnTablet: prop_types_1.default.bool,
|
|
53
|
+
key: prop_types_1.default.string,
|
|
54
|
+
cellRender: prop_types_1.default.func,
|
|
55
|
+
})).isRequired,
|
|
56
|
+
expandable: prop_types_1.default.bool,
|
|
57
|
+
expanded: prop_types_1.default.bool,
|
|
58
|
+
onClick: prop_types_1.default.func,
|
|
59
|
+
rowRender: prop_types_1.default.func,
|
|
60
|
+
headerRender: prop_types_1.default.func,
|
|
61
|
+
footerRender: prop_types_1.default.func,
|
|
62
|
+
onKeyDown: prop_types_1.default.func,
|
|
63
|
+
trClasses: prop_types_1.default.string,
|
|
64
|
+
rowIndex: prop_types_1.default.number,
|
|
87
65
|
};
|
|
88
|
-
|
|
66
|
+
exports.default = TableRow;
|
|
@@ -1,149 +1,130 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
Object.
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
var _ffeIconsReact = require("@sb1/ffe-icons-react");
|
|
9
|
-
var _classnames = _interopRequireDefault(require("classnames"));
|
|
10
|
-
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
11
|
-
var _react = _interopRequireWildcard(require("react"));
|
|
12
|
-
var _reactLifecyclesCompat = require("react-lifecycles-compat");
|
|
13
|
-
var _shallowEquals = _interopRequireDefault(require("shallow-equals"));
|
|
14
|
-
var _TableRow = _interopRequireDefault(require("./TableRow"));
|
|
15
|
-
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
|
|
16
|
-
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
17
|
-
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
18
|
-
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
19
|
-
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
20
|
-
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
|
21
|
-
function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
|
|
22
|
-
function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } }
|
|
23
|
-
function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
|
|
24
|
-
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
|
|
25
|
-
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
26
|
-
function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
|
|
27
|
-
function _possibleConstructorReturn(t, e) { if (e && ("object" == _typeof(e) || "function" == typeof e)) return e; if (void 0 !== e) throw new TypeError("Derived constructors may only return object or undefined"); return _assertThisInitialized(t); }
|
|
28
|
-
function _assertThisInitialized(e) { if (void 0 === e) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); return e; }
|
|
29
|
-
function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
|
|
30
|
-
function _getPrototypeOf(t) { return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) { return t.__proto__ || Object.getPrototypeOf(t); }, _getPrototypeOf(t); }
|
|
31
|
-
function _inherits(t, e) { if ("function" != typeof e && null !== e) throw new TypeError("Super expression must either be null or a function"); t.prototype = Object.create(e && e.prototype, { constructor: { value: t, writable: !0, configurable: !0 } }), Object.defineProperty(t, "prototype", { writable: !1 }), e && _setPrototypeOf(t, e); }
|
|
32
|
-
function _setPrototypeOf(t, e) { return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) { return t.__proto__ = e, t; }, _setPrototypeOf(t, e); }
|
|
33
|
-
var TableRowExpandable = /*#__PURE__*/function (_Component) {
|
|
34
|
-
function TableRowExpandable(props) {
|
|
35
|
-
var _this;
|
|
36
|
-
_classCallCheck(this, TableRowExpandable);
|
|
37
|
-
_this = _callSuper(this, TableRowExpandable, [props]);
|
|
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
|
|
2
|
+
var __extends = (this && this.__extends) || (function () {
|
|
3
|
+
var extendStatics = function (d, b) {
|
|
4
|
+
extendStatics = Object.setPrototypeOf ||
|
|
5
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
+
return extendStatics(d, b);
|
|
43
8
|
};
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
return
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
this.setState(function (prevState) {
|
|
69
|
-
return {
|
|
70
|
-
expanded: !prevState.expanded
|
|
71
|
-
};
|
|
72
|
-
});
|
|
73
|
-
event.preventDefault();
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
}, {
|
|
77
|
-
key: "render",
|
|
78
|
-
value: function render() {
|
|
79
|
-
var _this$props = this.props,
|
|
80
|
-
cells = _this$props.cells,
|
|
81
|
-
columns = _this$props.columns,
|
|
82
|
-
children = _this$props.children,
|
|
83
|
-
rowRender = _this$props.rowRender,
|
|
84
|
-
rowIndex = _this$props.rowIndex;
|
|
85
|
-
var unexpandable = !children;
|
|
86
|
-
return /*#__PURE__*/_react.default.createElement("tbody", {
|
|
87
|
-
ref: this.rowRef
|
|
88
|
-
}, /*#__PURE__*/_react.default.createElement(_TableRow.default, {
|
|
89
|
-
cells: _objectSpread(_objectSpread({}, cells), {}, {
|
|
90
|
-
expandIcon: unexpandable ? ' ' : /*#__PURE__*/_react.default.createElement(_ffeIconsReact.Icon, {
|
|
91
|
-
className: (0, _classnames.default)('ffe-table__expand-icon', {
|
|
92
|
-
'ffe-table__expand-icon--expanded': this.state.expanded
|
|
93
|
-
}),
|
|
94
|
-
fileUrl: "data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIGhlaWdodD0iMjQiIHZpZXdCb3g9IjAgLTk2MCA5NjAgOTYwIiB3aWR0aD0iMjQiPjxwYXRoIGQ9Ik00ODAtMzczLjUzOXEtNy4yMzEgMC0xMy40NjEtMi4zMDgtNi4yMzEtMi4zMDgtMTEuODQ2LTcuOTIzTDI3NC45MjQtNTYzLjUzOXEtOC4zMDgtOC4zMDctOC41LTIwLjg4NC0uMTkzLTEyLjU3NyA4LjUtMjEuMjY5IDguNjkyLTguNjkyIDIxLjA3Ni04LjY5MnQyMS4wNzYgOC42OTJMNDgwLTQ0Mi43NjhsMTYyLjkyNC0xNjIuOTI0cTguMzA3LTguMzA3IDIwLjg4NC04LjUgMTIuNTc2LS4xOTIgMjEuMjY4IDguNSA4LjY5MyA4LjY5MiA4LjY5MyAyMS4wNzcgMCAxMi4zODQtOC42OTMgMjEuMDc2TDUwNS4zMDctMzgzLjc3cS01LjYxNSA1LjYxNS0xMS44NDYgNy45MjMtNi4yMyAyLjMwOC0xMy40NjEgMi4zMDhaIi8+PC9zdmc+",
|
|
95
|
-
size: "md"
|
|
96
|
-
})
|
|
97
|
-
}),
|
|
98
|
-
trClasses: (0, _classnames.default)({
|
|
99
|
-
'ffe-table__row-expandable': !unexpandable
|
|
100
|
-
}, {
|
|
101
|
-
'ffe-table__row-expandable--expanded': this.state.expanded
|
|
102
|
-
}),
|
|
103
|
-
columns: columns,
|
|
104
|
-
onClick: this.toggleExpand,
|
|
105
|
-
onKeyDown: this.handleKeyPress,
|
|
106
|
-
expandable: !unexpandable,
|
|
107
|
-
expanded: this.state.expanded,
|
|
108
|
-
rowRender: rowRender,
|
|
109
|
-
rowIndex: rowIndex
|
|
110
|
-
}), /*#__PURE__*/_react.default.createElement("tr", {
|
|
111
|
-
role: "presentation",
|
|
112
|
-
"aria-hidden": String(!this.state.expanded),
|
|
113
|
-
className: (0, _classnames.default)('ffe-table__row', 'ffe-table__row-expandable-content', {
|
|
114
|
-
'ffe-table__row-expandable-content--expanded': this.state.expanded
|
|
115
|
-
}, {
|
|
116
|
-
'ffe-table__row--collapsed': !this.state.expanded
|
|
117
|
-
})
|
|
118
|
-
}, /*#__PURE__*/_react.default.createElement("td", {
|
|
119
|
-
colSpan: columns.length,
|
|
120
|
-
className: "ffe-table__cell-expandable-content"
|
|
121
|
-
}, /*#__PURE__*/_react.default.createElement("div", null, this.state.expanded && children))));
|
|
9
|
+
return function (d, b) {
|
|
10
|
+
if (typeof b !== "function" && b !== null)
|
|
11
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
+
extendStatics(d, b);
|
|
13
|
+
function __() { this.constructor = d; }
|
|
14
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
+
};
|
|
16
|
+
})();
|
|
17
|
+
var __assign = (this && this.__assign) || function () {
|
|
18
|
+
__assign = Object.assign || function(t) {
|
|
19
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
20
|
+
s = arguments[i];
|
|
21
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
22
|
+
t[p] = s[p];
|
|
23
|
+
}
|
|
24
|
+
return t;
|
|
25
|
+
};
|
|
26
|
+
return __assign.apply(this, arguments);
|
|
27
|
+
};
|
|
28
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
29
|
+
if (k2 === undefined) k2 = k;
|
|
30
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
31
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
32
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
122
33
|
}
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
34
|
+
Object.defineProperty(o, k2, desc);
|
|
35
|
+
}) : (function(o, m, k, k2) {
|
|
36
|
+
if (k2 === undefined) k2 = k;
|
|
37
|
+
o[k2] = m[k];
|
|
38
|
+
}));
|
|
39
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
40
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
41
|
+
}) : function(o, v) {
|
|
42
|
+
o["default"] = v;
|
|
43
|
+
});
|
|
44
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
45
|
+
if (mod && mod.__esModule) return mod;
|
|
46
|
+
var result = {};
|
|
47
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
48
|
+
__setModuleDefault(result, mod);
|
|
49
|
+
return result;
|
|
50
|
+
};
|
|
51
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
52
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
53
|
+
};
|
|
54
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
55
|
+
var ffe_icons_react_1 = require("@sb1/ffe-icons-react");
|
|
56
|
+
var classnames_1 = __importDefault(require("classnames"));
|
|
57
|
+
var prop_types_1 = __importDefault(require("prop-types"));
|
|
58
|
+
var react_1 = __importStar(require("react"));
|
|
59
|
+
var react_lifecycles_compat_1 = require("react-lifecycles-compat");
|
|
60
|
+
var shallow_equals_1 = __importDefault(require("shallow-equals"));
|
|
61
|
+
var TableRow_1 = __importDefault(require("./TableRow"));
|
|
62
|
+
var TableRowExpandable = /** @class */ (function (_super) {
|
|
63
|
+
__extends(TableRowExpandable, _super);
|
|
64
|
+
function TableRowExpandable(props) {
|
|
65
|
+
var _this = _super.call(this, props) || this;
|
|
66
|
+
_this.handleKeyPress = _this.handleKeyPress.bind(_this);
|
|
67
|
+
_this.toggleExpand = _this.toggleExpand.bind(_this);
|
|
68
|
+
_this.state = {
|
|
69
|
+
expanded: !!props.defaultExpanded,
|
|
70
|
+
sort: props.sort,
|
|
130
71
|
};
|
|
131
|
-
|
|
132
|
-
|
|
72
|
+
_this.rowRef = react_1.default.createRef();
|
|
73
|
+
return _this;
|
|
133
74
|
}
|
|
134
|
-
|
|
135
|
-
|
|
75
|
+
TableRowExpandable.prototype.componentDidMount = function () {
|
|
76
|
+
if (this.props.scrollToOnMount && this.rowRef.current) {
|
|
77
|
+
this.rowRef.current.scrollIntoView();
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
TableRowExpandable.getDerivedStateFromProps = function (nextProps, prevState) {
|
|
81
|
+
if ((!nextProps.children && prevState.expanded) ||
|
|
82
|
+
!(0, shallow_equals_1.default)(nextProps.sort, prevState.sort)) {
|
|
83
|
+
return {
|
|
84
|
+
expanded: false,
|
|
85
|
+
sort: nextProps.sort,
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
return null;
|
|
89
|
+
};
|
|
90
|
+
TableRowExpandable.prototype.toggleExpand = function () {
|
|
91
|
+
this.setState(function (prevState) { return ({ expanded: !prevState.expanded }); });
|
|
92
|
+
};
|
|
93
|
+
TableRowExpandable.prototype.handleKeyPress = function (event) {
|
|
94
|
+
if ((event.key === 'Enter' || event.key === ' ') &&
|
|
95
|
+
event.target.tagName === 'TR') {
|
|
96
|
+
this.setState(function (prevState) { return ({ expanded: !prevState.expanded }); });
|
|
97
|
+
event.preventDefault();
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
TableRowExpandable.prototype.render = function () {
|
|
101
|
+
var _a = this.props, cells = _a.cells, columns = _a.columns, children = _a.children, rowRender = _a.rowRender, rowIndex = _a.rowIndex;
|
|
102
|
+
var unexpandable = !children;
|
|
103
|
+
return (react_1.default.createElement("tbody", { ref: this.rowRef },
|
|
104
|
+
react_1.default.createElement(TableRow_1.default, { cells: __assign(__assign({}, cells), { expandIcon: unexpandable ? (' ') : (react_1.default.createElement(ffe_icons_react_1.Icon, { className: (0, classnames_1.default)('ffe-table__expand-icon', {
|
|
105
|
+
'ffe-table__expand-icon--expanded': this.state.expanded,
|
|
106
|
+
}), fileUrl: "data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIGhlaWdodD0iMjQiIHZpZXdCb3g9IjAgLTk2MCA5NjAgOTYwIiB3aWR0aD0iMjQiPjxwYXRoIGQ9Ik00ODAtMzczLjUzOXEtNy4yMzEgMC0xMy40NjEtMi4zMDgtNi4yMzEtMi4zMDgtMTEuODQ2LTcuOTIzTDI3NC45MjQtNTYzLjUzOXEtOC4zMDgtOC4zMDctOC41LTIwLjg4NC0uMTkzLTEyLjU3NyA4LjUtMjEuMjY5IDguNjkyLTguNjkyIDIxLjA3Ni04LjY5MnQyMS4wNzYgOC42OTJMNDgwLTQ0Mi43NjhsMTYyLjkyNC0xNjIuOTI0cTguMzA3LTguMzA3IDIwLjg4NC04LjUgMTIuNTc2LS4xOTIgMjEuMjY4IDguNSA4LjY5MyA4LjY5MiA4LjY5MyAyMS4wNzcgMCAxMi4zODQtOC42OTMgMjEuMDc2TDUwNS4zMDctMzgzLjc3cS01LjYxNSA1LjYxNS0xMS44NDYgNy45MjMtNi4yMyAyLjMwOC0xMy40NjEgMi4zMDhaIi8+PC9zdmc+", size: "md" })) }), trClasses: (0, classnames_1.default)({ 'ffe-table__row-expandable': !unexpandable }, {
|
|
107
|
+
'ffe-table__row-expandable--expanded': this.state.expanded,
|
|
108
|
+
}), columns: columns, onClick: this.toggleExpand, onKeyDown: this.handleKeyPress, expandable: !unexpandable, expanded: this.state.expanded, rowRender: rowRender, rowIndex: rowIndex }),
|
|
109
|
+
react_1.default.createElement("tr", { role: "presentation", "aria-hidden": String(!this.state.expanded), className: (0, classnames_1.default)('ffe-table__row', 'ffe-table__row-expandable-content', {
|
|
110
|
+
'ffe-table__row-expandable-content--expanded': this.state.expanded,
|
|
111
|
+
}, { 'ffe-table__row--collapsed': !this.state.expanded }) },
|
|
112
|
+
react_1.default.createElement("td", { colSpan: columns.length, className: "ffe-table__cell-expandable-content" },
|
|
113
|
+
react_1.default.createElement("div", null, this.state.expanded && children)))));
|
|
114
|
+
};
|
|
115
|
+
return TableRowExpandable;
|
|
116
|
+
}(react_1.Component));
|
|
136
117
|
TableRowExpandable.propTypes = {
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
118
|
+
children: prop_types_1.default.node,
|
|
119
|
+
cells: prop_types_1.default.object.isRequired,
|
|
120
|
+
columns: prop_types_1.default.array.isRequired,
|
|
121
|
+
sort: prop_types_1.default.object,
|
|
122
|
+
rowRender: prop_types_1.default.func,
|
|
123
|
+
headerRender: prop_types_1.default.func,
|
|
124
|
+
footerRender: prop_types_1.default.func,
|
|
125
|
+
rowIndex: prop_types_1.default.number,
|
|
126
|
+
defaultExpanded: prop_types_1.default.bool,
|
|
127
|
+
scrollToOnMount: prop_types_1.default.bool,
|
|
147
128
|
};
|
|
148
|
-
(0,
|
|
149
|
-
|
|
129
|
+
(0, react_lifecycles_compat_1.polyfill)(TableRowExpandable);
|
|
130
|
+
exports.default = TableRowExpandable;
|
|
@@ -0,0 +1,104 @@
|
|
|
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 __importDefault = (this && this.__importDefault) || function (mod) {
|
|
14
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
var react_1 = __importDefault(require("react"));
|
|
18
|
+
var TableRowExpandable_1 = __importDefault(require("./TableRowExpandable"));
|
|
19
|
+
var props = {
|
|
20
|
+
cells: {
|
|
21
|
+
name: 'Ola Normann',
|
|
22
|
+
address: 'Gateveien 2',
|
|
23
|
+
age: 23,
|
|
24
|
+
phone: '912 34 567',
|
|
25
|
+
email: 'ola@normann.no',
|
|
26
|
+
},
|
|
27
|
+
columns: [
|
|
28
|
+
{ key: 'name', content: 'Navn' },
|
|
29
|
+
{ key: 'address', content: 'Adresse' },
|
|
30
|
+
{ key: 'age', content: 'Alder', alignRight: true },
|
|
31
|
+
{ key: 'phone', content: 'Telefon' },
|
|
32
|
+
{ key: 'email', content: 'E-post' },
|
|
33
|
+
],
|
|
34
|
+
};
|
|
35
|
+
var wrapper = shallow(react_1.default.createElement(TableRowExpandable_1.default, __assign({}, props),
|
|
36
|
+
react_1.default.createElement("p", null, "The cake is a lie")));
|
|
37
|
+
var unexpandableWrapper = shallow(react_1.default.createElement(TableRowExpandable_1.default, __assign({}, props), false && react_1.default.createElement("div", null, "Ignorance is bliss, and we won't render this")));
|
|
38
|
+
var defaultExpandedWrapper = shallow(react_1.default.createElement(TableRowExpandable_1.default, __assign({}, props, { defaultExpanded: true }),
|
|
39
|
+
react_1.default.createElement("p", null, "The cake is a lie")));
|
|
40
|
+
describe('<TableRowExpandable>', function () {
|
|
41
|
+
it('should be collapsed by default', function () {
|
|
42
|
+
expect(wrapper.state().expanded).toBe(false);
|
|
43
|
+
expect(wrapper.find('.ffe-table__row-expandable--expanded')).toHaveLength(0);
|
|
44
|
+
expect(wrapper
|
|
45
|
+
.find('.ffe-table__row-expandable-content')
|
|
46
|
+
.prop('aria-hidden')).toBe('true');
|
|
47
|
+
expect(wrapper
|
|
48
|
+
.find('.ffe-table__row-expandable-content')
|
|
49
|
+
.hasClass('ffe-table__row--collapsed')).toBe(true);
|
|
50
|
+
});
|
|
51
|
+
it('should be expanded if provided true defaultExpanded', function () {
|
|
52
|
+
expect(defaultExpandedWrapper.state().expanded).toBe(true);
|
|
53
|
+
expect(defaultExpandedWrapper.find('.ffe-table__row--collapsed')).toHaveLength(0);
|
|
54
|
+
expect(defaultExpandedWrapper
|
|
55
|
+
.find('.ffe-table__row-expandable-content')
|
|
56
|
+
.prop('aria-hidden')).toBe('false');
|
|
57
|
+
expect(defaultExpandedWrapper
|
|
58
|
+
.find('.ffe-table__row-expandable-content')
|
|
59
|
+
.hasClass('ffe-table__row-expandable-content--expanded')).toBe(true);
|
|
60
|
+
});
|
|
61
|
+
it('should scroll into view on mount if true scrollToOnMount is provided', function () {
|
|
62
|
+
var scrollIntoViewMock = jest.fn();
|
|
63
|
+
window.HTMLElement.prototype.scrollIntoView = scrollIntoViewMock;
|
|
64
|
+
mount(react_1.default.createElement(TableRowExpandable_1.default, __assign({}, props, { scrollToOnMount: true }),
|
|
65
|
+
react_1.default.createElement("p", null, "The cake is a lie")));
|
|
66
|
+
expect(scrollIntoViewMock).toHaveBeenCalledTimes(1);
|
|
67
|
+
});
|
|
68
|
+
it('should render expanded content', function () {
|
|
69
|
+
wrapper.setState({ expanded: true });
|
|
70
|
+
expect(wrapper.find('td').last().find('p').text()).toBe('The cake is a lie');
|
|
71
|
+
expect(wrapper
|
|
72
|
+
.find('tr')
|
|
73
|
+
.last()
|
|
74
|
+
.hasClass('ffe-table__row-expandable-content--expanded')).toBe(true);
|
|
75
|
+
expect(wrapper.find('tr').last().hasClass('ffe-table__row--collapsed')).toBe(false);
|
|
76
|
+
});
|
|
77
|
+
it('should pass correct props to TableRow component', function () {
|
|
78
|
+
wrapper.setState({ expanded: true });
|
|
79
|
+
var tableRow = wrapper.find('TableRow').props();
|
|
80
|
+
expect(tableRow.expanded).toBe(true);
|
|
81
|
+
expect(tableRow.columns).toBe(props.columns);
|
|
82
|
+
expect(tableRow.trClasses).toContain('ffe-table__row-expandable--expanded');
|
|
83
|
+
});
|
|
84
|
+
it('should pass an expand icon with correct classname to TableRow', function () {
|
|
85
|
+
wrapper.setState({ expanded: true });
|
|
86
|
+
var tableRow = wrapper.find('TableRow').props();
|
|
87
|
+
expect(tableRow.cells.expandIcon.props.className).toContain('ffe-table__expand-icon--expanded');
|
|
88
|
+
expect(tableRow.expandable).toBe(true);
|
|
89
|
+
});
|
|
90
|
+
it('should not pass an expand icon to TableRows that are not expandable', function () {
|
|
91
|
+
var tableRow = unexpandableWrapper.find('TableRow').props();
|
|
92
|
+
expect(tableRow.cells.expandIcon).toBe(' ');
|
|
93
|
+
expect(tableRow.expandable).toBe(false);
|
|
94
|
+
});
|
|
95
|
+
var renderedWrapper = render(react_1.default.createElement(TableRowExpandable_1.default, __assign({}, props),
|
|
96
|
+
react_1.default.createElement("p", null, "a Festivus for the rest of us")));
|
|
97
|
+
it('should render a tbody with two tr', function () {
|
|
98
|
+
expect(renderedWrapper.children()).toHaveLength(2);
|
|
99
|
+
});
|
|
100
|
+
it('should set the correct aria attributes on tr', function () {
|
|
101
|
+
expect(renderedWrapper.find('tr').first().prop('aria-expanded')).toBe('false');
|
|
102
|
+
expect(renderedWrapper.find('tr').last().prop('aria-hidden')).toBe('true');
|
|
103
|
+
});
|
|
104
|
+
});
|
package/lib/index.js
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
});
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
9
|
-
var _default = exports.default = _Table.default;
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
var Table_1 = __importDefault(require("./Table"));
|
|
7
|
+
exports.default = Table_1.default;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sb1/ffe-tables-react",
|
|
3
|
-
"version": "8.0.
|
|
3
|
+
"version": "8.0.32",
|
|
4
4
|
"description": "React implementation of ffe-tables",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "SpareBank 1",
|
|
@@ -18,16 +18,16 @@
|
|
|
18
18
|
"url": "ssh://git@github.com:SpareBank1/designsystem.git"
|
|
19
19
|
},
|
|
20
20
|
"scripts": {
|
|
21
|
-
"build": "ffe-buildtool
|
|
22
|
-
"
|
|
21
|
+
"build": "ffe-buildtool tsc --es --cjs && copyfiles --flat src/index.d.ts types",
|
|
22
|
+
"build:es": "ffe-buildtool tsc --es",
|
|
23
23
|
"lint": "eslint src",
|
|
24
24
|
"lint:fix": "eslint src --fix",
|
|
25
25
|
"test": "ffe-buildtool jest",
|
|
26
26
|
"test:watch": "ffe-buildtool jest --watch"
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@sb1/ffe-icons-react": "^10.0.
|
|
30
|
-
"@sb1/ffe-tables": "^14.0.
|
|
29
|
+
"@sb1/ffe-icons-react": "^10.0.3",
|
|
30
|
+
"@sb1/ffe-tables": "^14.0.20",
|
|
31
31
|
"classnames": "^2.3.1",
|
|
32
32
|
"deep-equal": "^1.0.1",
|
|
33
33
|
"memoize-one": "^5.0.0",
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
"shallow-equals": "^1.0.0"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
|
-
"@sb1/ffe-buildtool": "^0.6.
|
|
39
|
+
"@sb1/ffe-buildtool": "^0.6.3",
|
|
40
40
|
"react": "^16.9.0",
|
|
41
41
|
"react-dom": "^16.9.0",
|
|
42
42
|
"sinon": "^7.2.3"
|
|
@@ -47,5 +47,5 @@
|
|
|
47
47
|
"publishConfig": {
|
|
48
48
|
"access": "public"
|
|
49
49
|
},
|
|
50
|
-
"gitHead": "
|
|
50
|
+
"gitHead": "f9439b117955babfcd2ea4389d38618679598e2d"
|
|
51
51
|
}
|
package/es/index.d.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import * as React from 'react';
|
package/lib/index.d.js
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
4
|
-
var React = _interopRequireWildcard(require("react"));
|
|
5
|
-
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
|
|
6
|
-
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|