@popmenu/table 0.22.0 → 0.25.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.
package/build/index.js CHANGED
@@ -6,12 +6,12 @@ var React = require('react');
6
6
  var useTable_js = require('react-table/src/hooks/useTable.js');
7
7
  var usePagination_js = require('react-table/src/plugin-hooks/usePagination.js');
8
8
  var useSortBy_js = require('react-table/src/plugin-hooks/useSortBy.js');
9
+ var useGlobalFilter_js = require('react-table/src/plugin-hooks/useGlobalFilter.js');
9
10
  var lab = require('@material-ui/lab');
10
11
  require('@material-ui/lab/Alert');
11
12
  var core = require('@material-ui/core');
12
13
  require('@material-ui/core/AppBar');
13
14
  var MuiIconButton = require('@material-ui/core/IconButton');
14
- var MuiTypography = require('@material-ui/core/Typography');
15
15
  var styles = require('@material-ui/core/styles');
16
16
  var MuiAvatar = require('@material-ui/core/Avatar');
17
17
  require('@material-ui/core/Badge');
@@ -79,7 +79,6 @@ function _interopNamespace(e) {
79
79
  var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
80
80
  var React__namespace = /*#__PURE__*/_interopNamespace(React);
81
81
  var MuiIconButton__default = /*#__PURE__*/_interopDefaultLegacy(MuiIconButton);
82
- var MuiTypography__default = /*#__PURE__*/_interopDefaultLegacy(MuiTypography);
83
82
  var MuiAvatar__default = /*#__PURE__*/_interopDefaultLegacy(MuiAvatar);
84
83
  var MuiButton__default = /*#__PURE__*/_interopDefaultLegacy(MuiButton);
85
84
  var CircularProgress__default = /*#__PURE__*/_interopDefaultLegacy(CircularProgress);
@@ -179,12 +178,12 @@ function __rest(s, e) {
179
178
  return t;
180
179
  }
181
180
 
182
- var _path$3k;
181
+ var _path$3l;
183
182
 
184
- function _extends$3B() { _extends$3B = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends$3B.apply(this, arguments); }
183
+ function _extends$3C() { _extends$3C = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends$3C.apply(this, arguments); }
185
184
 
186
185
  function SvgUser(props) {
187
- return /*#__PURE__*/React__namespace.createElement("svg", _extends$3B({
186
+ return /*#__PURE__*/React__namespace.createElement("svg", _extends$3C({
188
187
  viewBox: "0 0 16 16",
189
188
  strokeLinecap: "round",
190
189
  strokeLinejoin: "round",
@@ -192,7 +191,7 @@ function SvgUser(props) {
192
191
  width: "1em",
193
192
  height: "1em",
194
193
  fill: "none"
195
- }, props), _path$3k || (_path$3k = /*#__PURE__*/React__namespace.createElement("path", {
194
+ }, props), _path$3l || (_path$3l = /*#__PURE__*/React__namespace.createElement("path", {
196
195
  d: "M13.333 14v-1.333A2.667 2.667 0 0010.667 10H5.333a2.667 2.667 0 00-2.666 2.667V14M8 7.333A2.667 2.667 0 108 2a2.667 2.667 0 000 5.333z"
197
196
  })));
198
197
  }
@@ -319,29 +318,29 @@ IconButton.defaultProps = {
319
318
  color: 'secondary',
320
319
  };
321
320
 
322
- var useTypographyStyles = styles.makeStyles(function () {
323
- var _a;
324
- return ({
325
- root: (_a = {},
326
- _a["& ." + iconStaticClassName] = {
327
- position: 'relative',
328
- top: '0.125em',
329
- padding: '0 0.125em',
330
- boxSizing: 'content-box',
331
- },
332
- _a),
333
- caption: {
334
- display: 'inline',
335
- },
336
- overline: {
337
- display: 'inline',
338
- },
339
- });
340
- });
321
+ var useTypographyStyles = styles.makeStyles(function () { return ({
322
+ root: function (_a) {
323
+ var _b;
324
+ var weight = _a.weight;
325
+ return (__assign((_b = {}, _b["& ." + iconStaticClassName] = {
326
+ position: 'relative',
327
+ top: '0.125em',
328
+ padding: '0 0.125em',
329
+ boxSizing: 'content-box',
330
+ }, _b), (weight && { fontWeight: (weight === 'semi-bold' && 600) || (weight === 'bold' && 700) || 400 })));
331
+ },
332
+ caption: {
333
+ display: 'inline',
334
+ },
335
+ overline: {
336
+ display: 'inline',
337
+ },
338
+ }); });
341
339
 
342
340
  var Typography = React.forwardRef(function (props, ref) {
341
+ props.weight; var restProps = __rest(props, ["weight"]);
343
342
  var classes = useTypographyStyles(props);
344
- return React__default['default'].createElement(MuiTypography__default['default'], __assign({ ref: ref, classes: classes }, props));
343
+ return React__default['default'].createElement(core.Typography, __assign({ ref: ref, classes: classes }, restProps));
345
344
  });
346
345
  Typography.displayName = 'Typography';
347
346
 
@@ -757,12 +756,12 @@ var TableHeader = function (props) {
757
756
  return React__default['default'].createElement("thead", __assign$1({}, restProps), children);
758
757
  };
759
758
 
760
- var _path$3K;
759
+ var _path$3L;
761
760
 
762
- function _extends$3$() { _extends$3$ = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends$3$.apply(this, arguments); }
761
+ function _extends$40() { _extends$40 = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends$40.apply(this, arguments); }
763
762
 
764
763
  function SvgMore(props) {
765
- return /*#__PURE__*/React__namespace.createElement("svg", _extends$3$({
764
+ return /*#__PURE__*/React__namespace.createElement("svg", _extends$40({
766
765
  viewBox: "0 0 16 16",
767
766
  strokeLinecap: "round",
768
767
  strokeLinejoin: "round",
@@ -770,17 +769,35 @@ function SvgMore(props) {
770
769
  width: "1em",
771
770
  height: "1em",
772
771
  fill: "none"
773
- }, props), _path$3K || (_path$3K = /*#__PURE__*/React__namespace.createElement("path", {
772
+ }, props), _path$3L || (_path$3L = /*#__PURE__*/React__namespace.createElement("path", {
774
773
  d: "M8 8.667a.667.667 0 100-1.334.667.667 0 000 1.334zM8 4a.667.667 0 100-1.333A.667.667 0 008 4zm0 9.333A.667.667 0 108 12a.667.667 0 000 1.333z"
775
774
  })));
776
775
  }
777
776
 
778
- var _path$2X;
777
+ var _path$3B;
779
778
 
780
- function _extends$3b() { _extends$3b = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends$3b.apply(this, arguments); }
779
+ function _extends$3S() { _extends$3S = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends$3S.apply(this, arguments); }
780
+
781
+ function SvgSearch(props) {
782
+ return /*#__PURE__*/React__namespace.createElement("svg", _extends$3S({
783
+ viewBox: "0 0 16 16",
784
+ strokeLinecap: "round",
785
+ strokeLinejoin: "round",
786
+ stroke: "currentColor",
787
+ width: "1em",
788
+ height: "1em",
789
+ fill: "none"
790
+ }, props), _path$3B || (_path$3B = /*#__PURE__*/React__namespace.createElement("path", {
791
+ d: "M7.333 12.667A5.333 5.333 0 107.333 2a5.333 5.333 0 000 10.667zM14 14l-2.9-2.9"
792
+ })));
793
+ }
794
+
795
+ var _path$2Y;
796
+
797
+ function _extends$3c() { _extends$3c = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends$3c.apply(this, arguments); }
781
798
 
782
799
  function SvgChevronDown(props) {
783
- return /*#__PURE__*/React__namespace.createElement("svg", _extends$3b({
800
+ return /*#__PURE__*/React__namespace.createElement("svg", _extends$3c({
784
801
  viewBox: "0 0 16 16",
785
802
  strokeLinecap: "round",
786
803
  strokeLinejoin: "round",
@@ -788,17 +805,17 @@ function SvgChevronDown(props) {
788
805
  width: "1em",
789
806
  height: "1em",
790
807
  fill: "none"
791
- }, props), _path$2X || (_path$2X = /*#__PURE__*/React__namespace.createElement("path", {
808
+ }, props), _path$2Y || (_path$2Y = /*#__PURE__*/React__namespace.createElement("path", {
792
809
  d: "M4 6l4 4 4-4"
793
810
  })));
794
811
  }
795
812
 
796
- var _path$2W;
813
+ var _path$2X;
797
814
 
798
- function _extends$3a() { _extends$3a = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends$3a.apply(this, arguments); }
815
+ function _extends$3b() { _extends$3b = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends$3b.apply(this, arguments); }
799
816
 
800
817
  function SvgChevronUp(props) {
801
- return /*#__PURE__*/React__namespace.createElement("svg", _extends$3a({
818
+ return /*#__PURE__*/React__namespace.createElement("svg", _extends$3b({
802
819
  viewBox: "0 0 16 16",
803
820
  strokeLinecap: "round",
804
821
  strokeLinejoin: "round",
@@ -806,7 +823,7 @@ function SvgChevronUp(props) {
806
823
  width: "1em",
807
824
  height: "1em",
808
825
  fill: "none"
809
- }, props), _path$2W || (_path$2W = /*#__PURE__*/React__namespace.createElement("path", {
826
+ }, props), _path$2X || (_path$2X = /*#__PURE__*/React__namespace.createElement("path", {
810
827
  d: "M12 10L8 6l-4 4"
811
828
  })));
812
829
  }
@@ -898,28 +915,6 @@ var TableCell = function (props) {
898
915
  return (React__default['default'].createElement("td", __assign$1({ className: root }, restProps), children));
899
916
  };
900
917
 
901
- var useTableStyles = core.makeStyles(function (_a) {
902
- var typography = _a.typography;
903
- return ({
904
- root: function (_a) {
905
- var fullWidth = _a.fullWidth;
906
- return ({
907
- display: fullWidth ? 'flex' : 'inline-flex',
908
- flexDirection: 'column',
909
- });
910
- },
911
- table: function (_a) {
912
- var fullWidth = _a.fullWidth;
913
- return (__assign$1(__assign$1({ borderCollapse: 'collapse' }, (fullWidth && { width: '100%' })), typography[tableConstants.tableTypography]));
914
- },
915
- tableWrap: function () { return ({
916
- maxWidth: '100%',
917
- overflowX: 'auto',
918
- overflowY: 'hidden',
919
- }); },
920
- });
921
- });
922
-
923
918
  var filterProps = function (props) {
924
919
  props.icon; props.action; var filteredProps = __rest$1(props, ["icon", "action"]);
925
920
  return filteredProps;
@@ -973,17 +968,54 @@ var makeColumns = function (config) {
973
968
  return memoizedColumns;
974
969
  };
975
970
 
971
+ var GlobalFilter = function (props) {
972
+ var value = props.value, setValue = props.setValue, restProps = __rest$1(props, ["value", "setValue"]);
973
+ var onChange = restProps.onChange, InputProps = restProps.InputProps, cleanRestProps = __rest$1(restProps, ["onChange", "InputProps"]);
974
+ var handleChange = function (e) {
975
+ setValue(e.target.value);
976
+ if (onChange) {
977
+ onChange(e);
978
+ }
979
+ };
980
+ return (React__default['default'].createElement(core.TextField, __assign$1({ variant: "outlined", value: value, onChange: handleChange, InputProps: __assign$1({ startAdornment: (React__default['default'].createElement(core.InputAdornment, { position: "start" },
981
+ React__default['default'].createElement(Icon, { icon: SvgSearch }))) }, InputProps) }, cleanRestProps)));
982
+ };
983
+
984
+ var useTableStyles = core.makeStyles(function (_a) {
985
+ var typography = _a.typography;
986
+ return ({
987
+ root: function (_a) {
988
+ var fullWidth = _a.fullWidth;
989
+ return ({
990
+ display: fullWidth ? 'flex' : 'inline-flex',
991
+ flexDirection: 'column',
992
+ });
993
+ },
994
+ table: function (_a) {
995
+ var fullWidth = _a.fullWidth;
996
+ return (__assign$1(__assign$1({ borderCollapse: 'collapse' }, (fullWidth && { width: '100%' })), typography[tableConstants.tableTypography]));
997
+ },
998
+ tableWrap: function () { return ({
999
+ maxWidth: '100%',
1000
+ overflowX: 'auto',
1001
+ overflowY: 'hidden',
1002
+ }); },
1003
+ });
1004
+ });
1005
+
976
1006
  /* eslint-disable react/jsx-key */
977
1007
  var Table = function (props) {
1008
+ // Setup
978
1009
  var actionColumnId = 'table-actions-column';
979
- var rawColumns = props.columns, data = props.data, actions = props.actions, sortable = props.sortable, emptyMessage = props.emptyMessage, EmptyImage = props.EmptyImage, isLoading = props.loading, fullHeight = props.fullHeight, _a = props.paginationOptions, paginationOptions = _a === void 0 ? {} : _a, _b = props.tableOptions, tableOptions = _b === void 0 ? {} : _b, onPaginate = props.onPaginate;
1010
+ var rawColumns = props.columns, data = props.data, actions = props.actions, sortable = props.sortable, emptyMessage = props.emptyMessage, EmptyImage = props.EmptyImage, isLoading = props.loading, fullHeight = props.fullHeight, GlobalFilterProps = props.GlobalFilterProps, _a = props.paginationOptions, paginationOptions = _a === void 0 ? {} : _a, _b = props.tableOptions, tableOptions = _b === void 0 ? {} : _b, searchable = props.searchable, onPaginate = props.onPaginate;
980
1011
  var theme = core.useTheme();
981
1012
  var classes = useTableStyles(props);
982
1013
  var columns = React.useMemo(function () { return makeColumns({ columns: rawColumns, actions: actions, actionColumnId: actionColumnId }); }, [rawColumns, actions]);
983
1014
  var initialPaginationState = paginationOptions.initialState, restPaginationOptions = __rest$1(paginationOptions, ["initialState"]);
984
1015
  var initialState = __assign$1({}, initialPaginationState);
985
- var instance = useTable_js.useTable(__assign$1(__assign$1({ columns: columns, data: data, disableSortBy: !sortable, initialState: initialState }, restPaginationOptions), tableOptions), useSortBy_js.useSortBy, usePagination_js.usePagination);
986
- var getTableProps = instance.getTableProps, getTableBodyProps = instance.getTableBodyProps, headerGroups = instance.headerGroups, page = instance.page, prepareRow = instance.prepareRow, pageCount = instance.pageCount, gotoPage = instance.gotoPage, rows = instance.rows;
1016
+ var instance = useTable_js.useTable(__assign$1(__assign$1({ columns: columns, data: data, disableSortBy: !sortable, initialState: initialState }, restPaginationOptions), tableOptions), useGlobalFilter_js.useGlobalFilter, useSortBy_js.useSortBy, usePagination_js.usePagination);
1017
+ var getTableProps = instance.getTableProps, getTableBodyProps = instance.getTableBodyProps, headerGroups = instance.headerGroups, page = instance.page, prepareRow = instance.prepareRow, pageCount = instance.pageCount, gotoPage = instance.gotoPage, rows = instance.rows, state = instance.state, setGlobalFilter = instance.setGlobalFilter;
1018
+ // Aliases
987
1019
  var isPaginated = pageCount > 1;
988
1020
  var isEmpty = rows.length === 0;
989
1021
  var lineHeightRem = parseFloat(theme.typography[tableConstants.tableTypography].lineHeight);
@@ -994,6 +1026,7 @@ var Table = function (props) {
994
1026
  var bodyHeight = instance.state.pageSize * cellHeight;
995
1027
  var footerHeight = 88;
996
1028
  var minHeight = headerHeight + bodyHeight + footerHeight;
1029
+ // Handlers
997
1030
  var handlePagination = function (_e, pageNumber) {
998
1031
  var pageIndex = pageNumber - 1;
999
1032
  if (onPaginate) {
@@ -1004,6 +1037,8 @@ var Table = function (props) {
1004
1037
  }
1005
1038
  };
1006
1039
  return (React__default['default'].createElement(core.Box, { className: classes.root, minHeight: fullHeight ? minHeight : 'unset' },
1040
+ searchable && (React__default['default'].createElement(core.Box, null,
1041
+ React__default['default'].createElement(GlobalFilter, __assign$1({ value: state.globalFilter, setValue: setGlobalFilter }, GlobalFilterProps)))),
1007
1042
  React__default['default'].createElement(core.Box, { className: classes.tableWrap },
1008
1043
  React__default['default'].createElement("table", __assign$1({ className: classes.table }, getTableProps()),
1009
1044
  React__default['default'].createElement(TableHeader, null, headerGroups.map(function (headerGroup) { return (React__default['default'].createElement(TableHeaderRow, __assign$1({}, headerGroup.getHeaderGroupProps()), headerGroup.headers.map(function (column) { return (React__default['default'].createElement(TableHeaderCell, __assign$1({}, column.getHeaderProps(column.getSortByToggleProps()), { column: __assign$1(__assign$1({}, column), { isActionColumn: column.id === actionColumnId }), tableProps: props }), column.render('Header'))); }))); })),