@popmenu/table 0.21.0 → 0.24.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);
@@ -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
 
@@ -720,6 +719,34 @@ var Tooltip = React.forwardRef(function (props, ref) {
720
719
  });
721
720
  Tooltip.displayName = 'Tooltip';
722
721
 
722
+ core.makeStyles(function () { return ({
723
+ root: {
724
+ height: 56,
725
+ },
726
+ }); });
727
+ core.makeStyles(function (theme) { return ({
728
+ root: {
729
+ height: '100%',
730
+ width: 'min-content',
731
+ borderRadius: theme.spacing(1),
732
+ },
733
+ input: {
734
+ '&::-webkit-clear-button, &::-webkit-outer-spin-button, &::-webkit-inner-spin-button': {
735
+ display: 'none',
736
+ },
737
+ '-moz-appearance': 'textfield',
738
+ minWidth: 40,
739
+ padding: 0,
740
+ textAlign: 'center',
741
+ },
742
+ adornedStart: {
743
+ padding: 0,
744
+ },
745
+ adornedEnd: {
746
+ padding: 0,
747
+ },
748
+ }); });
749
+
723
750
  var TableFooter = function (props) {
724
751
  return (React__default['default'].createElement(core.Box, { display: "flex", justifyContent: "center", alignItems: "end", paddingTop: 3, paddingBottom: 4, flexGrow: 1 }, props.children));
725
752
  };
@@ -747,6 +774,24 @@ function SvgMore(props) {
747
774
  })));
748
775
  }
749
776
 
777
+ var _path$3A;
778
+
779
+ function _extends$3R() { _extends$3R = 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$3R.apply(this, arguments); }
780
+
781
+ function SvgSearch(props) {
782
+ return /*#__PURE__*/React__namespace.createElement("svg", _extends$3R({
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$3A || (_path$3A = /*#__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
+
750
795
  var _path$2X;
751
796
 
752
797
  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); }
@@ -870,28 +915,6 @@ var TableCell = function (props) {
870
915
  return (React__default['default'].createElement("td", __assign$1({ className: root }, restProps), children));
871
916
  };
872
917
 
873
- var useTableStyles = core.makeStyles(function (_a) {
874
- var typography = _a.typography;
875
- return ({
876
- root: function (_a) {
877
- var fullWidth = _a.fullWidth;
878
- return ({
879
- display: fullWidth ? 'flex' : 'inline-flex',
880
- flexDirection: 'column',
881
- });
882
- },
883
- table: function (_a) {
884
- var fullWidth = _a.fullWidth;
885
- return (__assign$1(__assign$1({ borderCollapse: 'collapse' }, (fullWidth && { width: '100%' })), typography[tableConstants.tableTypography]));
886
- },
887
- tableWrap: function () { return ({
888
- maxWidth: '100%',
889
- overflowX: 'auto',
890
- overflowY: 'hidden',
891
- }); },
892
- });
893
- });
894
-
895
918
  var filterProps = function (props) {
896
919
  props.icon; props.action; var filteredProps = __rest$1(props, ["icon", "action"]);
897
920
  return filteredProps;
@@ -945,17 +968,54 @@ var makeColumns = function (config) {
945
968
  return memoizedColumns;
946
969
  };
947
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
+
948
1006
  /* eslint-disable react/jsx-key */
949
1007
  var Table = function (props) {
1008
+ // Setup
950
1009
  var actionColumnId = 'table-actions-column';
951
- 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;
952
1011
  var theme = core.useTheme();
953
1012
  var classes = useTableStyles(props);
954
1013
  var columns = React.useMemo(function () { return makeColumns({ columns: rawColumns, actions: actions, actionColumnId: actionColumnId }); }, [rawColumns, actions]);
955
1014
  var initialPaginationState = paginationOptions.initialState, restPaginationOptions = __rest$1(paginationOptions, ["initialState"]);
956
1015
  var initialState = __assign$1({}, initialPaginationState);
957
- 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);
958
- 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
959
1019
  var isPaginated = pageCount > 1;
960
1020
  var isEmpty = rows.length === 0;
961
1021
  var lineHeightRem = parseFloat(theme.typography[tableConstants.tableTypography].lineHeight);
@@ -966,6 +1026,7 @@ var Table = function (props) {
966
1026
  var bodyHeight = instance.state.pageSize * cellHeight;
967
1027
  var footerHeight = 88;
968
1028
  var minHeight = headerHeight + bodyHeight + footerHeight;
1029
+ // Handlers
969
1030
  var handlePagination = function (_e, pageNumber) {
970
1031
  var pageIndex = pageNumber - 1;
971
1032
  if (onPaginate) {
@@ -976,6 +1037,8 @@ var Table = function (props) {
976
1037
  }
977
1038
  };
978
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)))),
979
1042
  React__default['default'].createElement(core.Box, { className: classes.tableWrap },
980
1043
  React__default['default'].createElement("table", __assign$1({ className: classes.table }, getTableProps()),
981
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'))); }))); })),