@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.
@@ -0,0 +1,3 @@
1
+ /// <reference types="react" />
2
+ import { GlobalFilterProps } from './GlobalFilterProps';
3
+ export declare const GlobalFilter: (props: GlobalFilterProps) => JSX.Element;
@@ -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
+ }
@@ -0,0 +1,2 @@
1
+ export { GlobalFilter } from './GlobalFilter';
2
+ export { GlobalFilterProps } from './GlobalFilterProps';
@@ -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,12 +3,12 @@ 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, Typography as Typography$1, 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
- import MuiTypography from '@material-ui/core/Typography';
12
12
  import { makeStyles as makeStyles$1, useTheme } from '@material-ui/core/styles';
13
13
  import MuiAvatar from '@material-ui/core/Avatar';
14
14
  import '@material-ui/core/Badge';
@@ -277,29 +277,29 @@ IconButton.defaultProps = {
277
277
  color: 'secondary',
278
278
  };
279
279
 
280
- var useTypographyStyles = makeStyles$1(function () {
281
- var _a;
282
- return ({
283
- root: (_a = {},
284
- _a["& ." + iconStaticClassName] = {
285
- position: 'relative',
286
- top: '0.125em',
287
- padding: '0 0.125em',
288
- boxSizing: 'content-box',
289
- },
290
- _a),
291
- caption: {
292
- display: 'inline',
293
- },
294
- overline: {
295
- display: 'inline',
296
- },
297
- });
298
- });
280
+ var useTypographyStyles = makeStyles$1(function () { return ({
281
+ root: function (_a) {
282
+ var _b;
283
+ var weight = _a.weight;
284
+ return (__assign((_b = {}, _b["& ." + iconStaticClassName] = {
285
+ position: 'relative',
286
+ top: '0.125em',
287
+ padding: '0 0.125em',
288
+ boxSizing: 'content-box',
289
+ }, _b), (weight && { fontWeight: (weight === 'semi-bold' && 600) || (weight === 'bold' && 700) || 400 })));
290
+ },
291
+ caption: {
292
+ display: 'inline',
293
+ },
294
+ overline: {
295
+ display: 'inline',
296
+ },
297
+ }); });
299
298
 
300
299
  var Typography = forwardRef(function (props, ref) {
300
+ props.weight; var restProps = __rest(props, ["weight"]);
301
301
  var classes = useTypographyStyles(props);
302
- return React__default.createElement(MuiTypography, __assign({ ref: ref, classes: classes }, props));
302
+ return React__default.createElement(Typography$1, __assign({ ref: ref, classes: classes }, restProps));
303
303
  });
304
304
  Typography.displayName = 'Typography';
305
305
 
@@ -678,6 +678,34 @@ var Tooltip = forwardRef(function (props, ref) {
678
678
  });
679
679
  Tooltip.displayName = 'Tooltip';
680
680
 
681
+ makeStyles(function () { return ({
682
+ root: {
683
+ height: 56,
684
+ },
685
+ }); });
686
+ makeStyles(function (theme) { return ({
687
+ root: {
688
+ height: '100%',
689
+ width: 'min-content',
690
+ borderRadius: theme.spacing(1),
691
+ },
692
+ input: {
693
+ '&::-webkit-clear-button, &::-webkit-outer-spin-button, &::-webkit-inner-spin-button': {
694
+ display: 'none',
695
+ },
696
+ '-moz-appearance': 'textfield',
697
+ minWidth: 40,
698
+ padding: 0,
699
+ textAlign: 'center',
700
+ },
701
+ adornedStart: {
702
+ padding: 0,
703
+ },
704
+ adornedEnd: {
705
+ padding: 0,
706
+ },
707
+ }); });
708
+
681
709
  var TableFooter = function (props) {
682
710
  return (React__default.createElement(Box, { display: "flex", justifyContent: "center", alignItems: "end", paddingTop: 3, paddingBottom: 4, flexGrow: 1 }, props.children));
683
711
  };
@@ -705,6 +733,24 @@ function SvgMore(props) {
705
733
  })));
706
734
  }
707
735
 
736
+ var _path$3A;
737
+
738
+ 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); }
739
+
740
+ function SvgSearch(props) {
741
+ return /*#__PURE__*/React.createElement("svg", _extends$3R({
742
+ viewBox: "0 0 16 16",
743
+ strokeLinecap: "round",
744
+ strokeLinejoin: "round",
745
+ stroke: "currentColor",
746
+ width: "1em",
747
+ height: "1em",
748
+ fill: "none"
749
+ }, props), _path$3A || (_path$3A = /*#__PURE__*/React.createElement("path", {
750
+ d: "M7.333 12.667A5.333 5.333 0 107.333 2a5.333 5.333 0 000 10.667zM14 14l-2.9-2.9"
751
+ })));
752
+ }
753
+
708
754
  var _path$2X;
