@sb1/ffe-tables-react 8.0.31 → 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.
@@ -1,81 +1,61 @@
1
- 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); }
2
- 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; }
3
- 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; }
4
- 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; }
5
- function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
6
- 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); }
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
+ };
7
12
  import React from 'react';
8
13
  import PropTypes from 'prop-types';
9
14
  import classNames from 'classnames';
10
15
  import TableCell from './TableCell';
11
- var TableRow = function TableRow(props) {
12
- var cells = props.cells,
13
- columns = props.columns,
14
- onClick = props.onClick,
15
- onKeyDown = props.onKeyDown,
16
- trClasses = props.trClasses,
17
- expandable = props.expandable,
18
- expanded = props.expanded,
19
- rowRender = props.rowRender,
20
- rowIndex = props.rowIndex;
21
- var expandableProps = expandable && {
22
- 'aria-expanded': expanded,
23
- onClick: onClick,
24
- onKeyDown: onKeyDown,
25
- role: 'button',
26
- tabIndex: '0'
27
- };
28
- var rowContent = columns.map(function (column, index) {
29
- return /*#__PURE__*/React.createElement(TableCell, {
30
- alignRight: column.alignRight,
31
- alignTop: column.alignTop,
32
- columnHeader: column.header,
33
- key: index,
34
- tdClasses: classNames({
35
- 'ffe-table__cell--collapsed': column.key === 'expandIcon'
36
- }, {
37
- 'ffe-table--hide-sm': column.hideOnMobile
38
- }, {
39
- 'ffe-table--hide-md': column.hideOnSmallTablet
40
- }, {
41
- 'ffe-table--hide-lg': column.hideOnTablet
42
- }, {
43
- 'ffe-table--hide-xlg': column.hideOnDesktop
44
- })
45
- }, column.cellRender ? column.cellRender(cells[column.key], column, props, index) : cells[column.key]);
46
- });
47
- var trprops = _objectSpread(_objectSpread({
48
- className: classNames('ffe-table__row', trClasses)
49
- }, expandableProps), {}, {
50
- onClick: onClick,
51
- children: rowContent
52
- });
53
- if (typeof rowRender === 'function') {
54
- return rowRender(trprops, props, rowIndex);
55
- }
56
- return /*#__PURE__*/React.createElement("tr", trprops, rowContent);
16
+ var TableRow = function (props) {
17
+ var cells = props.cells, columns = props.columns, onClick = props.onClick, onKeyDown = props.onKeyDown, trClasses = props.trClasses, expandable = props.expandable, expanded = props.expanded, rowRender = props.rowRender, rowIndex = props.rowIndex;
18
+ var expandableProps = expandable && {
19
+ 'aria-expanded': expanded,
20
+ onClick: onClick,
21
+ onKeyDown: onKeyDown,
22
+ role: 'button',
23
+ tabIndex: '0',
24
+ };
25
+ var rowContent = columns.map(function (column, index) {
26
+ return (React.createElement(TableCell, { alignRight: column.alignRight, alignTop: column.alignTop, columnHeader: column.header, key: index, tdClasses: classNames({
27
+ 'ffe-table__cell--collapsed': column.key === 'expandIcon',
28
+ }, { 'ffe-table--hide-sm': column.hideOnMobile }, { 'ffe-table--hide-md': column.hideOnSmallTablet }, { 'ffe-table--hide-lg': column.hideOnTablet }, { 'ffe-table--hide-xlg': column.hideOnDesktop }) }, column.cellRender
29
+ ? column.cellRender(cells[column.key], column, props, index)
30
+ : cells[column.key]));
31
+ });
32
+ var trprops = __assign(__assign({ className: classNames('ffe-table__row', trClasses) }, expandableProps), { onClick: onClick, children: rowContent });
33
+ if (typeof rowRender === 'function') {
34
+ return rowRender(trprops, props, rowIndex);
35
+ }
36
+ return React.createElement("tr", __assign({}, trprops), rowContent);
57
37
  };
58
38
  TableRow.propTypes = {
59
- cells: PropTypes.object.isRequired,
60
- columns: PropTypes.arrayOf(PropTypes.shape({
61
- alignRight: PropTypes.bool,
62
- alignTop: PropTypes.bool,
63
- header: PropTypes.any,
64
- hideOnDesktop: PropTypes.bool,
65
- hideOnMobile: PropTypes.bool,
66
- hideOnSmallTablet: PropTypes.bool,
67
- hideOnTablet: PropTypes.bool,
68
- key: PropTypes.string,
69
- cellRender: PropTypes.func
70
- })).isRequired,
71
- expandable: PropTypes.bool,
72
- expanded: PropTypes.bool,
73
- onClick: PropTypes.func,
74
- rowRender: PropTypes.func,
75
- headerRender: PropTypes.func,
76
- footerRender: PropTypes.func,
77
- onKeyDown: PropTypes.func,
78
- trClasses: PropTypes.string,
79
- rowIndex: PropTypes.number
39
+ cells: PropTypes.object.isRequired,
40
+ columns: PropTypes.arrayOf(PropTypes.shape({
41
+ alignRight: PropTypes.bool,
42
+ alignTop: PropTypes.bool,
43
+ header: PropTypes.any,
44
+ hideOnDesktop: PropTypes.bool,
45
+ hideOnMobile: PropTypes.bool,
46
+ hideOnSmallTablet: PropTypes.bool,
47
+ hideOnTablet: PropTypes.bool,
48
+ key: PropTypes.string,
49
+ cellRender: PropTypes.func,
50
+ })).isRequired,
51
+ expandable: PropTypes.bool,
52
+ expanded: PropTypes.bool,
53
+ onClick: PropTypes.func,
54
+ rowRender: PropTypes.func,
55
+ headerRender: PropTypes.func,
56
+ footerRender: PropTypes.func,
57
+ onKeyDown: PropTypes.func,
58
+ trClasses: PropTypes.string,
59
+ rowIndex: PropTypes.number,
80
60
  };
81
- export default TableRow;
61
+ export default TableRow;
@@ -1,19 +1,29 @@
1
- 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); }
2
- 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; }
3
- 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; }
4
- 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; }
5
- function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
6
- 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); } }
7
- function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
8
- function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
9
- 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); }
10
- function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
11
- 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); }
12
- function _assertThisInitialized(e) { if (void 0 === e) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); return e; }
13
- function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
14
- function _getPrototypeOf(t) { return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) { return t.__proto__ || Object.getPrototypeOf(t); }, _getPrototypeOf(t); }
15
- 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); }
16
- function _setPrototypeOf(t, e) { return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) { return t.__proto__ = e, t; }, _setPrototypeOf(t, e); }
1
+ var __extends = (this && this.__extends) || (function () {
2
+ var extendStatics = function (d, b) {
3
+ extendStatics = Object.setPrototypeOf ||
4
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
5
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
6
+ return extendStatics(d, b);
7
+ };
8
+ return function (d, b) {
9
+ if (typeof b !== "function" && b !== null)
10
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
11
+ extendStatics(d, b);
12
+ function __() { this.constructor = d; }
13
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
14
+ };
15
+ })();
16
+ var __assign = (this && this.__assign) || function () {
17
+ __assign = Object.assign || function(t) {
18
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
19
+ s = arguments[i];
20
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
21
+ t[p] = s[p];
22
+ }
23
+ return t;
24
+ };
25
+ return __assign.apply(this, arguments);
26
+ };
17
27
  import { Icon } from '@sb1/ffe-icons-react';
