@maherunlocker/custom-react-table
Version:
dynamic table based on react table v7
309 lines • 11.5 kB
JavaScript
"use strict";
var __rest = (this && this.__rest) || function (s, e) {
var t = {};
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
t[p] = s[p];
if (s != null && typeof Object.getOwnPropertySymbols === "function")
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
t[p[i]] = s[p[i]];
}
return t;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.RowCheckbox = exports.HeaderCheckbox = exports.TableLabel = exports.TableCell = exports.TableRow = exports.TableHeadCell = exports.TableHeadRow = exports.TableHead = exports.TableBody = exports.RawTable = exports.useStyles = void 0;
const jsx_runtime_1 = require("react/jsx-runtime");
const material_1 = require("@mui/material");
const TableBody_1 = __importDefault(require("@mui/material/TableBody"));
const TableCell_1 = __importDefault(require("@mui/material/TableCell"));
const TableHead_1 = __importDefault(require("@mui/material/TableHead"));
const TableRow_1 = __importDefault(require("@mui/material/TableRow"));
const Table_1 = __importDefault(require("@mui/material/Table"));
const react_1 = __importDefault(require("react"));
const classnames_1 = __importDefault(require("classnames"));
const styles_1 = require("@mui/styles");
const important_1 = require("../utils/important");
exports.useStyles = (0, styles_1.makeStyles)({
rawTable: {
borderSpacing: 0,
border: '1px solid rgba(224, 224, 224, 1)',
maxWidth: '100%',
borderTop: '0',
fontFamily: `"Segoe UI", "-apple-system", "Helvetica Neue", "Arial"`,
// minHeight: '100vh',
// marginTop: 5,
},
tableHead: {
position: 'sticky',
top: '0px',
zIndex: 200,
borderTop: '0',
marginTop: '0',
marginBottom: '2',
paddingTop: '0',
},
stickyCol: {
position: (0, important_1.important)('sticky'),
right: (0, important_1.important)('45px'),
background: 'white',
//boxShadow: '5px 2px 5px grey',
},
hide_colomns_sticky: {
position: (0, important_1.important)('sticky'),
right: (0, important_1.important)(0),
background: 'white',
//boxShadow: '5px 2px 5px grey',
},
tableHeadRow: {
// backgroundColor: 'red',
backgroundColor: '#F8F8FB ',
color: '#000',
border: '0px',
// borderBottom: '1px solid rgba(224, 224, 224, 1)',
// '&:hover $resizeHandle': {
// opacity: 1,
// },
},
tableHeadCell: {
padding: '16px 1px 16px 16px',
fontSize: '0.875rem',
textAlign: 'center',
maxHeight: 45,
verticalAlign: 'inherit',
justifyContent: 'center !important',
display: 'flex',
fontFamily: `"Segoe UI", "-apple-system", "Helvetica Neue", "Arial"`,
fontWeight: '700 !important',
lineHeight: '1.5rem',
borderRight: '1px solid rgba(224, 224, 224, 1)',
'&:last-child': {
borderRight: 'none',
},
// borderBottom: '1px solid #555B6D',
},
tableBody: {
fontFamily: `"Segoe UI", "-apple-system", "Helvetica Neue", "Arial"`,
},
tableRow: {
color: 'inherit',
maxHeight: 50,
outline: 0,
fontFamily: `"Segoe UI", "-apple-system", "Helvetica Neue", "Arial"`,
verticalAlign: 'middle',
backgroundColor: 'white',
border: 'none',
'&:hover': {
backgroundColor: 'rgba(0, 0, 0, 0.07)',
},
'&:nth-child(even)': {
backgroundColor: 'hsl(0, 0%, 98%,1)',
},
borderBottom: '1px rgb(239, 239, 239)',
'&:last-child': {
borderBottom: 'none',
},
'&.rowSelected': {
backgroundColor: 'rgba(195, 55, 55, 0.04)',
// backgroundColor: 'rgba(0, 0, 0, 0.04)',
'&:hover': {
backgroundColor: 'rgba(0, 0, 0, 0.07)',
},
},
'&.clickable': {
cursor: 'pointer',
},
},
tableLabel: {},
tableCell: {
padding: '8px 16px',
fontFamily: `"Segoe UI", "-apple-system", "Helvetica Neue", "Arial"`,
fontSize: '0.875rem',
textAlign: 'center',
fontWeight: 300,
lineHeight: 1.3,
verticalAlign: 'inherit',
color: 'rgba(0, 0, 0, 0.87)',
display: 'flex',
justifyContent: 'center',
alignItems: 'center',
// borderRight: '1px solid rgba(224, 224, 224, 1)',
// '&:last-child': {
// borderRight: 'none',
// },
},
resizeHandle: {
position: 'absolute',
cursor: 'col-resize',
zIndex: 100,
opacity: 0,
borderLeft: '1px solid #42a5f5',
borderRight: '1px solid #42a5f5',
height: '50%',
top: '25%',
transition: 'all linear 100ms',
right: -2,
width: 3,
'&.handleActive': {
opacity: 1,
border: 'none',
backgroundColor: '#42a5f5',
height: 'calc(100% - 4px)',
top: '2px',
right: -1,
width: 1,
},
},
tableSortLabel: {
'& svg': {
width: 16,
height: 16,
marginTop: 0,
marginLeft: 2,
},
},
tableFilterAltOutlinedIcon: {
width: ' 21px !important',
height: '23px !important',
marginTop: 0,
marginRight: 2,
},
headerIcon: {
'& svg': {
width: 16,
height: 16,
marginTop: 4,
marginRight: 0,
},
},
iconDirectionAsc: {
transform: 'rotate(90deg)',
},
iconDirectionDesc: {
transform: 'rotate(180deg)',
},
iconDirectionRight: {
transform: 'rotate(180deg)',
},
cellIcon: {
'& svg': {
width: 16,
height: 16,
marginTop: 3,
},
},
FiltersCss: {
border: '1px solid rgba(224, 224, 224, 1)',
borderSpacing: 0,
paddingLeft: '0 !important',
paddingTop: '0 !important',
height: '45px !important',
backgroundColor: ' var(--unnamed-color-ffffff) 0% 0% no-repeat padding-box ',
alignItems: 'center',
minHeight: '64px',
},
DividerCss: {
background: '#F7F7FA 0% 0% no-repeat padding-box',
// border: '1px solid #F1F1F1',
height: '2px',
},
SvgNoDataCss: {
display: 'flex !important',
justifyContent: 'center !important',
alignContent: 'center!important',
alignItems: 'center!important',
border: '0',
height: '60%',
},
cardHeaderCss: {
padding: '0 ',
backgroundColor: 'white',
marginBottom: '4px !important',
border: '1px solid rgba(0,0,0,.125)',
},
cell_short: {
lineHeight: '1.5rem',
fontWeight: '700!important',
// width: 100,
border: '0 !important',
},
});
const areEqual = (prevProps, nextProps) => prevProps.checked === nextProps.checked &&
prevProps.indeterminate === nextProps.indeterminate;
const RawTable = (_a) => {
var { children, className } = _a, rest = __rest(_a, ["children", "className"]);
const classes = (0, exports.useStyles)();
return ((0, jsx_runtime_1.jsx)(Table_1.default, Object.assign({ className: (0, classnames_1.default)(className, classes.rawTable) }, rest, { children: children })));
};
exports.RawTable = RawTable;
const TableBody = (_a) => {
var { children, className } = _a, rest = __rest(_a, ["children", "className"]);
const classes = (0, exports.useStyles)();
return ((0, jsx_runtime_1.jsx)(TableBody_1.default, Object.assign({ className: (0, classnames_1.default)(className, classes.tableBody) }, rest, { children: children })));
};
exports.TableBody = TableBody;
const TableHead = (_a) => {
var { children, className } = _a, rest = __rest(_a, ["children", "className"]);
const classes = (0, exports.useStyles)();
return ((0, jsx_runtime_1.jsx)(TableHead_1.default, Object.assign({ className: (0, classnames_1.default)(className, classes.tableHead) }, rest, { children: children })));
};
exports.TableHead = TableHead;
const TableHeadRow = (_a) => {
var { children, className } = _a, rest = __rest(_a, ["children", "className"]);
const classes = (0, exports.useStyles)();
return ((0, jsx_runtime_1.jsx)(TableRow_1.default, Object.assign({ className: (0, classnames_1.default)(className, classes.tableHeadRow) }, rest, { children: children })));
};
exports.TableHeadRow = TableHeadRow;
const TableHeadCell = (_a) => {
var { children, className } = _a, rest = __rest(_a, ["children", "className"]);
const classes = (0, exports.useStyles)();
return ((0, jsx_runtime_1.jsx)(TableCell_1.default, Object.assign({ className: (0, classnames_1.default)(className, classes.tableHeadCell) }, rest, { children: children })));
};
exports.TableHeadCell = TableHeadCell;
const TableRow = (_a) => {
var { children, className } = _a, rest = __rest(_a, ["children", "className"]);
const classes = (0, exports.useStyles)();
return ((0, jsx_runtime_1.jsx)(TableRow_1.default, Object.assign({ className: (0, classnames_1.default)(className, classes.tableRow) }, rest, { children: children })));
};
exports.TableRow = TableRow;
// export const TableRow = React.memo(TableRow_, areEqual);
const TableCell = (_a) => {
var { children, className } = _a, rest = __rest(_a, ["children", "className"]);
const classes = (0, exports.useStyles)();
return ((0, jsx_runtime_1.jsx)(TableCell_1.default, Object.assign({ className: (0, classnames_1.default)(className, classes.tableCell) }, rest, { children: children })));
};
exports.TableCell = TableCell;
// export const TableCell = React.memo(TableCell_, areEqual);
const TableLabel = (_a) => {
var { children, className } = _a, rest = __rest(_a, ["children", "className"]);
const classes = (0, exports.useStyles)();
return ((0, jsx_runtime_1.jsx)("div", Object.assign({ className: (0, classnames_1.default)(className, classes.tableLabel) }, rest, { children: children })));
};
exports.TableLabel = TableLabel;
exports.HeaderCheckbox = react_1.default.memo((0, material_1.styled)(material_1.Checkbox)({
fontSize: '1rem',
margin: '-8px 0 -8px -15px',
padding: '8px 9px',
'& svg': {
width: '24px',
height: '24px',
},
'&:hover': {
backgroundColor: 'transparent',
},
}), areEqual);
exports.RowCheckbox = react_1.default.memo((0, material_1.styled)(material_1.Checkbox)({
fontSize: '14px',
margin: '-9px 0 -8px -15px',
padding: '5px 9px',
'&:hover': {
backgroundColor: 'transparent',
},
'& svg': {
width: 24,
height: 24,
},
}), areEqual);
//# sourceMappingURL=TableStyle.js.map