@bento-core/table 0.2.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.
Files changed (58) hide show
  1. package/babel.config.json +20 -0
  2. package/dist/DefaultThemConfig.js +68 -0
  3. package/dist/ExtendedView.js +64 -0
  4. package/dist/TableView.js +90 -0
  5. package/dist/body/ActionBodyCell.js +37 -0
  6. package/dist/body/CustomTblBody.js +64 -0
  7. package/dist/body/DefaultThemConfig.js +84 -0
  8. package/dist/body/DisplayBodyCell.js +80 -0
  9. package/dist/body/components/CheckBoxView.js +24 -0
  10. package/dist/body/components/CustomLinkView.js +30 -0
  11. package/dist/body/components/DataFormatView.js +43 -0
  12. package/dist/body/components/DeleteCellView.js +29 -0
  13. package/dist/errMsg/DefaultThemConfig.js +19 -0
  14. package/dist/errMsg/DisplayErrMsg.js +44 -0
  15. package/dist/header/ActionHeaderCell.js +42 -0
  16. package/dist/header/CustomCell.js +47 -0
  17. package/dist/header/CustomTblHeader.js +82 -0
  18. package/dist/header/DefaultThemConfig.js +160 -0
  19. package/dist/header/components/CheckBoxView.js +28 -0
  20. package/dist/header/components/DeleteCellView.js +47 -0
  21. package/dist/header/components/RemoveAllDialog.js +36 -0
  22. package/dist/index.js +45 -0
  23. package/dist/pagination/CustomPagination.js +74 -0
  24. package/dist/toolbar/CustomToolbar.js +53 -0
  25. package/dist/toolbar/DownloadButtonView.js +23 -0
  26. package/dist/toolbar/ManageColumnView.js +110 -0
  27. package/dist/util/ClassNames.js +22 -0
  28. package/dist/util/Dataformat.js +14 -0
  29. package/dist/util/Types.js +53 -0
  30. package/package.json +25 -0
  31. package/src/DefaultThemConfig.js +62 -0
  32. package/src/ExtendedView.js +63 -0
  33. package/src/TableView.js +94 -0
  34. package/src/body/ActionBodyCell.js +39 -0
  35. package/src/body/CustomTblBody.js +68 -0
  36. package/src/body/DefaultThemConfig.js +79 -0
  37. package/src/body/DisplayBodyCell.js +78 -0
  38. package/src/body/components/CheckBoxView.js +20 -0
  39. package/src/body/components/CustomLinkView.js +25 -0
  40. package/src/body/components/DataFormatView.js +44 -0
  41. package/src/body/components/DeleteCellView.js +31 -0
  42. package/src/errMsg/DefaultThemConfig.js +13 -0
  43. package/src/errMsg/DisplayErrMsg.js +40 -0
  44. package/src/header/ActionHeaderCell.js +42 -0
  45. package/src/header/CustomCell.js +51 -0
  46. package/src/header/CustomTblHeader.js +87 -0
  47. package/src/header/DefaultThemConfig.js +154 -0
  48. package/src/header/components/CheckBoxView.js +27 -0
  49. package/src/header/components/DeleteCellView.js +61 -0
  50. package/src/header/components/RemoveAllDialog.js +54 -0
  51. package/src/index.js +8 -0
  52. package/src/pagination/CustomPagination.js +66 -0
  53. package/src/toolbar/CustomToolbar.js +52 -0
  54. package/src/toolbar/DownloadButtonView.js +29 -0
  55. package/src/toolbar/ManageColumnView.js +134 -0
  56. package/src/util/ClassNames.js +17 -0
  57. package/src/util/Dataformat.js +8 -0
  58. package/src/util/Types.js +39 -0
