@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,210 +1,169 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
});
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
var _classnames = _interopRequireDefault(require("classnames"));
|
|
9
|
-
var _deepEqual = _interopRequireDefault(require("deep-equal"));
|
|
10
|
-
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
11
|
-
var _react = _interopRequireWildcard(require("react"));
|
|
12
|
-
var _Table = _interopRequireDefault(require("../Table"));
|
|
13
|
-
var _sortData = _interopRequireDefault(require("./sort-data"));
|
|
14
|
-
var _memoizeOne = _interopRequireDefault(require("memoize-one"));
|
|
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 _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); }
|
|
19
|
-
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; }
|
|
20
|
-
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; }
|
|
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 _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
|
|
25
|
-
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); }
|
|
26
|
-
function _assertThisInitialized(e) { if (void 0 === e) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); return e; }
|
|
27
|
-
function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
|
|
28
|
-
function _getPrototypeOf(t) { return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) { return t.__proto__ || Object.getPrototypeOf(t); }, _getPrototypeOf(t); }
|
|
29
|
-
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); }
|
|
30
|
-
function _setPrototypeOf(t, e) { return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) { return t.__proto__ = e, t; }, _setPrototypeOf(t, e); }
|
|
31
|
-
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; }
|
|
32
|
-
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
|
|
33
|
-
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); }
|
|
34
|
-
var SortableTable = /*#__PURE__*/function (_Component) {
|
|
35
|
-
function SortableTable(props) {
|
|
36
|
-
var _this;
|
|
37
|
-
_classCallCheck(this, SortableTable);
|
|
38
|
-
_this = _callSuper(this, SortableTable, [props]);
|
|
39
|
-
_defineProperty(_this, "sort", function (columns, data, sortBy, descending) {
|
|
40
|
-
var _this$props$onSort = _this.props.onSort,
|
|
41
|
-
onSort = _this$props$onSort === void 0 ? function () {} : _this$props$onSort;
|
|
42
|
-
var tableData = (0, _sortData.default)(columns, data, sortBy, descending);
|
|
43
|
-
onSort({
|
|
44
|
-
sortBy: sortBy,
|
|
45
|
-
descending: descending,
|
|
46
|
-
tableData: tableData
|
|
47
|
-
});
|
|
48
|
-
return tableData;
|
|
49
|
-
});
|
|
50
|
-
_defineProperty(_this, "sortTableData", (0, _memoizeOne.default)(function (columns, data, sortBy, descending) {
|
|
51
|
-
return sortBy ? _this.sort(columns, data, sortBy, descending) : data;
|
|
52
|
-
}));
|
|
53
|
-
var _sortBy = props.sortBy,
|
|
54
|
-
_props$descending = props.descending,
|
|
55
|
-
_descending = _props$descending === void 0 ? false : _props$descending;
|
|
56
|
-
_this.state = {
|
|
57
|
-
sortBy: _sortBy,
|
|
58
|
-
descending: _descending
|
|
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);
|
|
59
8
|
};
|
|
60
|
-
return
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
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]; } };
|
|
72
33
|
}
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
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 deep_equal_1 = __importDefault(require("deep-equal"));
|
|
58
|
+
var prop_types_1 = __importDefault(require("prop-types"));
|
|
59
|
+
var react_1 = __importStar(require("react"));
|
|
60
|
+
var Table_1 = __importDefault(require("../Table"));
|
|
61
|
+
var sort_data_1 = __importDefault(require("./sort-data"));
|
|
62
|
+
var memoize_one_1 = __importDefault(require("memoize-one"));
|
|
63
|
+
var SortableTable = /** @class */ (function (_super) {
|
|
64
|
+
__extends(SortableTable, _super);
|
|
65
|
+
function SortableTable(props) {
|
|
66
|
+
var _this = _super.call(this, props) || this;
|
|
67
|
+
_this.sort = function (columns, data, sortBy, descending) {
|
|
68
|
+
var _a = _this.props.onSort, onSort = _a === void 0 ? function () { } : _a;
|
|
69
|
+
var tableData = (0, sort_data_1.default)(columns, data, sortBy, descending);
|
|
70
|
+
onSort({
|
|
71
|
+
sortBy: sortBy,
|
|
72
|
+
descending: descending,
|
|
73
|
+
tableData: tableData,
|
|
74
|
+
});
|
|
75
|
+
return tableData;
|
|
81
76
|
};
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
}, {
|
|
85
|
-
key: "handleKeyPress",
|
|
86
|
-
value: function handleKeyPress(columnKey, event) {
|
|
87
|
-
if (event.key === 'Enter' || event.key === ' ') {
|
|
88
|
-
this.tableHeaderClicked(columnKey);
|
|
89
|
-
event.preventDefault();
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
}, {
|
|
93
|
-
key: "getAriaSort",
|
|
94
|
-
value: function getAriaSort(column) {
|
|
95
|
-
if (this.state.sortBy !== column.key) {
|
|
96
|
-
return 'none';
|
|
97
|
-
}
|
|
98
|
-
return this.state.descending ? 'descending' : 'ascending';
|
|
99
|
-
}
|
|
100
|
-
}, {
|
|
101
|
-
key: "decorateSortableTableHeader",
|
|
102
|
-
value: function decorateSortableTableHeader(column) {
|
|
103
|
-
var _this2 = this;
|
|
104
|
-
if (column.header === '') {
|
|
105
|
-
return /*#__PURE__*/_react.default.createElement("span", {
|
|
106
|
-
className: "ffe-sortable-table__header"
|
|
77
|
+
_this.sortTableData = (0, memoize_one_1.default)(function (columns, data, sortBy, descending) {
|
|
78
|
+
return sortBy ? _this.sort(columns, data, sortBy, descending) : data;
|
|
107
79
|
});
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
onKeyDown: function onKeyDown(event) {
|
|
115
|
-
return _this2.handleKeyPress(column.key, event);
|
|
116
|
-
},
|
|
117
|
-
className: (0, _classnames.default)('ffe-sortable-table__header', {
|
|
118
|
-
'ffe-sortable-table__header--active': this.state.sortBy === column.key
|
|
119
|
-
}),
|
|
120
|
-
role: "button",
|
|
121
|
-
onClick: this.tableHeaderClicked.bind(this, column.key)
|
|
122
|
-
}, column.header, /*#__PURE__*/_react.default.createElement(_ffeIconsReact.Icon, {
|
|
123
|
-
className: (0, _classnames.default)('icon', 'ffe-sortable-table__sort-arrow', {
|
|
124
|
-
'ffe-sortable-table__sort-arrow--descending': this.state.sortBy === column.key && this.state.descending
|
|
125
|
-
}),
|
|
126
|
-
fileUrl: "data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIGhlaWdodD0iMjQiIHZpZXdCb3g9IjAgLTk2MCA5NjAgOTYwIiB3aWR0aD0iMjQiPjxwYXRoIGQ9Ik00NjAuODA4LTM5My4wNCAzMzQuNzYzLTUxOS4wODRxLTIuNjA4LTIuNjA4LTQuMTA4LTUuODI0LTEuNS0zLjIxNy0xLjUtNi44OTMgMC03LjM1MiA0Ljk3Mi0xMi43NzUgNC45NzEtNS40MjMgMTMuMTA1LTUuNDIzaDI2NS41MzZxOC4xMzQgMCAxMy4xMDUgNS40NzUgNC45NzIgNS40NzYgNC45NzIgMTIuNzc2IDAgMS44MjYtNS42MTYgMTIuNjcyTDQ5OS4xOTItMzkzLjAzOXEtNC4zNDYgNC4zNDYtOC45ODUgNi4zNDYtNC42NCAyLTEwLjIwNyAyLTUuNTY3IDAtMTAuMjA3LTItNC42MzktMi04Ljk4NS02LjM0N1oiLz48L3N2Zz4=",
|
|
127
|
-
size: "md"
|
|
128
|
-
}));
|
|
80
|
+
var sortBy = props.sortBy, _a = props.descending, descending = _a === void 0 ? false : _a;
|
|
81
|
+
_this.state = {
|
|
82
|
+
sortBy: sortBy,
|
|
83
|
+
descending: descending,
|
|
84
|
+
};
|
|
85
|
+
return _this;
|
|
129
86
|
}
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
return
|
|
136
|
-
|
|
137
|
-
|
|
87
|
+
SortableTable.prototype.sortStateHasChanged = function (nextState) {
|
|
88
|
+
return (nextState.sortBy !== this.state.sortBy ||
|
|
89
|
+
nextState.descending !== this.state.descending);
|
|
90
|
+
};
|
|
91
|
+
SortableTable.prototype.shouldComponentUpdate = function (nextProps, nextState) {
|
|
92
|
+
return (!(0, deep_equal_1.default)(nextProps, this.props) || this.sortStateHasChanged(nextState));
|
|
93
|
+
};
|
|
94
|
+
SortableTable.prototype.tableHeaderClicked = function (columnKey) {
|
|
95
|
+
this.setState(function (prevState) {
|
|
96
|
+
var descending = columnKey === prevState.sortBy ? !prevState.descending : false;
|
|
97
|
+
return {
|
|
98
|
+
sortBy: columnKey,
|
|
99
|
+
descending: descending,
|
|
100
|
+
};
|
|
138
101
|
});
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
limit
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
className: className,
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
});
|
|
186
|
-
}
|
|
187
|
-
}]);
|
|
188
|
-
}(_react.Component);
|
|
102
|
+
};
|
|
103
|
+
SortableTable.prototype.handleKeyPress = function (columnKey, event) {
|
|
104
|
+
if (event.key === 'Enter' || event.key === ' ') {
|
|
105
|
+
this.tableHeaderClicked(columnKey);
|
|
106
|
+
event.preventDefault();
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
SortableTable.prototype.getAriaSort = function (column) {
|
|
110
|
+
if (this.state.sortBy !== column.key) {
|
|
111
|
+
return 'none';
|
|
112
|
+
}
|
|
113
|
+
return this.state.descending ? 'descending' : 'ascending';
|
|
114
|
+
};
|
|
115
|
+
SortableTable.prototype.decorateSortableTableHeader = function (column) {
|
|
116
|
+
var _this = this;
|
|
117
|
+
if (column.header === '') {
|
|
118
|
+
return react_1.default.createElement("span", { className: "ffe-sortable-table__header" });
|
|
119
|
+
}
|
|
120
|
+
if (column.notSortable) {
|
|
121
|
+
return column.header;
|
|
122
|
+
}
|
|
123
|
+
return (react_1.default.createElement("span", { tabIndex: "0", onKeyDown: function (event) { return _this.handleKeyPress(column.key, event); }, className: (0, classnames_1.default)('ffe-sortable-table__header', {
|
|
124
|
+
'ffe-sortable-table__header--active': this.state.sortBy === column.key,
|
|
125
|
+
}), role: "button", onClick: this.tableHeaderClicked.bind(this, column.key) },
|
|
126
|
+
column.header,
|
|
127
|
+
react_1.default.createElement(ffe_icons_react_1.Icon, { className: (0, classnames_1.default)('icon', 'ffe-sortable-table__sort-arrow', {
|
|
128
|
+
'ffe-sortable-table__sort-arrow--descending': this.state.sortBy === column.key &&
|
|
129
|
+
this.state.descending,
|
|
130
|
+
}), fileUrl: "data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIGhlaWdodD0iMjQiIHZpZXdCb3g9IjAgLTk2MCA5NjAgOTYwIiB3aWR0aD0iMjQiPjxwYXRoIGQ9Ik00NjAuODA4LTM5My4wNCAzMzQuNzYzLTUxOS4wODRxLTIuNjA4LTIuNjA4LTQuMTA4LTUuODI0LTEuNS0zLjIxNy0xLjUtNi44OTMgMC03LjM1MiA0Ljk3Mi0xMi43NzUgNC45NzEtNS40MjMgMTMuMTA1LTUuNDIzaDI2NS41MzZxOC4xMzQgMCAxMy4xMDUgNS40NzUgNC45NzIgNS40NzYgNC45NzIgMTIuNzc2IDAgMS44MjYtNS42MTYgMTIuNjcyTDQ5OS4xOTItMzkzLjAzOXEtNC4zNDYgNC4zNDYtOC45ODUgNi4zNDYtNC42NCAyLTEwLjIwNyAyLTUuNTY3IDAtMTAuMjA3LTItNC42MzktMi04Ljk4NS02LjM0N1oiLz48L3N2Zz4=", size: "md" })));
|
|
131
|
+
};
|
|
132
|
+
SortableTable.prototype.render = function () {
|
|
133
|
+
var _this = this;
|
|
134
|
+
var sortableColumns = this.props.columns.map(function (column) {
|
|
135
|
+
return __assign(__assign({}, column), { ariaSort: _this.getAriaSort(column), header: _this.decorateSortableTableHeader(column) });
|
|
136
|
+
});
|
|
137
|
+
var caption = this.props.caption;
|
|
138
|
+
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;
|
|
139
|
+
var _b = this.state, sortBy = _b.sortBy, descending = _b.descending;
|
|
140
|
+
if (srOnlyCaption && sortBy) {
|
|
141
|
+
caption = caption.concat(' ', sortBy, ' ', descending ? 'descending' : 'ascending');
|
|
142
|
+
}
|
|
143
|
+
var tableData = this.sortTableData(columns, data, sortBy, descending);
|
|
144
|
+
return (react_1.default.createElement(Table_1.default, { 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 }));
|
|
145
|
+
};
|
|
146
|
+
return SortableTable;
|
|
147
|
+
}(react_1.Component));
|
|
189
148
|
SortableTable.propTypes = {
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
149
|
+
caption: prop_types_1.default.node,
|
|
150
|
+
srOnlyCaption: prop_types_1.default.bool,
|
|
151
|
+
expandedContentMapper: prop_types_1.default.func,
|
|
152
|
+
offset: prop_types_1.default.number,
|
|
153
|
+
limit: prop_types_1.default.number,
|
|
154
|
+
columnLayoutMobile: prop_types_1.default.bool,
|
|
155
|
+
condensed: prop_types_1.default.bool,
|
|
156
|
+
smallHeader: prop_types_1.default.bool,
|
|
157
|
+
alignLeft: prop_types_1.default.bool,
|
|
158
|
+
breakpoint: prop_types_1.default.oneOf(['sm', 'none']),
|
|
159
|
+
columns: prop_types_1.default.arrayOf(prop_types_1.default.object).isRequired,
|
|
160
|
+
data: prop_types_1.default.arrayOf(prop_types_1.default.object).isRequired,
|
|
161
|
+
sortBy: prop_types_1.default.string,
|
|
162
|
+
descending: prop_types_1.default.bool,
|
|
163
|
+
onSort: prop_types_1.default.func,
|
|
164
|
+
rowRender: prop_types_1.default.func,
|
|
165
|
+
headerRender: prop_types_1.default.func,
|
|
166
|
+
footerRender: prop_types_1.default.func,
|
|
167
|
+
className: prop_types_1.default.string,
|
|
209
168
|
};
|
|
210
|
-
|
|
169
|
+
exports.default = SortableTable;
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"use strict";
|
|
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 react_1 = __importDefault(require("react"));
|
|
7
|
+
var sinon_1 = require("sinon");
|
|
8
|
+
var SortableTable_1 = __importDefault(require("./SortableTable"));
|
|
9
|
+
describe('<SortableTable>', function () {
|
|
10
|
+
var columns = [
|
|
11
|
+
{ header: 'Name', key: 'name' },
|
|
12
|
+
{ header: 'Age', key: 'age' },
|
|
13
|
+
{ header: 'Employee-id', key: 'id' },
|
|
14
|
+
{ header: '', key: 'button' },
|
|
15
|
+
];
|
|
16
|
+
var data = [
|
|
17
|
+
{
|
|
18
|
+
name: 'Zombie Mountain',
|
|
19
|
+
age: 36,
|
|
20
|
+
id: 2,
|
|
21
|
+
button: react_1.default.createElement("button", null, "poke"),
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
name: 'Daenerys Targaryen',
|
|
25
|
+
age: 16,
|
|
26
|
+
id: 4,
|
|
27
|
+
button: react_1.default.createElement("button", null, "poke"),
|
|
28
|
+
},
|
|
29
|
+
{ name: 'Ned Stark', age: 48, id: 3, button: react_1.default.createElement("button", null, "poke") },
|
|
30
|
+
{ name: 'Jon Snow', age: 20, id: 1, button: react_1.default.createElement("button", null, "poke") },
|
|
31
|
+
];
|
|
32
|
+
var wrapper = render(react_1.default.createElement(SortableTable_1.default, { columns: columns, data: data }));
|
|
33
|
+
it('should show right amount of th tags', function () {
|
|
34
|
+
expect(wrapper.find('th')).toHaveLength(columns.length);
|
|
35
|
+
});
|
|
36
|
+
it('should render a row for each data array entry', function () {
|
|
37
|
+
expect(wrapper.find('tbody tr')).toHaveLength(data.length);
|
|
38
|
+
});
|
|
39
|
+
it('should set data-th property on each cell rendered', function () {
|
|
40
|
+
expect(wrapper.find('[data-th]')).toHaveLength(data.length * columns.length);
|
|
41
|
+
});
|
|
42
|
+
it('should add `aria-sort` property', function () {
|
|
43
|
+
expect(wrapper.find('[aria-sort]')).toHaveLength(columns.length);
|
|
44
|
+
});
|
|
45
|
+
it('should not show sorting arrow if header is blank string', function () {
|
|
46
|
+
expect(wrapper.find('.ffe-sortable-table__sort-arrow').length).toBe(columns.length - 1);
|
|
47
|
+
});
|
|
48
|
+
it('should show buttons in table when passing in buttons in data', function () {
|
|
49
|
+
expect(wrapper.find('button').length).toBe(data.length);
|
|
50
|
+
});
|
|
51
|
+
it('should call onSort after sorting table', function () {
|
|
52
|
+
var onSort = (0, sinon_1.spy)();
|
|
53
|
+
var table = shallow(react_1.default.createElement(SortableTable_1.default, { columns: columns, data: data, onSort: onSort }));
|
|
54
|
+
table.instance().tableHeaderClicked('name');
|
|
55
|
+
sinon_1.assert.calledWith(onSort, (0, sinon_1.match)(function (val) {
|
|
56
|
+
return ('sortBy' in val && 'descending' in val && 'tableData' in val);
|
|
57
|
+
}));
|
|
58
|
+
});
|
|
59
|
+
it('should call onSort after initial sort', function () {
|
|
60
|
+
var onSort = (0, sinon_1.spy)();
|
|
61
|
+
shallow(react_1.default.createElement(SortableTable_1.default, { columns: columns, data: data, onSort: onSort, sortBy: 'name' }));
|
|
62
|
+
sinon_1.assert.calledWith(onSort, (0, sinon_1.match)(function (val) {
|
|
63
|
+
return ('sortBy' in val && 'descending' in val && 'tableData' in val);
|
|
64
|
+
}));
|
|
65
|
+
});
|
|
66
|
+
describe('condensed', function () {
|
|
67
|
+
it('should by default not be condensed', function () {
|
|
68
|
+
return expect(wrapper.find('.ffe-table--condensed')).toHaveLength(0);
|
|
69
|
+
});
|
|
70
|
+
var condensedWrapper = render(react_1.default.createElement(SortableTable_1.default, { condensed: true, columns: columns, data: data }));
|
|
71
|
+
it('can be condensed', function () { return expect(condensedWrapper).toHaveLength(1); });
|
|
72
|
+
});
|
|
73
|
+
});
|
|
@@ -1,38 +1,33 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
9
|
-
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
|
|
10
|
-
function _iterableToArray(r) { if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r); }
|
|
11
|
-
function _arrayWithoutHoles(r) { if (Array.isArray(r)) return _arrayLikeToArray(r); }
|
|
12
|
-
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
|
|
13
|
-
var _default = exports.default = function _default(columns, data, sortBy, descending) {
|
|
14
|
-
var sortedData = _toConsumableArray(data);
|
|
15
|
-
var compare = function compare(data1, data2) {
|
|
16
|
-
if (!isNaN(data1[sortBy])) {
|
|
17
|
-
return data1[sortBy] - data2[sortBy];
|
|
18
|
-
}
|
|
19
|
-
if (!data1[sortBy]) {
|
|
20
|
-
return data2[sortBy] ? 1 : 0;
|
|
2
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
3
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
4
|
+
if (ar || !(i in from)) {
|
|
5
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
6
|
+
ar[i] = from[i];
|
|
7
|
+
}
|
|
21
8
|
}
|
|
22
|
-
return
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
9
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.default = (function (columns, data, sortBy, descending) {
|
|
13
|
+
var sortedData = __spreadArray([], data, true);
|
|
14
|
+
var compare = function (data1, data2) {
|
|
15
|
+
if (!isNaN(data1[sortBy])) {
|
|
16
|
+
return data1[sortBy] - data2[sortBy];
|
|
17
|
+
}
|
|
18
|
+
if (!data1[sortBy]) {
|
|
19
|
+
return data2[sortBy] ? 1 : 0;
|
|
20
|
+
}
|
|
21
|
+
return data1[sortBy].localeCompare(data2[sortBy]);
|
|
31
22
|
};
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
23
|
+
var column = columns.find(function (col) { return col.key === sortBy; });
|
|
24
|
+
var customCompare = column && typeof column.compare === 'function' ? column.compare : null;
|
|
25
|
+
if (customCompare) {
|
|
26
|
+
compare = function (data1, data2) { return customCompare(data1[sortBy], data2[sortBy]); };
|
|
27
|
+
}
|
|
28
|
+
sortedData.sort(compare);
|
|
29
|
+
if (descending) {
|
|
30
|
+
sortedData.reverse();
|
|
31
|
+
}
|
|
32
|
+
return sortedData;
|
|
33
|
+
});
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
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 sort_data_1 = __importDefault(require("./sort-data"));
|
|
7
|
+
var columns = [
|
|
8
|
+
{ key: 'name', header: 'Name' },
|
|
9
|
+
{ key: 'age', header: 'Age' },
|
|
10
|
+
{ key: 'id', header: 'Employee-id' },
|
|
11
|
+
{
|
|
12
|
+
key: 'rand',
|
|
13
|
+
header: 'A random number with thousand separator needs a custom compare',
|
|
14
|
+
compare: function (a, b) { return a.replace(/\s/g, '') - b.replace(/\s/g, ''); },
|
|
15
|
+
},
|
|
16
|
+
];
|
|
17
|
+
var data = [
|
|
18
|
+
{ name: 'Zombie Mountain', age: 36, id: 2, rand: '69 873' },
|
|
19
|
+
{ name: 'Daenerys Targaryen', age: 16, id: 4, rand: '9 156' },
|
|
20
|
+
{ name: 'Ned Stark', age: 48, id: 3, rand: '3 863 914' },
|
|
21
|
+
{ name: 'Jon Snow', age: 20, id: 1, rand: '145 678' },
|
|
22
|
+
];
|
|
23
|
+
describe('sortData', function () {
|
|
24
|
+
it('should sort data in descending order', function () {
|
|
25
|
+
var ascendingTableData = (0, sort_data_1.default)(columns, data, 'age', true);
|
|
26
|
+
for (var i = 1; i > ascendingTableData.length; i++) {
|
|
27
|
+
expect(ascendingTableData[i].id).toBeLessThan(ascendingTableData[i - 1].id);
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
it('should sort data in ascending order', function () {
|
|
31
|
+
var ascendingTableData = (0, sort_data_1.default)(columns, data, 'age', false);
|
|
32
|
+
for (var i = 1; i > ascendingTableData.length; i++) {
|
|
33
|
+
expect(ascendingTableData[i].id).toBeGreaterThan(ascendingTableData[i - 1].id);
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
it('should sort data based on `sortBy` parameter', function () {
|
|
37
|
+
var tableData = (0, sort_data_1.default)(columns, data, 'age', true);
|
|
38
|
+
expect(tableData[0].age).toBe(48);
|
|
39
|
+
expect(tableData[1].age).toBe(36);
|
|
40
|
+
expect(tableData[2].age).toBe(20);
|
|
41
|
+
expect(tableData[3].age).toBe(16);
|
|
42
|
+
});
|
|
43
|
+
it('should sort data even though an attribute is not set', function () {
|
|
44
|
+
data[3] = { name: 'Jon Snow', id: 1, rand: '145 678' }; // no age key
|
|
45
|
+
var tableData = (0, sort_data_1.default)(columns, data, 'age', false);
|
|
46
|
+
expect(tableData[0].age).toBe(16);
|
|
47
|
+
expect(tableData[1].age).toBe(36);
|
|
48
|
+
expect(tableData[2].age).toBe(48);
|
|
49
|
+
expect(tableData[3].age).toBe(undefined);
|
|
50
|
+
});
|
|
51
|
+
it('should sort data with a custom compare function when provided', function () {
|
|
52
|
+
var tableData = (0, sort_data_1.default)(columns, data, 'rand', false);
|
|
53
|
+
expect(tableData[0].rand).toBe('9 156');
|
|
54
|
+
expect(tableData[1].rand).toBe('69 873');
|
|
55
|
+
expect(tableData[2].rand).toBe('145 678');
|
|
56
|
+
expect(tableData[3].rand).toBe('3 863 914');
|
|
57
|
+
});
|
|
58
|
+
});
|