18
28
  import classNames from 'classnames';
19
29
  import PropTypes from 'prop-types';
@@ -21,120 +31,72 @@ import React, { Component } from 'react';
21
31
  import { polyfill } from 'react-lifecycles-compat';
22
32
  import shallowEqual from 'shallow-equals';
23
33
  import TableRow from './TableRow';
24
- var TableRowExpandable = /*#__PURE__*/function (_Component) {
25
- function TableRowExpandable(props) {
26
- var _this;
27
- _classCallCheck(this, TableRowExpandable);
28
- _this = _callSuper(this, TableRowExpandable, [props]);
29
- _this.handleKeyPress = _this.handleKeyPress.bind(_this);
30
- _this.toggleExpand = _this.toggleExpand.bind(_this);
31
- _this.state = {
32
- expanded: !!props.defaultExpanded,
33
- sort: props.sort
34
- };
35
- _this.rowRef = /*#__PURE__*/React.createRef();
36
- return _this;
37
- }
38
- _inherits(TableRowExpandable, _Component);
39
- return _createClass(TableRowExpandable, [{
40
- key: "componentDidMount",
41
- value: function componentDidMount() {
42
- if (this.props.scrollToOnMount && this.rowRef.current) {
43
- this.rowRef.current.scrollIntoView();
44
- }
45
- }
46
- }, {
47
- key: "toggleExpand",
48
- value: function toggleExpand() {
49
- this.setState(function (prevState) {
50
- return {
51
- expanded: !prevState.expanded
34
+ var TableRowExpandable = /** @class */ (function (_super) {
35
+ __extends(TableRowExpandable, _super);
36
+ function TableRowExpandable(props) {
37
+ var _this = _super.call(this, props) || this;
38
+ _this.handleKeyPress = _this.handleKeyPress.bind(_this);
39
+ _this.toggleExpand = _this.toggleExpand.bind(_this);
40
+ _this.state = {
41
+ expanded: !!props.defaultExpanded,
42
+ sort: props.sort,
52
43
  };
53
- });
54
- }
55
- }, {
56
- key: "handleKeyPress",
57
- value: function handleKeyPress(event) {
58
- if ((event.key === 'Enter' || event.key === ' ') && event.target.tagName === 'TR') {
59
- this.setState(function (prevState) {
60
- return {
61
- expanded: !prevState.expanded
62
- };
63
- });
64
- event.preventDefault();
65
- }
66
- }
67
- }, {
68
- key: "render",
69
- value: function render() {
70
- var _this$props = this.props,
71
- cells = _this$props.cells,
72
- columns = _this$props.columns,
73
- children = _this$props.children,
74
- rowRender = _this$props.rowRender,
75
- rowIndex = _this$props.rowIndex;
76
- var unexpandable = !children;
77
- return /*#__PURE__*/React.createElement("tbody", {
78
- ref: this.rowRef
79
- }, /*#__PURE__*/React.createElement(TableRow, {
80
- cells: _objectSpread(_objectSpread({}, cells), {}, {
81
- expandIcon: unexpandable ? ' ' : /*#__PURE__*/React.createElement(Icon, {
82
- className: classNames('ffe-table__expand-icon', {
83
- 'ffe-table__expand-icon--expanded': this.state.expanded
84
- }),
85
- fileUrl: "data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIGhlaWdodD0iMjQiIHZpZXdCb3g9IjAgLTk2MCA5NjAgOTYwIiB3aWR0aD0iMjQiPjxwYXRoIGQ9Ik00ODAtMzczLjUzOXEtNy4yMzEgMC0xMy40NjEtMi4zMDgtNi4yMzEtMi4zMDgtMTEuODQ2LTcuOTIzTDI3NC45MjQtNTYzLjUzOXEtOC4zMDgtOC4zMDctOC41LTIwLjg4NC0uMTkzLTEyLjU3NyA4LjUtMjEuMjY5IDguNjkyLTguNjkyIDIxLjA3Ni04LjY5MnQyMS4wNzYgOC42OTJMNDgwLTQ0Mi43NjhsMTYyLjkyNC0xNjIuOTI0cTguMzA3LTguMzA3IDIwLjg4NC04LjUgMTIuNTc2LS4xOTIgMjEuMjY4IDguNSA4LjY5MyA4LjY5MiA4LjY5MyAyMS4wNzcgMCAxMi4zODQtOC42OTMgMjEuMDc2TDUwNS4zMDctMzgzLjc3cS01LjYxNSA1LjYxNS0xMS44NDYgNy45MjMtNi4yMyAyLjMwOC0xMy40NjEgMi4zMDhaIi8+PC9zdmc+",
86
- size: "md"
87
- })
88
- }),
89
- trClasses: classNames({
90
- 'ffe-table__row-expandable': !unexpandable
91
- }, {
92
- 'ffe-table__row-expandable--expanded': this.state.expanded
93
- }),
94
- columns: columns,
95
- onClick: this.toggleExpand,
96
- onKeyDown: this.handleKeyPress,
97
- expandable: !unexpandable,
98
- expanded: this.state.expanded,
99
- rowRender: rowRender,
100
- rowIndex: rowIndex
101
- }), /*#__PURE__*/React.createElement("tr", {
102
- role: "presentation",
103
- "aria-hidden": String(!this.state.expanded),
104
- className: classNames('ffe-table__row', 'ffe-table__row-expandable-content', {
105
- 'ffe-table__row-expandable-content--expanded': this.state.expanded
106
- }, {
107
- 'ffe-table__row--collapsed': !this.state.expanded
108
- })
109
- }, /*#__PURE__*/React.createElement("td", {
110
- colSpan: columns.length,
111
- className: "ffe-table__cell-expandable-content"
112
- }, /*#__PURE__*/React.createElement("div", null, this.state.expanded && children))));
44
+ _this.rowRef = React.createRef();
45
+ return _this;
113
46
  }
114
- }], [{
115
- key: "getDerivedStateFromProps",
116
- value: function getDerivedStateFromProps(nextProps, prevState) {
117
- if (!nextProps.children && prevState.expanded || !shallowEqual(nextProps.sort, prevState.sort)) {
118
- return {
119
- expanded: false,
120
- sort: nextProps.sort
121
- };
122
- }
123
- return null;
124
- }
125
- }]);
126
- }(Component);
47
+ TableRowExpandable.prototype.componentDidMount = function () {
48
+ if (this.props.scrollToOnMount && this.rowRef.current) {
49
+ this.rowRef.current.scrollIntoView();
50
+ }
51
+ };
52
+ TableRowExpandable.getDerivedStateFromProps = function (nextProps, prevState) {
53
+ if ((!nextProps.children && prevState.expanded) ||
54
+ !shallowEqual(nextProps.sort, prevState.sort)) {
55
+ return {
56
+ expanded: false,
57
+ sort: nextProps.sort,
58
+ };
59
+ }
60
+ return null;
61
+ };
62
+ TableRowExpandable.prototype.toggleExpand = function () {
63
+ this.setState(function (prevState) { return ({ expanded: !prevState.expanded }); });
64
+ };
65
+ TableRowExpandable.prototype.handleKeyPress = function (event) {
66
+ if ((event.key === 'Enter' || event.key === ' ') &&
67
+ event.target.tagName === 'TR') {
68
+ this.setState(function (prevState) { return ({ expanded: !prevState.expanded }); });
69
+ event.preventDefault();
70
+ }
71
+ };
72
+ TableRowExpandable.prototype.render = function () {
73
+ var _a = this.props, cells = _a.cells, columns = _a.columns, children = _a.children, rowRender = _a.rowRender, rowIndex = _a.rowIndex;
74
+ var unexpandable = !children;
75
+ return (React.createElement("tbody", { ref: this.rowRef },
76
+ React.createElement(TableRow, { cells: __assign(__assign({}, cells), { expandIcon: unexpandable ? (' ') : (React.createElement(Icon, { className: classNames('ffe-table__expand-icon', {
77
+ 'ffe-table__expand-icon--expanded': this.state.expanded,
78
+ }), fileUrl: "data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIGhlaWdodD0iMjQiIHZpZXdCb3g9IjAgLTk2MCA5NjAgOTYwIiB3aWR0aD0iMjQiPjxwYXRoIGQ9Ik00ODAtMzczLjUzOXEtNy4yMzEgMC0xMy40NjEtMi4zMDgtNi4yMzEtMi4zMDgtMTEuODQ2LTcuOTIzTDI3NC45MjQtNTYzLjUzOXEtOC4zMDgtOC4zMDctOC41LTIwLjg4NC0uMTkzLTEyLjU3NyA4LjUtMjEuMjY5IDguNjkyLTguNjkyIDIxLjA3Ni04LjY5MnQyMS4wNzYgOC42OTJMNDgwLTQ0Mi43NjhsMTYyLjkyNC0xNjIuOTI0cTguMzA3LTguMzA3IDIwLjg4NC04LjUgMTIuNTc2LS4xOTIgMjEuMjY4IDguNSA4LjY5MyA4LjY5MiA4LjY5MyAyMS4wNzcgMCAxMi4zODQtOC42OTMgMjEuMDc2TDUwNS4zMDctMzgzLjc3cS01LjYxNSA1LjYxNS0xMS44NDYgNy45MjMtNi4yMyAyLjMwOC0xMy40NjEgMi4zMDhaIi8+PC9zdmc+", size: "md" })) }), trClasses: classNames({ 'ffe-table__row-expandable': !unexpandable }, {
79
+ 'ffe-table__row-expandable--expanded': this.state.expanded,
80
+ }), columns: columns, onClick: this.toggleExpand, onKeyDown: this.handleKeyPress, expandable: !unexpandable, expanded: this.state.expanded, rowRender: rowRender, rowIndex: rowIndex }),
81
+ React.createElement("tr", { role: "presentation", "aria-hidden": String(!this.state.expanded), className: classNames('ffe-table__row', 'ffe-table__row-expandable-content', {
82
+ 'ffe-table__row-expandable-content--expanded': this.state.expanded,
83
+ }, { 'ffe-table__row--collapsed': !this.state.expanded }) },
84
+ React.createElement("td", { colSpan: columns.length, className: "ffe-table__cell-expandable-content" },
85
+ React.createElement("div", null, this.state.expanded && children)))));
86
+ };
87
+ return TableRowExpandable;
88
+ }(Component));
127
89
  TableRowExpandable.propTypes = {
128
- children: PropTypes.node,
129
- cells: PropTypes.object.isRequired,
130
- columns: PropTypes.array.isRequired,
131
- sort: PropTypes.object,
132
- rowRender: PropTypes.func,
133
- headerRender: PropTypes.func,
134
- footerRender: PropTypes.func,
135
- rowIndex: PropTypes.number,
136
- defaultExpanded: PropTypes.bool,
137
- scrollToOnMount: PropTypes.bool
90
+ children: PropTypes.node,
91
+ cells: PropTypes.object.isRequired,
92
+ columns: PropTypes.array.isRequired,
93
+ sort: PropTypes.object,
94
+ rowRender: PropTypes.func,
95
+ headerRender: PropTypes.func,
96
+ footerRender: PropTypes.func,
97
+ rowIndex: PropTypes.number,
98
+ defaultExpanded: PropTypes.bool,
99
+ scrollToOnMount: PropTypes.bool,
138
100
  };
139
101
  polyfill(TableRowExpandable);
140
- export default TableRowExpandable;
102
+ export default TableRowExpandable;
@@ -0,0 +1,99 @@
1
+ var __assign = (this && this.__assign) || function () {
2
+ __assign = Object.assign || function(t) {
3
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
4
+ s = arguments[i];
5
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
6
+ t[p] = s[p];
7
+ }
8
+ return t;
9
+ };
10
+ return __assign.apply(this, arguments);
11
+ };
12
+ import React from 'react';
13
+ import TableRowExpandable from './TableRowExpandable';
14
+ var props = {
15
+ cells: {
16
+ name: 'Ola Normann',
17
+ address: 'Gateveien 2',
18
+ age: 23,
19
+ phone: '912 34 567',
20
+ email: 'ola@normann.no',
21
+ },
22
+ columns: [
23
+ { key: 'name', content: 'Navn' },
24
+ { key: 'address', content: 'Adresse' },
25
+ { key: 'age', content: 'Alder', alignRight: true },
26
+ { key: 'phone', content: 'Telefon' },
27
+ { key: 'email', content: 'E-post' },
28
+ ],
29
+ };
30
+ var wrapper = shallow(React.createElement(TableRowExpandable, __assign({}, props),
31
+ React.createElement("p", null, "The cake is a lie")));
32
+ var unexpandableWrapper = shallow(React.createElement(TableRowExpandable, __assign({}, props), false && React.createElement("div", null, "Ignorance is bliss, and we won't render this")));
33
+ var defaultExpandedWrapper = shallow(React.createElement(TableRowExpandable, __assign({}, props, { defaultExpanded: true }),
34
+ React.createElement("p", null, "The cake is a lie")));
35
+ describe('<TableRowExpandable>', function () {
36
+ it('should be collapsed by default', function () {
37
+ expect(wrapper.state().expanded).toBe(false);
38
+ expect(wrapper.find('.ffe-table__row-expandable--expanded')).toHaveLength(0);
39
+ expect(wrapper
40
+ .find('.ffe-table__row-expandable-content')
41
+ .prop('aria-hidden')).toBe('true');
42
+ expect(wrapper
43
+ .find('.ffe-table__row-expandable-content')
44
+ .hasClass('ffe-table__row--collapsed')).toBe(true);
45
+ });
46
+ it('should be expanded if provided true defaultExpanded', function () {
47
+ expect(defaultExpandedWrapper.state().expanded).toBe(true);
48
+ expect(defaultExpandedWrapper.find('.ffe-table__row--collapsed')).toHaveLength(0);
49
+ expect(defaultExpandedWrapper
50
+ .find('.ffe-table__row-expandable-content')
51
+ .prop('aria-hidden')).toBe('false');
52
+ expect(defaultExpandedWrapper
53
+ .find('.ffe-table__row-expandable-content')
54
+ .hasClass('ffe-table__row-expandable-content--expanded')).toBe(true);
55
+ });
56
+ it('should scroll into view on mount if true scrollToOnMount is provided', function () {
57
+ var scrollIntoViewMock = jest.fn();
58
+ window.HTMLElement.prototype.scrollIntoView = scrollIntoViewMock;
59
+ mount(React.createElement(TableRowExpandable, __assign({}, props, { scrollToOnMount: true }),
60
+ React.createElement("p", null, "The cake is a lie")));
61
+ expect(scrollIntoViewMock).toHaveBeenCalledTimes(1);
62
+ });
63
+ it('should render expanded content', function () {
64
+ wrapper.setState({ expanded: true });
65
+ expect(wrapper.find('td').last().find('p').text()).toBe('The cake is a lie');
66
+ expect(wrapper
67
+ .find('tr')
68
+ .last()
69
+ .hasClass('ffe-table__row-expandable-content--expanded')).toBe(true);
70
+ expect(wrapper.find('tr').last().hasClass('ffe-table__row--collapsed')).toBe(false);
71
+ });
72
+ it('should pass correct props to TableRow component', function () {
73
+ wrapper.setState({ expanded: true });
74
+ var tableRow = wrapper.find('TableRow').props();
75
+ expect(tableRow.expanded).toBe(true);
76
+ expect(tableRow.columns).toBe(props.columns);
77
+ expect(tableRow.trClasses).toContain('ffe-table__row-expandable--expanded');
78
+ });
79
+ it('should pass an expand icon with correct classname to TableRow', function () {
80
+ wrapper.setState({ expanded: true });
81
+ var tableRow = wrapper.find('TableRow').props();
82
+ expect(tableRow.cells.expandIcon.props.className).toContain('ffe-table__expand-icon--expanded');
83
+ expect(tableRow.expandable).toBe(true);
84
+ });
85
+ it('should not pass an expand icon to TableRows that are not expandable', function () {
86
+ var tableRow = unexpandableWrapper.find('TableRow').props();
87
+ expect(tableRow.cells.expandIcon).toBe(' ');
88
+ expect(tableRow.expandable).toBe(false);
89
+ });
90
+ var renderedWrapper = render(React.createElement(TableRowExpandable, __assign({}, props),
91
+ React.createElement("p", null, "a Festivus for the rest of us")));
92
+ it('should render a tbody with two tr', function () {
93
+ expect(renderedWrapper.children()).toHaveLength(2);
94
+ });
95
+ it('should set the correct aria attributes on tr', function () {
96
+ expect(renderedWrapper.find('tr').first().prop('aria-expanded')).toBe('false');
97
+ expect(renderedWrapper.find('tr').last().prop('aria-hidden')).toBe('true');
98
+ });
99
+ });
package/es/index.js CHANGED
@@ -1,2 +1,2 @@
1
1
  import Table from './Table';
2
- export default Table;
2
+ export default Table;