@pdg/react-table 1.0.1 → 1.0.3
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/dist/Table/Table.d.ts +2 -2
- package/dist/Table/Table.types.d.ts +2 -1
- package/dist/index.esm.js +21 -13
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +21 -13
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/Table/Table.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import { TableProps, TableCommands } from './Table.types';
|
|
2
|
+
import { TableProps, TableCommands, TableItem } from './Table.types';
|
|
3
3
|
import 'simplebar-react/dist/simplebar.min.css';
|
|
4
|
-
declare const Table: React.ForwardRefExoticComponent<TableProps<
|
|
4
|
+
declare const Table: React.ForwardRefExoticComponent<TableProps<TableItem> & React.RefAttributes<TableCommands>>;
|
|
5
5
|
export default Table;
|
|
@@ -13,6 +13,7 @@ export interface TableColumn<T = TableItem> {
|
|
|
13
13
|
width?: string | number;
|
|
14
14
|
minWidth?: string | number;
|
|
15
15
|
ellipsis?: boolean;
|
|
16
|
+
dateFormat?: string;
|
|
16
17
|
tooltipProps?: Omit<TooltipProps, 'children' | 'title'>;
|
|
17
18
|
head?: {
|
|
18
19
|
className?: CommonSxProps['className'];
|
|
@@ -44,7 +45,7 @@ export interface TableColumn<T = TableItem> {
|
|
|
44
45
|
onClick?(item: T, index: number): void;
|
|
45
46
|
}
|
|
46
47
|
export interface TableProps<T = TableItem> extends CommonSxProps {
|
|
47
|
-
columns?: TableColumn<T>[];
|
|
48
|
+
columns?: (TableColumn<T> | false | undefined | null)[];
|
|
48
49
|
defaultAlign?: TableCellProps['align'];
|
|
49
50
|
defaultEllipsis?: boolean;
|
|
50
51
|
stickyHeader?: boolean;
|
package/dist/index.esm.js
CHANGED
|
@@ -8523,13 +8523,13 @@ var TableBodyCell = function (_a) {
|
|
|
8523
8523
|
}
|
|
8524
8524
|
break;
|
|
8525
8525
|
case 'date':
|
|
8526
|
-
if (data
|
|
8527
|
-
data = dayjs(data).format('YYYY-MM-DD');
|
|
8526
|
+
if (data) {
|
|
8527
|
+
data = dayjs(data, column.dateFormat).format('YYYY-MM-DD');
|
|
8528
8528
|
}
|
|
8529
8529
|
break;
|
|
8530
8530
|
case 'datetime':
|
|
8531
|
-
if (data
|
|
8532
|
-
data = dayjs(data).format('YYYY-MM-DD HH:mm:ss');
|
|
8531
|
+
if (data) {
|
|
8532
|
+
data = dayjs(data, column.dateFormat).format('YYYY-MM-DD HH:mm:ss');
|
|
8533
8533
|
}
|
|
8534
8534
|
break;
|
|
8535
8535
|
default:
|
|
@@ -8604,7 +8604,10 @@ var templateObject_1;var TableFooterCell = function (_a) {
|
|
|
8604
8604
|
style.appendChild(document.createTextNode(css));
|
|
8605
8605
|
}
|
|
8606
8606
|
}var css_248z = "[data-simplebar]{position:relative;flex-direction:column;flex-wrap:wrap;justify-content:flex-start;align-content:flex-start;align-items:flex-start}.simplebar-wrapper{overflow:hidden;width:inherit;height:inherit;max-width:inherit;max-height:inherit}.simplebar-mask{direction:inherit;position:absolute;overflow:hidden;padding:0;margin:0;left:0;top:0;bottom:0;right:0;width:auto!important;height:auto!important;z-index:0}.simplebar-offset{direction:inherit!important;box-sizing:inherit!important;resize:none!important;position:absolute;top:0;left:0;bottom:0;right:0;padding:0;margin:0;-webkit-overflow-scrolling:touch}.simplebar-content-wrapper{direction:inherit;box-sizing:border-box!important;position:relative;display:block;height:100%;width:auto;max-width:100%;max-height:100%;scrollbar-width:none;-ms-overflow-style:none}.simplebar-content-wrapper::-webkit-scrollbar,.simplebar-hide-scrollbar::-webkit-scrollbar{width:0;height:0}.simplebar-content:after,.simplebar-content:before{content:' ';display:table}.simplebar-placeholder{max-height:100%;max-width:100%;width:100%;pointer-events:none}.simplebar-height-auto-observer-wrapper{box-sizing:inherit!important;height:100%;width:100%;max-width:1px;position:relative;float:left;max-height:1px;overflow:hidden;z-index:-1;padding:0;margin:0;pointer-events:none;flex-grow:inherit;flex-shrink:0;flex-basis:0}.simplebar-height-auto-observer{box-sizing:inherit;display:block;opacity:0;position:absolute;top:0;left:0;height:1000%;width:1000%;min-height:1px;min-width:1px;overflow:hidden;pointer-events:none;z-index:-1}.simplebar-track{z-index:1;position:absolute;right:0;bottom:0;pointer-events:none;overflow:hidden}[data-simplebar].simplebar-dragging .simplebar-content{pointer-events:none;user-select:none;-webkit-user-select:none}[data-simplebar].simplebar-dragging .simplebar-track{pointer-events:all}.simplebar-scrollbar{position:absolute;left:0;right:0;min-height:10px}.simplebar-scrollbar:before{position:absolute;content:'';background:#000;border-radius:7px;left:2px;right:2px;opacity:0;transition:opacity .2s .5s linear}.simplebar-scrollbar.simplebar-visible:before{opacity:.5;transition-delay:0s;transition-duration:0s}.simplebar-track.simplebar-vertical{top:0;width:11px}.simplebar-scrollbar:before{top:2px;bottom:2px;left:2px;right:2px}.simplebar-track.simplebar-horizontal{left:0;height:11px}.simplebar-track.simplebar-horizontal .simplebar-scrollbar{right:auto;left:0;top:0;bottom:0;min-height:0;min-width:10px;width:auto}[data-simplebar-direction=rtl] .simplebar-track.simplebar-vertical{right:auto;left:0}.simplebar-dummy-scrollbar-size{direction:rtl;position:fixed;opacity:0;visibility:hidden;height:500px;width:500px;overflow-y:hidden;overflow-x:scroll;-ms-overflow-style:scrollbar!important}.simplebar-dummy-scrollbar-size>div{width:200%;height:200%;margin:10px 0}.simplebar-hide-scrollbar{position:fixed;left:0;visibility:hidden;overflow-y:scroll;scrollbar-width:none;-ms-overflow-style:none}\n";
|
|
8607
|
-
styleInject(css_248z);
|
|
8607
|
+
styleInject(css_248z);function columnFilter(v) {
|
|
8608
|
+
return v !== undefined && v !== null && v !== false;
|
|
8609
|
+
}
|
|
8610
|
+
var Table = React__default.forwardRef(function (_a, ref) {
|
|
8608
8611
|
// State - footerHeight --------------------------------------------------------------------------------------------
|
|
8609
8612
|
var initColumns = _a.columns, initItems = _a.items, initPaging = _a.paging, pagingAlign = _a.pagingAlign, defaultAlign = _a.defaultAlign, defaultEllipsis = _a.defaultEllipsis, stickyHeader = _a.stickyHeader, height = _a.height, minHeight = _a.minHeight, maxHeight = _a.maxHeight, showOddColor = _a.showOddColor, showEvenColor = _a.showEvenColor, cellPadding = _a.cellPadding, footer = _a.footer, noData = _a.noData, pagination = _a.pagination, onClick = _a.onClick, onGetBodyRowSx = _a.onGetBodyRowSx, onPageChange = _a.onPageChange;
|
|
8610
8613
|
var _b = useState(), footerHeight = _b[0], setFooterHeight = _b[1];
|
|
@@ -8622,8 +8625,9 @@ styleInject(css_248z);var Table = React__default.forwardRef(function (_a, ref) {
|
|
|
8622
8625
|
}).ref;
|
|
8623
8626
|
// State -----------------------------------------------------------------------------------------------------------
|
|
8624
8627
|
var _c = useAutoUpdateState(initColumns), columns = _c[0], setColumns = _c[1];
|
|
8625
|
-
var _d =
|
|
8626
|
-
var _e = useAutoUpdateState(
|
|
8628
|
+
var _d = useState(), finalColumns = _d[0], setFinalColumns = _d[1];
|
|
8629
|
+
var _e = useAutoUpdateState(initItems), items = _e[0], setItems = _e[1];
|
|
8630
|
+
var _f = useAutoUpdateState(initPaging), paging = _f[0], setPaging = _f[1];
|
|
8627
8631
|
var tableSx = useAutoUpdateState(useCallback(function () {
|
|
8628
8632
|
var sx = {
|
|
8629
8633
|
padding: typeof cellPadding === 'number' ? "".concat(cellPadding, "px") : cellPadding,
|
|
@@ -8634,6 +8638,10 @@ styleInject(css_248z);var Table = React__default.forwardRef(function (_a, ref) {
|
|
|
8634
8638
|
'> .MuiTableFooter-root > .MuiTableRow-root > .MuiTableCell-root ': sx,
|
|
8635
8639
|
};
|
|
8636
8640
|
}, [cellPadding]))[0];
|
|
8641
|
+
// Effect ----------------------------------------------------------------------------------------------------------
|
|
8642
|
+
useEffect(function () {
|
|
8643
|
+
setFinalColumns(columns === null || columns === void 0 ? void 0 : columns.filter(columnFilter));
|
|
8644
|
+
}, [columns]);
|
|
8637
8645
|
// Commands --------------------------------------------------------------------------------------------------------
|
|
8638
8646
|
useLayoutEffect(function () {
|
|
8639
8647
|
if (ref) {
|
|
@@ -8664,13 +8672,13 @@ styleInject(css_248z);var Table = React__default.forwardRef(function (_a, ref) {
|
|
|
8664
8672
|
}
|
|
8665
8673
|
}, [ref, columns, items, paging]);
|
|
8666
8674
|
// Render ----------------------------------------------------------------------------------------------------------
|
|
8667
|
-
return
|
|
8675
|
+
return finalColumns ? (React__default.createElement(Paper, { className: 'ReactMuiTable', variant: 'outlined', style: { width: '100%' } },
|
|
8668
8676
|
React__default.createElement(SimpleBar, { style: { height: height, minHeight: minHeight, maxHeight: maxHeight } },
|
|
8669
8677
|
React__default.createElement(Table$1, { stickyHeader: stickyHeader, sx: tableSx },
|
|
8670
8678
|
React__default.createElement(TableHead, null,
|
|
8671
|
-
React__default.createElement(TableRow, null,
|
|
8672
|
-
React__default.createElement(TableBody, { style: { paddingBottom: footerHeight || 65 } }, items ? (items.length > 0 ? (items.map(function (item, idx) { return (React__default.createElement(StyledBodyRow, { className: classNames(!!showOddColor && 'odd-color', !!showEvenColor && 'even-color'), key: idx, hover: true, sx: onGetBodyRowSx ? onGetBodyRowSx(item, idx) : undefined },
|
|
8673
|
-
React__default.createElement(TableCell, { colSpan:
|
|
8679
|
+
React__default.createElement(TableRow, null, finalColumns.map(function (column, idx) { return (React__default.createElement(TableHeadCell, { key: idx, column: column, defaultAlign: defaultAlign })); }))),
|
|
8680
|
+
React__default.createElement(TableBody, { style: { paddingBottom: footerHeight || 65 } }, items ? (items.length > 0 ? (items.map(function (item, idx) { return (React__default.createElement(StyledBodyRow, { className: classNames(!!showOddColor && 'odd-color', !!showEvenColor && 'even-color'), key: idx, hover: true, sx: onGetBodyRowSx ? onGetBodyRowSx(item, idx) : undefined }, finalColumns.map(function (column, columnIdx) { return (React__default.createElement(TableBodyCell, { key: columnIdx, index: idx, item: item, defaultAlign: defaultAlign, defaultEllipsis: defaultEllipsis, column: column, onClick: onClick })); }))); })) : (React__default.createElement(StyledBodyRow, null,
|
|
8681
|
+
React__default.createElement(TableCell, { colSpan: finalColumns.length }, noData ? (noData) : (React__default.createElement(StyledNoDataDiv, null,
|
|
8674
8682
|
React__default.createElement("div", null,
|
|
8675
8683
|
React__default.createElement(Icon, null, "error")),
|
|
8676
8684
|
React__default.createElement("div", null, "\uAC80\uC0C9\uB41C \uC815\uBCF4\uAC00 \uC5C6\uC2B5\uB2C8\uB2E4."))))))) : undefined),
|
|
@@ -8682,11 +8690,11 @@ styleInject(css_248z);var Table = React__default.forwardRef(function (_a, ref) {
|
|
|
8682
8690
|
backgroundColor: '#fff',
|
|
8683
8691
|
} },
|
|
8684
8692
|
React__default.createElement(TableRow, null,
|
|
8685
|
-
React__default.createElement(TableCell, { colSpan:
|
|
8693
|
+
React__default.createElement(TableCell, { colSpan: finalColumns.length, style: { borderBottom: 0, borderTop: '1px solid rgba(224, 224, 224, 1)' } },
|
|
8686
8694
|
React__default.createElement(Stack, { alignItems: pagingAlign },
|
|
8687
8695
|
React__default.createElement(TablePagination, { className: pagination === null || pagination === void 0 ? void 0 : pagination.className, style: pagination === null || pagination === void 0 ? void 0 : pagination.style, sx: pagination === null || pagination === void 0 ? void 0 : pagination.sx, paging: paging, align: pagingAlign, onChange: onPageChange })))))),
|
|
8688
8696
|
footer && (React__default.createElement(TableFooter, null,
|
|
8689
|
-
React__default.createElement(TableRow, null,
|
|
8697
|
+
React__default.createElement(TableRow, null, finalColumns.map(function (column, idx) { return (React__default.createElement(TableFooterCell, { key: idx, column: column, defaultAlign: defaultAlign })); })))))))) : null;
|
|
8690
8698
|
});
|
|
8691
8699
|
Table.displayName = 'Table';
|
|
8692
8700
|
Table.defaultProps = TableDefaultProps;var SearchTableDefaultProps = {};var SearchTable = React__default.forwardRef(function (_a, ref) {
|