@@ -0,0 +1,78 @@
1
+ import React from 'react';
2
+ import {
3
+ TableCell,
4
+ Link,
5
+ Typography,
6
+ } from '@material-ui/core';
7
+ import { cellTypes } from '../util/Types';
8
+ import CustomLinkView from './components/CustomLinkView';
9
+ import DataFormatView from './components/DataFormatView';
10
+
11
+ /**
12
+ * Custom Column reneder
13
+ */
14
+ const CustomComponent = ({
15
+ row,
16
+ column,
17
+ }) => {
18
+ const { dataField, customCellRender } = column;
19
+ return (
20
+ <>
21
+ {customCellRender({ ...row, ...column, label: row[dataField] })}
22
+ </>
23
+ );
24
+ };
25
+
26
+ /**
27
+ * data display columns
28
+ * @returns default/Link/Custom view
29
+ */
30
+ const ViewCell = ({
31
+ column,
32
+ row,
33
+ }) => {
34
+ const { cellType } = column;
35
+ switch (cellType) {
36
+ case cellTypes.FORMAT_DATA:
37
+ return (
38
+ <DataFormatView
39
+ row={row}
40
+ column={column}
41
+ />
42
+ );
43
+ case cellTypes.LINK:
44
+ return (
45
+ <CustomLinkView
46
+ row={row}
47
+ column={column}
48
+ />
49
+ );
50
+ case cellTypes.CUSTOM_ELEM:
51
+ return (
52
+ <CustomComponent
53
+ row={row}
54
+ column={column}
55
+ />
56
+ );
57
+ default:
58
+ return (
59
+ <Typography>
60
+ {row[column.dataField]}
61
+ </Typography>
62
+ );
63
+ }
64
+ };
65
+
66
+ const DisplayCell = ({
67
+ row,
68
+ column,
69
+ }) => (
70
+ <TableCell className={column.dataField}>
71
+ <ViewCell
72
+ row={row}
73
+ column={column}
74
+ />
75
+ </TableCell>
76
+ );
77
+
78
+ export default DisplayCell;
@@ -0,0 +1,20 @@
1
+ import React from 'react';
2
+ import {
3
+ Checkbox,
4
+ TableCell,
5
+ } from '@material-ui/core';
6
+
7
+ const CheckboxView = ({
8
+ row,
9
+ onRowSelectChange,
10
+ }) => (
11
+ <TableCell padding="checkbox">
12
+ <Checkbox
13
+ disableRipple
14
+ onClick={(event) => onRowSelectChange(event, row)}
15
+ checked={row.isChecked}
16
+ />
17
+ </TableCell>
18
+ );
19
+
20
+ export default CheckboxView;
@@ -0,0 +1,25 @@
1
+ import React from 'react';
2
+ import {
3
+ Link, Typography,
4
+ } from '@material-ui/core';
5
+ import { cellTypes } from '../../util/Types';
6
+
7
+ /**
8
+ * Custom Link component
9
+ */
10
+ const CustomLinkView = ({
11
+ column,
12
+ row,
13
+ }) => {
14
+ const { rootPath, pathParams } = column?.linkAttr;
15
+ const url = pathParams.map((attr) => `#${rootPath}/`.concat(row[attr]));
16
+ return (
17
+ <Link href={url} className={cellTypes.LINK}>
18
+ <Typography>
19
+ {row[column?.dataField]}
20
+ </Typography>
21
+ </Link>
22
+ );
23
+ };
24
+
25
+ export default CustomLinkView;
@@ -0,0 +1,44 @@
1
+ import React from 'react';
2
+ import { Typography } from '@material-ui/core';
3
+ import { dataFormatTypes } from '../../util/Types';
4
+ import { formatBytes } from '../../util/Dataformat';
5
+
6
+ /**
7
+ * dataformat view for file size (byte, MB, GB)
8
+ * or other data format column as required
9
+ */
10
+ const CellView = ({
11
+ column,
12
+ row,
13
+ }) => {
14
+ const { dataFormatType } = column;
15
+ const value = row[column?.dataField]
16
+ switch(dataFormatType) {
17
+ case dataFormatTypes.FORMAT_BYTES:
18
+ return (
19
+ <Typography>
20
+ {formatBytes(value)}
21
+ </Typography>
22
+ );
23
+ default:
24
+ return (
25
+ <Typography>
26
+ {value}
27
+ </Typography>
28
+ );
29
+ }
30
+ };
31
+
32
+ const DataFormatView = ({
33
+ column,
34
+ row,
35
+ }) => (
36
+ <>
37
+ <CellView
38
+ column={column}
39
+ row={row}
40
+ />
41
+ </>
42
+ );
43
+
44
+ export default DataFormatView;
@@ -0,0 +1,31 @@
1
+ import React from 'react';
2
+ import {
3
+ IconButton,
4
+ TableCell,
5
+ } from '@material-ui/core';
6
+ import {
7
+ DeleteOutline as DeleteOutlineIcon,
8
+ } from '@material-ui/icons';
9
+
10
+ const DeleteCellView = ({
11
+ column,
12
+ row,
13
+ }) => (
14
+ <TableCell
15
+ scope="col"
16
+ className="delete_row"
17
+ >
18
+ <IconButton
19
+ disableRipple
20
+ className="del_row_btn"
21
+ onClick={() => column.cellEventHandler(row)}
22
+ >
23
+ <DeleteOutlineIcon
24
+ className="del_row_btn_icon"
25
+ fontSize="small"
26
+ />
27
+ </IconButton>
28
+ </TableCell>
29
+ );
30
+
31
+ export default DeleteCellView;
@@ -0,0 +1,13 @@
1
+ const defaultTheme = () => ({
2
+ MuiTypography: {
3
+ root: {
4
+ color: '#4a4a4a',
5
+ fontFamily: 'Roboto, Helvetica, Arial, sans-serif',
6
+ fontWeight: '500',
7
+ lineHeight: '1.5',
8
+ letterSpacing: '0.00938em',
9
+ },
10
+ },
11
+ });
12
+
13
+ export default defaultTheme;
@@ -0,0 +1,40 @@
1
+ import {
2
+ Container,
3
+ createTheme,
4
+ ThemeProvider,
5
+ Typography,
6
+ withStyles,
7
+ } from '@material-ui/core';
8
+ import React from 'react';
9
+ import defaultTheme from './DefaultThemConfig';
10
+
11
+ const DisplayErr = ({
12
+ classes,
13
+ table,
14
+ customTheme,
15
+ }) => {
16
+ const { tableMsg } = table;
17
+ const themeConfig = createTheme({ overrides: { ...defaultTheme(), ...customTheme } });
18
+
19
+ return (
20
+ <ThemeProvider theme={themeConfig}>
21
+ <Container
22
+ className={classes.errContainer}
23
+ >
24
+ <Typography className="errMsgText">
25
+ {tableMsg && tableMsg.noMatch}
26
+ </Typography>
27
+ </Container>
28
+ </ThemeProvider>
29
+ );
30
+ };
31
+
32
+ const styles = () => ({
33
+ errContainer: {
34
+ textAlign: 'center',
35
+ height: '40px',
36
+ paddingTop: '10px',
37
+ },
38
+ });
39
+
40
+ export default withStyles(styles)(DisplayErr);
@@ -0,0 +1,42 @@
1
+ import React from 'react';
2
+ import { Typography } from '@material-ui/core';
3
+ import { cellTypes } from '../util/Types';
4
+ import CheckboxView from './components/CheckBoxView';
5
+ import DeleteCellView from './components/DeleteCellView';
6
+
7
+ const ActionHeaderCell = ({
8
+ includeSelectedIds,
9
+ toggleSelectAll,
10
+ Ids,
11
+ count,
12
+ rows,
13
+ column,
14
+ }) => {
15
+ const { cellType } = column;
16
+
17
+ if (cellTypes.CHECKBOX === cellType) {
18
+ return (
19
+ <CheckboxView
20
+ includeSelectedIds={includeSelectedIds}
21
+ toggleSelectAll={toggleSelectAll}
22
+ Ids={Ids}
23
+ />
24
+ )
25
+ }
26
+
27
+ if (cellTypes.DELETE === cellType) {
28
+ return (
29
+ <DeleteCellView
30
+ rows={rows}
31
+ count={count}
32
+ column={column}
33
+ />
34
+ );
35
+ }
36
+
37
+ return (
38
+ <></>
39
+ );
40
+ }
41
+
42
+ export default ActionHeaderCell;
@@ -0,0 +1,51 @@
1
+ import React from 'react';
2
+ import TableCell from '@material-ui/core/TableCell';
3
+ import TableSortLabel from '@material-ui/core/TableSortLabel';
4
+ import MuiTooltip from '@material-ui/core/Tooltip';
5
+ import { headerTypes } from '../util/Types';
6
+
7
+ /**
8
+ *
9
+ * @returns default/Link/Custom view
10
+ */
11
+ const CustomHeaderCell = ({
12
+ sortOrder,
13
+ sortBy,
14
+ column,
15
+ components = {},
16
+ toggleSort,
17
+ }) => {
18
+ const {
19
+ dataField,
20
+ tooltipText,
21
+ header,
22
+ headerType,
23
+ customColHeaderRender,
24
+ } = column;
25
+
26
+ const Tooltip = components.Tooltip || MuiTooltip;
27
+
28
+ return (
29
+ <TableCell
30
+ scope="col"
31
+ active={sortBy === dataField}
32
+ direction={sortOrder}
33
+ >
34
+ <Tooltip
35
+ title={tooltipText}
36
+ >
37
+ <TableSortLabel
38
+ active={sortBy === dataField}
39
+ hideSortIcon={sortBy !== dataField}
40
+ direction={sortBy === dataField ? sortOrder : 'asc'}
41
+ onClick={toggleSort}
42
+ >
43
+ {(headerType === headerTypes.CUSTOM_ELEM && customColHeaderRender)
44
+ ? customColHeaderRender(column) : header}
45
+ </TableSortLabel>
46
+ </Tooltip>
47
+ </TableCell>
48
+ );
49
+ };
50
+
51
+ export default CustomHeaderCell;
@@ -0,0 +1,87 @@
1
+ import React from 'react';
2
+ import PropTypes from 'prop-types';
3
+ import {
4
+ TableHead,
5
+ TableRow,
6
+ createTheme,
7
+ ThemeProvider,
8
+ } from '@material-ui/core';
9
+ import HeaderCell from './CustomCell';
10
+ // import { getClsName, tableCls } from '../util/ClassNames';
11
+ import defaultTheme from './DefaultThemConfig';
12
+ import { actionCellTypes, cellTypes } from '../util/Types';
13
+ import CheckboxView from './components/CheckBoxView';
14
+ import DeleteCellView from './components/DeleteCellView';
15
+ import ActionHeaderCell from './ActionHeaderCell';
16
+
17
+ const CustomTableHeader = ({
18
+ table,
19
+ rows = [],
20
+ toggleSelectAll,
21
+ sortByColumn,
22
+ components = {},
23
+ customTheme = {},
24
+ count,
25
+ }) => {
26
+ const {
27
+ columns,
28
+ selectedRows = [],
29
+ sortBy,
30
+ sortOrder,
31
+ } = table;
32
+ const Ids = rows.map((row) => row[table.dataKey]);
33
+ const includeSelectedIds = Ids.some((id) => selectedRows.includes(id));
34
+ const displayColunms = columns.filter((col) => col.display);
35
+ /**
36
+ * create root class name based on table info
37
+ * themeprovider to customize style
38
+ */
39
+ // const rootClsName = getClsName(table.title, tableCls.HEADER);
40
+ const themeConfig = createTheme({ overrides: { ...defaultTheme(), ...customTheme } });
41
+ return (
42
+ <ThemeProvider theme={themeConfig}>
43
+ <TableHead>
44
+ <TableRow>
45
+ {
46
+ displayColunms.map((column) => {
47
+ const { cellType } = column;
48
+ const isActionCell = actionCellTypes.includes(cellType) || false;
49
+
50
+ if (isActionCell) {
51
+ return (
52
+ <ActionHeaderCell
53
+ includeSelectedIds={includeSelectedIds}
54
+ toggleSelectAll={toggleSelectAll}
55
+ Ids={Ids}
56
+ rows={rows}
57
+ count={count}
58
+ column={column}
59
+ />
60
+ )
61
+ }
62
+
63
+ return (
64
+ <HeaderCell
65
+ components={components}
66
+ column={column}
67
+ sortBy={sortBy}
68
+ sortOrder={sortOrder}
69
+ toggleSort={() => sortByColumn(column.dataField, sortOrder)}
70
+ />
71
+ );
72
+ })
73
+ }
74
+ </TableRow>
75
+ </TableHead>
76
+ </ThemeProvider>
77
+ );
78
+ };
79
+
80
+ CustomTableHeader.propTypes = {
81
+ table: PropTypes.objectOf(PropTypes.object).isRequired,
82
+ rows: PropTypes.arrayOf(PropTypes.object).isRequired,
83
+ toggleSelectAll: PropTypes.func.isRequired,
84
+ sortByColumn: PropTypes.string.isRequired,
85
+ };
86
+
87
+ export default CustomTableHeader;
@@ -0,0 +1,154 @@
1
+ const defaultTheme = () => ({
2
+ MuiTableHead: {
3
+ root: {
4
+ fontWeight: '400',
5
+ lineHeight: '1.5',
6
+ letterSpacing: '0.00938em',
7
+ },
8
+ },
9
+ MuiCheckbox: {
10
+ colorPrimary: {
11
+ color: '#13344A',
12
+ marginLeft: '12px',
13
+ '&.Mui-checked': {
14
+ color: '#13344A',
15
+ },
16
+ },
17
+ },
18
+ MuiTableCell: {
19
+ root: {
20
+ padding: '0px 5px 0px 20px',
21
+ color: '#13344A',
22
+ cursor: 'pointer',
23
+ },
24
+ },
25
+ MuiTableSortLabel: {
26
+ root: {
27
+ color: '#13344A',
28
+ position: 'relative',
29
+ fontSize: '11pt',
30
+ fontFamily: 'Lato Regular,Raleway, sans-serif',
31
+ fontWeight: 'bold',
32
+ letterSpacing: '0.06em',
33
+ textDecoration: 'underline',
34
+ '&:hover': {
35
+ pointerEvents: 'none',
36
+ color: 'red',
37
+ },
38
+ '&:focus': {
39
+ pointerEvents: 'none',
40
+ color: '#13344A',
41
+ },
42
+ },
43
+ },
44
+ MuiButtonBase: {
45
+ root: {
46
+ color: '#13344A',
47
+ },
48
+ },
49
+ MuiButton: {
50
+ text: {
51
+ padding: '10px 16px',
52
+ },
53
+ root: {
54
+ color: '#fff',
55
+ fontSize: '0.875rem',
56
+ marginTop: '6px',
57
+ fontFamily: 'Lato',
58
+ borderRadius: '4px',
59
+ marginBottom: '10px',
60
+ textTransform: 'uppercase',
61
+ width: '133px',
62
+ height: '45px',
63
+ '&.okBtn': {
64
+ width: '133px',
65
+ height: '45px',
66
+ cursor: 'pointer',
67
+ background: '#98a19e',
68
+ },
69
+ '&.cancelBtn': {
70
+ width: '133px',
71
+ height: '45px',
72
+ cursor: 'pointer',
73
+ background: '#42779a',
74
+ },
75
+ },
76
+ },
77
+ MuiTableRow: {
78
+ head: {
79
+ height: '40px',
80
+ borderBottom: '3px solid #42779a',
81
+ borderTop: '3px solid #42779a',
82
+ },
83
+ },
84
+ MuiTypography: {
85
+ root: {
86
+ '&.del_all_row_text': {
87
+ lineHeight: '37px',
88
+ float: 'left',
89
+ color: '#A61401',
90
+ fontSize: '11pt',
91
+ textAlign: 'center',
92
+ fontFamily: 'Lato Regular, Raleway, sans-serif',
93
+ },
94
+ '&.remove_all_tooltip': {
95
+ zIndex: '1000',
96
+ border: '2px solid #A61401',
97
+ background: '#fff',
98
+ fontSize: '12px',
99
+ width: '110px',
100
+ height: '48px',
101
+ fontWeight: '500',
102
+ color: '#A61401',
103
+ borderRadius: '7px',
104
+ padding: '5px 10px',
105
+ textAlign: 'center',
106
+ },
107
+ },
108
+ },
109
+ MuiSvgIcon: {
110
+ root: {
111
+ '&.del_all_row_btn_icon': {
112
+ color: '#A61401',
113
+ },
114
+ },
115
+ },
116
+ MuiTooltip: {
117
+ tooltipPlacementBottom: {
118
+ margin: '0px 0px 20px 0px',
119
+ '@media (min-width: 600px)': {
120
+ margin: '0px 0px 20px 0px',
121
+ },
122
+ },
123
+ tooltip: {
124
+ // backgroundColor: 'none',
125
+ },
126
+ },
127
+ MuiDialog: {
128
+ paper: {
129
+ width: '431px',
130
+ height: '170px',
131
+ borderRadius: '25px',
132
+ textAlign: 'center',
133
+ backgroundColor: '#E8DFDC',
134
+ border: '2px solid #A61401',
135
+ },
136
+ },
137
+ MuiDialogContent: {
138
+ root: {
139
+ padding: '40px 20px 0px 20px',
140
+ '&.alter-content': {
141
+ fontFamily: 'Lato',
142
+ size: '16px',
143
+ },
144
+ },
145
+ },
146
+ MuiDialogActions: {
147
+ root: {
148
+ justifyContent: 'center',
149
+ paddingBottom: '25px',
150
+ },
151
+ },
152
+ });
153
+
154
+ export default defaultTheme;
@@ -0,0 +1,27 @@
1
+ import React from 'react';
2
+ import {
3
+ TableCell,
4
+ Checkbox,
5
+ FormControlLabel,
6
+ } from '@material-ui/core';
7
+
8
+ const CheckboxView = ({
9
+ includeSelectedIds,
10
+ toggleSelectAll,
11
+ Ids,
12
+ }) => (
13
+ <TableCell padding="checkbox">
14
+ <FormControlLabel
15
+ control={(
16
+ <Checkbox
17
+ color="primary"
18
+ indeterminate={includeSelectedIds}
19
+ checked={includeSelectedIds}
20
+ onChange={(event) => toggleSelectAll(event, Ids, includeSelectedIds)}
21
+ />
22
+ )}
23
+ />
24
+ </TableCell>
25
+ );
26
+
27
+ export default CheckboxView;
@@ -0,0 +1,61 @@
1
+ import React, { useState } from 'react';
2
+ import {
3
+ TableCell,
4
+ Typography,
5
+ IconButton,
6
+ Tooltip,
7
+ } from '@material-ui/core';
8
+ import {
9
+ ArrowDropDown as ArrowDropDownIcon,
10
+ } from '@material-ui/icons';
11
+ import RemoveAllDialogView from './RemoveAllDialog';
12
+
13
+ const TooltipContent = () => (
14
+ <Typography className="remove_all_tooltip">
15
+ {' '}
16
+ Remove
17
+ {' '}
18
+ <b>All</b>
19
+ {' '}
20
+ items in cart.
21
+ {' '}
22
+ </Typography>
23
+ );
24
+
25
+ const DeleteCellView = ({
26
+ column,
27
+ count,
28
+ }) => {
29
+ const [displayDialog, setDisplay] = useState(false);
30
+ const toggleDialogDisplay = () => setDisplay(!displayDialog);
31
+ return (
32
+ <TableCell
33
+ scope="col"
34
+ className="del_all_row"
35
+ >
36
+ <Typography className="del_all_row_text">
37
+ Remove
38
+ </Typography>
39
+ <Tooltip
40
+ className="del_all_row_tooltip"
41
+ title={TooltipContent()}
42
+ renderComponent={TooltipContent()}
43
+ >
44
+ <IconButton aria-label="help" className="del_all_row_btn">
45
+ <ArrowDropDownIcon
46
+ className="del_all_row_btn_icon"
47
+ onClick={toggleDialogDisplay}
48
+ />
49
+ </IconButton>
50
+ </Tooltip>
51
+ <RemoveAllDialogView
52
+ open={displayDialog}
53
+ removeAllFiles={column.headerEventHandler}
54
+ count={count}
55
+ toggleDisplay={toggleDialogDisplay}
56
+ />
57
+ </TableCell>
58
+ );
59
+ };
60
+
61
+ export default DeleteCellView;