@popmenu/table 0.20.0 → 0.23.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/components/GlobalFilter/GlobalFilter.d.ts +3 -0
- package/build/components/GlobalFilter/GlobalFilterProps.d.ts +7 -0
- package/build/components/GlobalFilter/index.d.ts +2 -0
- package/build/components/Table/TableProps.d.ts +5 -0
- package/build/index.es.js +121 -56
- package/build/index.es.js.map +1 -1
- package/build/index.js +120 -55
- package/build/index.js.map +1 -1
- package/package.json +2 -2
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { OutlinedTextFieldProps } from '@material-ui/core/TextField';
|
|
2
|
+
export interface GlobalFilterProps extends Omit<OutlinedTextFieldProps, 'variant'> {
|
|
3
|
+
/** the value of global filter from table instance */
|
|
4
|
+
value: string;
|
|
5
|
+
/** the setter for value of global filter from table instance */
|
|
6
|
+
setValue: (value: string) => void;
|
|
7
|
+
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { Cell, Column, TableInstance, UsePaginationOptions } from 'react-table';
|
|
3
|
+
import { GlobalFilterProps } from '../GlobalFilter';
|
|
3
4
|
export interface TableProps {
|
|
4
5
|
/** Configurations for each individual column. */
|
|
5
6
|
columns: Array<Column & {
|
|
@@ -17,6 +18,8 @@ export interface TableProps {
|
|
|
17
18
|
fullHeight?: boolean;
|
|
18
19
|
/** Styles the table to take up its containers full width. */
|
|
19
20
|
fullWidth?: boolean;
|
|
21
|
+
/** Enables global filter as search. */
|
|
22
|
+
searchable?: boolean;
|
|
20
23
|
/** Enables sortability for columns. */
|
|
21
24
|
sortable?: boolean;
|
|
22
25
|
/** Sets loading state. When true, Will render a CircularProgress when true and not rows. */
|
|
@@ -25,6 +28,8 @@ export interface TableProps {
|
|
|
25
28
|
emptyMessage?: string;
|
|
26
29
|
/** An image to be displayed with the empty message. */
|
|
27
30
|
EmptyImage?: () => React.ReactNode;
|
|
31
|
+
/** Props applied to the global search input component. Extends [TextField props](https://v4.mui.com/api/text-field/). */
|
|
32
|
+
GlobalFilterProps?: Omit<GlobalFilterProps, 'value' | 'setValue'>;
|
|
28
33
|
/** Callback for managing pagination events. */
|
|
29
34
|
onPaginate?: (pageIndex: number, instance: TableInstance) => void;
|
|
30
35
|
/** Callback for managing pagination events. */
|
package/build/index.es.js
CHANGED
|
@@ -3,9 +3,10 @@ import React__default, { forwardRef, createElement, useMemo, useState } from 're
|
|
|
3
3
|
import { useTable } from 'react-table/src/hooks/useTable.js';
|
|
4
4
|
import { usePagination } from 'react-table/src/plugin-hooks/usePagination.js';
|
|
5
5
|
import { useSortBy } from 'react-table/src/plugin-hooks/useSortBy.js';
|
|
6
|
+
import { useGlobalFilter } from 'react-table/src/plugin-hooks/useGlobalFilter.js';
|
|
6
7
|
import { Pagination } from '@material-ui/lab';
|
|
7
8
|
import '@material-ui/lab/Alert';
|
|
8
|
-
import { makeStyles, Paper as Paper$1, Link as Link$1, Box, useTheme as useTheme$1 } from '@material-ui/core';
|
|
9
|
+
import { makeStyles, Paper as Paper$1, Link as Link$1, Box, useTheme as useTheme$1, TextField, InputAdornment } from '@material-ui/core';
|
|
9
10
|
import '@material-ui/core/AppBar';
|
|
10
11
|
import MuiIconButton from '@material-ui/core/IconButton';
|
|
11
12
|
import MuiTypography from '@material-ui/core/Typography';
|
|
@@ -137,20 +138,20 @@ function __rest(s, e) {
|
|
|
137
138
|
return t;
|
|
138
139
|
}
|
|
139
140
|
|
|
140
|
-
var _path$
|
|
141
|
+
var _path$2O;
|
|
141
142
|
|
|
142
|
-
function _extends$
|
|
143
|
+
function _extends$32() { _extends$32 = 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$32.apply(this, arguments); }
|
|
143
144
|
|
|
144
145
|
function SvgUser(props) {
|
|
145
|
-
return /*#__PURE__*/React.createElement("svg", _extends$
|
|
146
|
+
return /*#__PURE__*/React.createElement("svg", _extends$32({
|
|
146
147
|
viewBox: "0 0 16 16",
|
|
147
148
|
strokeLinecap: "round",
|
|
148
149
|
strokeLinejoin: "round",
|
|
149
150
|
stroke: "currentColor",
|
|
151
|
+
fill: "none",
|
|
150
152
|
width: "1em",
|
|
151
|
-
height: "1em"
|
|
152
|
-
|
|
153
|
-
}, props), _path$3k || (_path$3k = /*#__PURE__*/React.createElement("path", {
|
|
153
|
+
height: "1em"
|
|
154
|
+
}, props), _path$2O || (_path$2O = /*#__PURE__*/React.createElement("path", {
|
|
154
155
|
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"
|
|
155
156
|
})));
|
|
156
157
|
}
|
|
@@ -678,6 +679,34 @@ var Tooltip = forwardRef(function (props, ref) {
|
|
|
678
679
|
});
|
|
679
680
|
Tooltip.displayName = 'Tooltip';
|
|
680
681
|
|
|
682
|
+
makeStyles(function () { return ({
|
|
683
|
+
root: {
|
|
684
|
+
height: 56,
|
|
685
|
+
},
|
|
686
|
+
}); });
|
|
687
|
+
makeStyles(function (theme) { return ({
|
|
688
|
+
root: {
|
|
689
|
+
height: '100%',
|
|
690
|
+
width: 'min-content',
|
|
691
|
+
borderRadius: theme.spacing(1),
|
|
692
|
+
},
|
|
693
|
+
input: {
|
|
694
|
+
'&::-webkit-clear-button, &::-webkit-outer-spin-button, &::-webkit-inner-spin-button': {
|
|
695
|
+
display: 'none',
|
|
696
|
+
},
|
|
697
|
+
'-moz-appearance': 'textfield',
|
|
698
|
+
minWidth: 40,
|
|
699
|
+
padding: 0,
|
|
700
|
+
textAlign: 'center',
|
|
701
|
+
},
|
|
702
|
+
adornedStart: {
|
|
703
|
+
padding: 0,
|
|
704
|
+
},
|
|
705
|
+
adornedEnd: {
|
|
706
|
+
padding: 0,
|
|
707
|
+
},
|
|
708
|
+
}); });
|
|
709
|
+
|
|
681
710
|
var TableFooter = function (props) {
|
|
682
711
|
return (React__default.createElement(Box, { display: "flex", justifyContent: "center", alignItems: "end", paddingTop: 3, paddingBottom: 4, flexGrow: 1 }, props.children));
|
|
683
712
|
};
|
|
@@ -687,57 +716,75 @@ var TableHeader = function (props) {
|
|
|
687
716
|
return React__default.createElement("thead", __assign$1({}, restProps), children);
|
|
688
717
|
};
|
|
689
718
|
|
|
690
|
-
var _path$
|
|
719
|
+
var _path$4w;
|
|
691
720
|
|
|
692
|
-
function _extends$
|
|
721
|
+
function _extends$4M() { _extends$4M = 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$4M.apply(this, arguments); }
|
|
693
722
|
|
|
694
|
-
function
|
|
695
|
-
return /*#__PURE__*/React.createElement("svg", _extends$
|
|
723
|
+
function SvgChevronDown(props) {
|
|
724
|
+
return /*#__PURE__*/React.createElement("svg", _extends$4M({
|
|
696
725
|
viewBox: "0 0 16 16",
|
|
697
726
|
strokeLinecap: "round",
|
|
698
727
|
strokeLinejoin: "round",
|
|
699
728
|
stroke: "currentColor",
|
|
729
|
+
fill: "none",
|
|
700
730
|
width: "1em",
|
|
701
|
-
height: "1em"
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
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"
|
|
731
|
+
height: "1em"
|
|
732
|
+
}, props), _path$4w || (_path$4w = /*#__PURE__*/React.createElement("path", {
|
|
733
|
+
d: "M4 6l4 4 4-4"
|
|
705
734
|
})));
|
|
706
735
|
}
|
|
707
736
|
|
|
708
|
-
var _path$
|
|
737
|
+
var _path$4v;
|
|
709
738
|
|
|
710
|
-
function _extends$
|
|
739
|
+
function _extends$4L() { _extends$4L = 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$4L.apply(this, arguments); }
|
|
711
740
|
|
|
712
|
-
function
|
|
713
|
-
return /*#__PURE__*/React.createElement("svg", _extends$
|
|
741
|
+
function SvgChevronUp(props) {
|
|
742
|
+
return /*#__PURE__*/React.createElement("svg", _extends$4L({
|
|
714
743
|
viewBox: "0 0 16 16",
|
|
715
744
|
strokeLinecap: "round",
|
|
716
745
|
strokeLinejoin: "round",
|
|
717
746
|
stroke: "currentColor",
|
|
747
|
+
fill: "none",
|
|
718
748
|
width: "1em",
|
|
719
|
-
height: "1em"
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
d: "M4 6l4 4 4-4"
|
|
749
|
+
height: "1em"
|
|
750
|
+
}, props), _path$4v || (_path$4v = /*#__PURE__*/React.createElement("path", {
|
|
751
|
+
d: "M12 10L8 6l-4 4"
|
|
723
752
|
})));
|
|
724
753
|
}
|
|
725
754
|
|
|
726
|
-
var _path$
|
|
755
|
+
var _path$3c;
|
|
727
756
|
|
|
728
|
-
function _extends$
|
|
757
|
+
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); }
|
|
729
758
|
|
|
730
|
-
function
|
|
731
|
-
return /*#__PURE__*/React.createElement("svg", _extends$
|
|
759
|
+
function SvgMore(props) {
|
|
760
|
+
return /*#__PURE__*/React.createElement("svg", _extends$3s({
|
|
732
761
|
viewBox: "0 0 16 16",
|
|
733
762
|
strokeLinecap: "round",
|
|
734
763
|
strokeLinejoin: "round",
|
|
735
764
|
stroke: "currentColor",
|
|
765
|
+
fill: "none",
|
|
736
766
|
width: "1em",
|
|
737
|
-
height: "1em"
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
767
|
+
height: "1em"
|
|
768
|
+
}, props), _path$3c || (_path$3c = /*#__PURE__*/React.createElement("path", {
|
|
769
|
+
d: "M8 8.667a.667.667 0 100-1.334.667.667 0 000 1.334zM8 4a.667.667 0 100-1.334A.667.667 0 008 4zm0 9.333A.667.667 0 108 12a.667.667 0 000 1.333z"
|
|
770
|
+
})));
|
|
771
|
+
}
|
|
772
|
+
|
|
773
|
+
var _path$32;
|
|
774
|
+
|
|
775
|
+
function _extends$3i() { _extends$3i = 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$3i.apply(this, arguments); }
|
|
776
|
+
|
|
777
|
+
function SvgSearch(props) {
|
|
778
|
+
return /*#__PURE__*/React.createElement("svg", _extends$3i({
|
|
779
|
+
viewBox: "0 0 16 16",
|
|
780
|
+
strokeLinecap: "round",
|
|
781
|
+
strokeLinejoin: "round",
|
|
782
|
+
stroke: "currentColor",
|
|
783
|
+
fill: "none",
|
|
784
|
+
width: "1em",
|
|
785
|
+
height: "1em"
|
|
786
|
+
}, props), _path$32 || (_path$32 = /*#__PURE__*/React.createElement("path", {
|
|
787
|
+
d: "M7.333 12.667A5.333 5.333 0 107.333 2a5.333 5.333 0 000 10.667zM14 14l-2.9-2.9"
|
|
741
788
|
})));
|
|
742
789
|
}
|
|
743
790
|
|
|
@@ -828,28 +875,6 @@ var TableCell = function (props) {
|
|
|
828
875
|
return (React__default.createElement("td", __assign$1({ className: root }, restProps), children));
|
|
829
876
|
};
|
|
830
877
|
|
|
831
|
-
var useTableStyles = makeStyles(function (_a) {
|
|
832
|
-
var typography = _a.typography;
|
|
833
|
-
return ({
|
|
834
|
-
root: function (_a) {
|
|
835
|
-
var fullWidth = _a.fullWidth;
|
|
836
|
-
return ({
|
|
837
|
-
display: fullWidth ? 'flex' : 'inline-flex',
|
|
838
|
-
flexDirection: 'column',
|
|
839
|
-
});
|
|
840
|
-
},
|
|
841
|
-
table: function (_a) {
|
|
842
|
-
var fullWidth = _a.fullWidth;
|
|
843
|
-
return (__assign$1(__assign$1({ borderCollapse: 'collapse' }, (fullWidth && { width: '100%' })), typography[tableConstants.tableTypography]));
|
|
844
|
-
},
|
|
845
|
-
tableWrap: function () { return ({
|
|
846
|
-
maxWidth: '100%',
|
|
847
|
-
overflowX: 'auto',
|
|
848
|
-
overflowY: 'hidden',
|
|
849
|
-
}); },
|
|
850
|
-
});
|
|
851
|
-
});
|
|
852
|
-
|
|
853
878
|
var filterProps = function (props) {
|
|
854
879
|
props.icon; props.action; var filteredProps = __rest$1(props, ["icon", "action"]);
|
|
855
880
|
return filteredProps;
|
|
@@ -903,17 +928,54 @@ var makeColumns = function (config) {
|
|
|
903
928
|
return memoizedColumns;
|
|
904
929
|
};
|
|
905
930
|
|
|
931
|
+
var GlobalFilter = function (props) {
|
|
932
|
+
var value = props.value, setValue = props.setValue, restProps = __rest$1(props, ["value", "setValue"]);
|
|
933
|
+
var onChange = restProps.onChange, InputProps = restProps.InputProps, cleanRestProps = __rest$1(restProps, ["onChange", "InputProps"]);
|
|
934
|
+
var handleChange = function (e) {
|
|
935
|
+
setValue(e.target.value);
|
|
936
|
+
if (onChange) {
|
|
937
|
+
onChange(e);
|
|
938
|
+
}
|
|
939
|
+
};
|
|
940
|
+
return (React__default.createElement(TextField, __assign$1({ variant: "outlined", value: value, onChange: handleChange, InputProps: __assign$1({ startAdornment: (React__default.createElement(InputAdornment, { position: "start" },
|
|
941
|
+
React__default.createElement(Icon, { icon: SvgSearch }))) }, InputProps) }, cleanRestProps)));
|
|
942
|
+
};
|
|
943
|
+
|
|
944
|
+
var useTableStyles = makeStyles(function (_a) {
|
|
945
|
+
var typography = _a.typography;
|
|
946
|
+
return ({
|
|
947
|
+
root: function (_a) {
|
|
948
|
+
var fullWidth = _a.fullWidth;
|
|
949
|
+
return ({
|
|
950
|
+
display: fullWidth ? 'flex' : 'inline-flex',
|
|
951
|
+
flexDirection: 'column',
|
|
952
|
+
});
|
|
953
|
+
},
|
|
954
|
+
table: function (_a) {
|
|
955
|
+
var fullWidth = _a.fullWidth;
|
|
956
|
+
return (__assign$1(__assign$1({ borderCollapse: 'collapse' }, (fullWidth && { width: '100%' })), typography[tableConstants.tableTypography]));
|
|
957
|
+
},
|
|
958
|
+
tableWrap: function () { return ({
|
|
959
|
+
maxWidth: '100%',
|
|
960
|
+
overflowX: 'auto',
|
|
961
|
+
overflowY: 'hidden',
|
|
962
|
+
}); },
|
|
963
|
+
});
|
|
964
|
+
});
|
|
965
|
+
|
|
906
966
|
/* eslint-disable react/jsx-key */
|
|
907
967
|
var Table = function (props) {
|
|
968
|
+
// Setup
|
|
908
969
|
var actionColumnId = 'table-actions-column';
|
|
909
|
-
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;
|
|
970
|
+
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;
|
|
910
971
|
var theme = useTheme$1();
|
|
911
972
|
var classes = useTableStyles(props);
|
|
912
973
|
var columns = useMemo(function () { return makeColumns({ columns: rawColumns, actions: actions, actionColumnId: actionColumnId }); }, [rawColumns, actions]);
|
|
913
974
|
var initialPaginationState = paginationOptions.initialState, restPaginationOptions = __rest$1(paginationOptions, ["initialState"]);
|
|
914
975
|
var initialState = __assign$1({}, initialPaginationState);
|
|
915
|
-
var instance = useTable(__assign$1(__assign$1({ columns: columns, data: data, disableSortBy: !sortable, initialState: initialState }, restPaginationOptions), tableOptions), useSortBy, usePagination);
|
|
916
|
-
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;
|
|
976
|
+
var instance = useTable(__assign$1(__assign$1({ columns: columns, data: data, disableSortBy: !sortable, initialState: initialState }, restPaginationOptions), tableOptions), useGlobalFilter, useSortBy, usePagination);
|
|
977
|
+
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;
|
|
978
|
+
// Aliases
|
|
917
979
|
var isPaginated = pageCount > 1;
|
|
918
980
|
var isEmpty = rows.length === 0;
|
|
919
981
|
var lineHeightRem = parseFloat(theme.typography[tableConstants.tableTypography].lineHeight);
|
|
@@ -924,6 +986,7 @@ var Table = function (props) {
|
|
|
924
986
|
var bodyHeight = instance.state.pageSize * cellHeight;
|
|
925
987
|
var footerHeight = 88;
|
|
926
988
|
var minHeight = headerHeight + bodyHeight + footerHeight;
|
|
989
|
+
// Handlers
|
|
927
990
|
var handlePagination = function (_e, pageNumber) {
|
|
928
991
|
var pageIndex = pageNumber - 1;
|
|
929
992
|
if (onPaginate) {
|
|
@@ -934,6 +997,8 @@ var Table = function (props) {
|
|
|
934
997
|
}
|
|
935
998
|
};
|
|
936
999
|
return (React__default.createElement(Box, { className: classes.root, minHeight: fullHeight ? minHeight : 'unset' },
|
|
1000
|
+
searchable && (React__default.createElement(Box, null,
|
|
1001
|
+
React__default.createElement(GlobalFilter, __assign$1({ value: state.globalFilter, setValue: setGlobalFilter }, GlobalFilterProps)))),
|
|
937
1002
|
React__default.createElement(Box, { className: classes.tableWrap },
|
|
938
1003
|
React__default.createElement("table", __assign$1({ className: classes.table }, getTableProps()),
|
|
939
1004
|
React__default.createElement(TableHeader, null, headerGroups.map(function (headerGroup) { return (React__default.createElement(TableHeaderRow, __assign$1({}, headerGroup.getHeaderGroupProps()), headerGroup.headers.map(function (column) { return (React__default.createElement(TableHeaderCell, __assign$1({}, column.getHeaderProps(column.getSortByToggleProps()), { column: __assign$1(__assign$1({}, column), { isActionColumn: column.id === actionColumnId }), tableProps: props }), column.render('Header'))); }))); })),
|