709
755
 
710
756
  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); }
@@ -828,28 +874,6 @@ var TableCell = function (props) {
828
874
  return (React__default.createElement("td", __assign$1({ className: root }, restProps), children));
829
875
  };
830
876
 
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
877
  var filterProps = function (props) {
854
878
  props.icon; props.action; var filteredProps = __rest$1(props, ["icon", "action"]);
855
879
  return filteredProps;
@@ -903,17 +927,54 @@ var makeColumns = function (config) {
903
927
  return memoizedColumns;
904
928
  };
905
929
 
930
+ var GlobalFilter = function (props) {
931
+ var value = props.value, setValue = props.setValue, restProps = __rest$1(props, ["value", "setValue"]);
932
+ var onChange = restProps.onChange, InputProps = restProps.InputProps, cleanRestProps = __rest$1(restProps, ["onChange", "InputProps"]);
933
+ var handleChange = function (e) {
934
+ setValue(e.target.value);
935
+ if (onChange) {
936
+ onChange(e);
937
+ }
938
+ };
939
+ return (React__default.createElement(TextField, __assign$1({ variant: "outlined", value: value, onChange: handleChange, InputProps: __assign$1({ startAdornment: (React__default.createElement(InputAdornment, { position: "start" },
940
+ React__default.createElement(Icon, { icon: SvgSearch }))) }, InputProps) }, cleanRestProps)));
941
+ };
942
+
943
+ var useTableStyles = makeStyles(function (_a) {
944
+ var typography = _a.typography;
945
+ return ({
946
+ root: function (_a) {
947
+ var fullWidth = _a.fullWidth;
948
+ return ({
949
+ display: fullWidth ? 'flex' : 'inline-flex',
950
+ flexDirection: 'column',
951
+ });
952
+ },
953
+ table: function (_a) {
954
+ var fullWidth = _a.fullWidth;
955
+ return (__assign$1(__assign$1({ borderCollapse: 'collapse' }, (fullWidth && { width: '100%' })), typography[tableConstants.tableTypography]));
956
+ },
957
+ tableWrap: function () { return ({
958
+ maxWidth: '100%',
959
+ overflowX: 'auto',
960
+ overflowY: 'hidden',
961
+ }); },
962
+ });
963
+ });
964
+
906
965
  /* eslint-disable react/jsx-key */
907
966
  var Table = function (props) {
967
+ // Setup
908
968
  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;
969
+ 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
970
  var theme = useTheme$1();
911
971
  var classes = useTableStyles(props);
912
972
  var columns = useMemo(function () { return makeColumns({ columns: rawColumns, actions: actions, actionColumnId: actionColumnId }); }, [rawColumns, actions]);
913
973
  var initialPaginationState = paginationOptions.initialState, restPaginationOptions = __rest$1(paginationOptions, ["initialState"]);
914
974
  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;
975
+ var instance = useTable(__assign$1(__assign$1({ columns: columns, data: data, disableSortBy: !sortable, initialState: initialState }, restPaginationOptions), tableOptions), useGlobalFilter, useSortBy, usePagination);
976
+ 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;
977
+ // Aliases
917
978
  var isPaginated = pageCount > 1;
918
979
  var isEmpty = rows.length === 0;
919
980
  var lineHeightRem = parseFloat(theme.typography[tableConstants.tableTypography].lineHeight);
@@ -924,6 +985,7 @@ var Table = function (props) {
924
985
  var bodyHeight = instance.state.pageSize * cellHeight;
925
986
  var footerHeight = 88;
926
987
  var minHeight = headerHeight + bodyHeight + footerHeight;
988
+ // Handlers
927
989
  var handlePagination = function (_e, pageNumber) {
928
990
  var pageIndex = pageNumber - 1;
929
991
  if (onPaginate) {
@@ -934,6 +996,8 @@ var Table = function (props) {
934
996
  }
935
997
  };
936
998
  return (React__default.createElement(Box, { className: classes.root, minHeight: fullHeight ? minHeight : 'unset' },
999
+ searchable && (React__default.createElement(Box, null,
1000
+ React__default.createElement(GlobalFilter, __assign$1({ value: state.globalFilter, setValue: setGlobalFilter }, GlobalFilterProps)))),
937
1001
  React__default.createElement(Box, { className: classes.tableWrap },
938
1002
  React__default.createElement("table", __assign$1({ className: classes.table }, getTableProps()),
939
1003
  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'))); }))); })),