@pdg/react-table 1.0.11 → 1.0.13

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.
@@ -55,6 +55,7 @@ export interface TableProps<T = TableItem> extends CommonSxProps {
55
55
  height?: string | number;
56
56
  maxHeight?: string | number;
57
57
  minHeight?: string | number;
58
+ fullHeight?: boolean;
58
59
  showOddColor?: boolean;
59
60
  showEvenColor?: boolean;
60
61
  cellPadding?: string | number;
package/dist/index.esm.js CHANGED
@@ -8558,9 +8558,11 @@ var templateObject_1;var StyledBodyRow = styled(TableRow)(function (_a) {
8558
8558
  });
8559
8559
  });
8560
8560
  var TableBodyRow = function (_a) {
8561
- var style = _a.style,
8561
+ var className = _a.className, style = _a.style,
8562
8562
  //--------------------------------------------------------------------------------------------------------------------
8563
- id = _a.id, index = _a.index, defaultAlign = _a.defaultAlign, defaultEllipsis = _a.defaultEllipsis, sortable = _a.sortable, columns = _a.columns, item = _a.item, onClick = _a.onClick, props = __rest$1(_a, ["style", "id", "index", "defaultAlign", "defaultEllipsis", "sortable", "columns", "item", "onClick"]);
8563
+ id = _a.id, index = _a.index, defaultAlign = _a.defaultAlign, defaultEllipsis = _a.defaultEllipsis, sortable = _a.sortable, columns = _a.columns, item = _a.item, onClick = _a.onClick,
8564
+ // -------------------------------------------------------------------------------------------------------------------
8565
+ props = __rest$1(_a, ["className", "style", "id", "index", "defaultAlign", "defaultEllipsis", "sortable", "columns", "item", "onClick"]);
8564
8566
  var _b = useSortable({ id: id }), attributes = _b.attributes, listeners = _b.listeners, setNodeRef = _b.setNodeRef, transform = _b.transform, transition = _b.transition;
8565
8567
  var finalStyle = useMemo(function () {
8566
8568
  return sortable
@@ -8570,7 +8572,7 @@ var TableBodyRow = function (_a) {
8570
8572
  return sortable
8571
8573
  ? __assign$1(__assign$1({ ref: setNodeRef }, attributes), listeners) : {};
8572
8574
  }, [attributes, listeners, setNodeRef, sortable]);
8573
- return (React__default.createElement(StyledBodyRow, __assign$1({ style: finalStyle }, props, sortableProps), columns.map(function (column, columnIdx) { return (React__default.createElement(TableBodyCell, { key: columnIdx, index: index, item: item, defaultAlign: defaultAlign, defaultEllipsis: defaultEllipsis, column: column, onClick: onClick })); })));
8575
+ return (React__default.createElement(StyledBodyRow, __assign$1({ className: classNames('TableBodyRow', className), style: finalStyle }, props, sortableProps), columns.map(function (column, columnIdx) { return (React__default.createElement(TableBodyCell, { key: columnIdx, index: index, item: item, defaultAlign: defaultAlign, defaultEllipsis: defaultEllipsis, column: column, onClick: onClick })); })));
8574
8576
  };
8575
8577
  TableBodyRow.displayName = 'TableBodyRow';
8576
8578
  TableBodyRow.defaultProps = TableBodyRowDefaultProps;var TableHeadCell = function (_a) {
@@ -8600,7 +8602,7 @@ TableBodyRow.defaultProps = TableBodyRowDefaultProps;var TableHeadCell = functio
8600
8602
  };var TablePagination = function (_a) {
8601
8603
  var className = _a.className, style = _a.style, sx = _a.sx, paging = _a.paging, align = _a.align, onChange = _a.onChange;
8602
8604
  return (React__default.createElement(Stack, { alignItems: align },
8603
- React__default.createElement(Pagination, { count: paging.last_page, page: paging.current_page, color: 'primary', className: className, style: style, sx: sx, onChange: function (e, page) {
8605
+ React__default.createElement(Pagination, { count: paging.last_page, page: paging.current_page, color: 'primary', className: classNames('TablePagination', className), style: style, sx: sx, onChange: function (e, page) {
8604
8606
  if (onChange)
8605
8607
  onChange(page);
8606
8608
  } })));
@@ -8697,7 +8699,9 @@ styleInject(css_248z);function columnFilter(v) {
8697
8699
  }
8698
8700
  var Table = React__default.forwardRef(function (_a, ref) {
8699
8701
  // sortable --------------------------------------------------------------------------------------------------------
8700
- 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, sortable = _a.sortable, onClick = _a.onClick, onGetBodyRowSx = _a.onGetBodyRowSx, onPageChange = _a.onPageChange, onSortChange = _a.onSortChange;
8702
+ 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, fullHeight = _a.fullHeight, showOddColor = _a.showOddColor, showEvenColor = _a.showEvenColor, cellPadding = _a.cellPadding, footer = _a.footer, noData = _a.noData, pagination = _a.pagination, sortable = _a.sortable, onClick = _a.onClick, onGetBodyRowSx = _a.onGetBodyRowSx, onPageChange = _a.onPageChange, onSortChange = _a.onSortChange,
8703
+ // ---------------------------------------------------------------------------------------------------------------
8704
+ className = _a.className, initStyle = _a.style, sx = _a.sx;
8701
8705
  var sensors = useSensors(useSensor(MouseSensor, {
8702
8706
  // Require the mouse to move by 10 pixels before activating
8703
8707
  activationConstraint: {
@@ -8712,26 +8716,40 @@ var Table = React__default.forwardRef(function (_a, ref) {
8712
8716
  }), useSensor(KeyboardSensor, {
8713
8717
  coordinateGetter: sortableKeyboardCoordinates,
8714
8718
  }));
8719
+ // State - containerHeight -------------------------------------------------------------------------------------------
8720
+ var _b = useState(), containerHeight = _b[0], setContainerHeight = _b[1];
8721
+ var containerHeightDetector = useResizeDetector({
8722
+ handleHeight: true,
8723
+ handleWidth: false,
8724
+ onResize: function () {
8725
+ if (containerHeightDetector.current) {
8726
+ setContainerHeight(containerHeightDetector.current.getBoundingClientRect().height);
8727
+ }
8728
+ else {
8729
+ setContainerHeight(undefined);
8730
+ }
8731
+ },
8732
+ }).ref;
8715
8733
  // State - footerHeight --------------------------------------------------------------------------------------------
8716
- var _b = useState(), footerHeight = _b[0], setFooterHeight = _b[1];
8717
- var footerHeightResizeDetector = useResizeDetector({
8734
+ var _c = useState(), pagingHeight = _c[0], setPagingHeight = _c[1];
8735
+ var pagingHeightResizeDetector = useResizeDetector({
8718
8736
  handleHeight: true,
8719
8737
  handleWidth: false,
8720
8738
  onResize: function () {
8721
- if (footerHeightResizeDetector.current) {
8722
- setFooterHeight(footerHeightResizeDetector.current.getBoundingClientRect().height);
8739
+ if (pagingHeightResizeDetector.current) {
8740
+ setPagingHeight(pagingHeightResizeDetector.current.getBoundingClientRect().height);
8723
8741
  }
8724
8742
  else {
8725
- setFooterHeight(undefined);
8743
+ setPagingHeight(undefined);
8726
8744
  }
8727
8745
  },
8728
8746
  }).ref;
8729
8747
  // State -----------------------------------------------------------------------------------------------------------
8730
- var _c = useAutoUpdateLayoutState(initColumns), columns = _c[0], setColumns = _c[1];
8731
- var _d = useState(), finalColumns = _d[0], setFinalColumns = _d[1];
8732
- var _e = useAutoUpdateLayoutState(initItems), items = _e[0], setItems = _e[1];
8733
- var _f = useState(), sortableItems = _f[0], setSortableItems = _f[1];
8734
- var _g = useAutoUpdateLayoutState(initPaging), paging = _g[0], setPaging = _g[1];
8748
+ var _d = useAutoUpdateLayoutState(initColumns), columns = _d[0], setColumns = _d[1];
8749
+ var _e = useState(), finalColumns = _e[0], setFinalColumns = _e[1];
8750
+ var _f = useAutoUpdateLayoutState(initItems), items = _f[0], setItems = _f[1];
8751
+ var _g = useState(), sortableItems = _g[0], setSortableItems = _g[1];
8752
+ var _h = useAutoUpdateLayoutState(initPaging), paging = _h[0], setPaging = _h[1];
8735
8753
  // Memo --------------------------------------------------------------------------------------------------------------
8736
8754
  var tableSx = useMemo(function () {
8737
8755
  var sx = {
@@ -8822,38 +8840,63 @@ var Table = React__default.forwardRef(function (_a, ref) {
8822
8840
  });
8823
8841
  }
8824
8842
  }, [onSortChange]);
8843
+ // Memo --------------------------------------------------------------------------------------------------------------
8844
+ var style = useMemo(function () {
8845
+ if (fullHeight) {
8846
+ return __assign$1(__assign$1({ width: '100%' }, initStyle), { flex: 1, justifyContent: 'flex-end', height: '100%', display: 'flex', flexDirection: 'column', position: 'relative' });
8847
+ }
8848
+ else {
8849
+ return __assign$1({ width: '100%' }, initStyle);
8850
+ }
8851
+ }, [initStyle, fullHeight]);
8852
+ var simpleBarStyle = useMemo(function () {
8853
+ if (fullHeight) {
8854
+ return {
8855
+ height: (containerHeight || 0) - (pagingHeight || 0),
8856
+ flex: 1,
8857
+ position: 'absolute',
8858
+ left: 0,
8859
+ right: 0,
8860
+ marginBottom: pagingHeight,
8861
+ };
8862
+ }
8863
+ else {
8864
+ return { height: height, minHeight: minHeight, maxHeight: maxHeight };
8865
+ }
8866
+ }, [containerHeight, fullHeight, height, maxHeight, minHeight, pagingHeight]);
8867
+ var pagingStyle = useMemo(function () {
8868
+ if (fullHeight) {
8869
+ return { position: 'sticky', padding: '13px 0' };
8870
+ }
8871
+ else {
8872
+ return { padding: '13px 0' };
8873
+ }
8874
+ }, [fullHeight]);
8825
8875
  // Render ----------------------------------------------------------------------------------------------------------
8826
- return finalColumns ? (React__default.createElement(Paper, { className: 'ReactMuiTable', variant: 'outlined', style: { width: '100%' } },
8827
- React__default.createElement(SimpleBar, { style: { height: height, minHeight: minHeight, maxHeight: maxHeight } },
8876
+ return finalColumns ? (React__default.createElement(Paper, { ref: fullHeight ? containerHeightDetector : undefined, className: classNames('Table', className), variant: 'outlined', style: style, sx: sx },
8877
+ React__default.createElement(SimpleBar, { style: simpleBarStyle },
8828
8878
  React__default.createElement(DndContext, { sensors: sensors, collisionDetection: closestCenter, onDragEnd: handleDragEnd },
8829
8879
  React__default.createElement(Table$1, { stickyHeader: stickyHeader, sx: tableSx },
8830
8880
  React__default.createElement(TableHead, null,
8831
8881
  React__default.createElement(TableRow, null, finalColumns.map(function (column, idx) { return (React__default.createElement(TableHeadCell, { key: idx, column: column, defaultAlign: defaultAlign })); }))),
8832
- React__default.createElement(TableBody, { style: { paddingBottom: footerHeight || 65 } }, sortableItems ? (sortableItems.length > 0 ? (React__default.createElement(SortableContext, { items: sortableItems, strategy: verticalListSortingStrategy }, sortableItems.map(function (item, idx) { return (React__default.createElement(TableBodyRow, { key: item.id, className: classNames(!!showOddColor && 'odd-color', !!showEvenColor && 'even-color'), hover: true, sx: onGetBodyRowSx ? onGetBodyRowSx(item, idx) : undefined, id: item.id, index: idx, defaultAlign: defaultAlign, defaultEllipsis: defaultEllipsis, sortable: sortable, columns: finalColumns, item: item, onClick: onClick })); }))) : (React__default.createElement(StyledBodyRow$1, null,
8882
+ React__default.createElement(TableBody, null, sortableItems ? (sortableItems.length > 0 ? (React__default.createElement(SortableContext, { items: sortableItems, strategy: verticalListSortingStrategy }, sortableItems.map(function (item, idx) { return (React__default.createElement(TableBodyRow, { key: item.id, className: classNames(!!showOddColor && 'odd-color', !!showEvenColor && 'even-color'), hover: true, sx: onGetBodyRowSx ? onGetBodyRowSx(item, idx) : undefined, id: item.id, index: idx, defaultAlign: defaultAlign, defaultEllipsis: defaultEllipsis, sortable: sortable, columns: finalColumns, item: item, onClick: onClick })); }))) : (React__default.createElement(StyledBodyRow$1, null,
8833
8883
  React__default.createElement(TableCell, { colSpan: finalColumns.length }, noData ? (noData) : (React__default.createElement(StyledNoDataDiv, null,
8834
8884
  React__default.createElement("div", null,
8835
8885
  React__default.createElement(Icon, null, "error")),
8836
8886
  React__default.createElement("div", null, "\uAC80\uC0C9\uB41C \uC815\uBCF4\uAC00 \uC5C6\uC2B5\uB2C8\uB2E4."))))))) : undefined),
8837
- paging && (React__default.createElement(TableFooter, { ref: footerHeightResizeDetector, sx: {
8838
- left: 0,
8839
- bottom: 0,
8840
- zIndex: 2,
8841
- position: 'sticky',
8842
- backgroundColor: '#fff',
8843
- } },
8844
- React__default.createElement(TableRow, null,
8845
- React__default.createElement(TableCell, { colSpan: finalColumns.length, style: { borderBottom: 0, borderTop: '1px solid rgba(224, 224, 224, 1)' } },
8846
- React__default.createElement(Stack, { alignItems: pagingAlign },
8847
- 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 })))))),
8848
8887
  footer && (React__default.createElement(TableFooter, null,
8849
- React__default.createElement(TableRow, null, finalColumns.map(function (column, idx) { return (React__default.createElement(TableFooterCell, { key: idx, column: column, defaultAlign: defaultAlign })); }))))))))) : null;
8888
+ React__default.createElement(TableRow, null, finalColumns.map(function (column, idx) { return (React__default.createElement(TableFooterCell, { key: idx, column: column, defaultAlign: defaultAlign })); }))))))),
8889
+ paging && (React__default.createElement(Stack, { ref: fullHeight ? pagingHeightResizeDetector : undefined, alignItems: pagingAlign, style: pagingStyle },
8890
+ 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 }))))) : null;
8850
8891
  });
8851
8892
  Table.displayName = 'Table';
8852
8893
  Table.defaultProps = TableDefaultProps;var SearchTableDefaultProps = {};var SearchTable = React__default.forwardRef(function (_a, ref) {
8853
- var hash = _a.hash, search = _a.search, table = _a.table, betweenSearchTableComponent = _a.betweenSearchTableComponent, onGetData = _a.onGetData, onRequestHashChange = _a.onRequestHashChange;
8894
+ var color = _a.color, hash = _a.hash, search = _a.search, table = _a.table, betweenSearchTableComponent = _a.betweenSearchTableComponent, onGetData = _a.onGetData, onRequestHashChange = _a.onRequestHashChange,
8895
+ // ---------------------------------------------------------------------------------------------------------------
8896
+ className = _a.className, style = _a.style, sx = _a.sx;
8854
8897
  var searchRef = useRef();
8855
8898
  var tableRef = useRef();
8856
- //--------------------------------------------------------------------------------------------------------------------
8899
+ //------------------------------------------------------------------------------------------------------------------
8857
8900
  var getSearchInfo = useCallback(function (search) {
8858
8901
  var searchInfo = {};
8859
8902
  if (search) {
@@ -9132,9 +9175,9 @@ Table.defaultProps = TableDefaultProps;var SearchTableDefaultProps = {};var Sear
9132
9175
  }
9133
9176
  }, [searchRef, hash, hashChange, getData, isFirstSearchSubmit]);
9134
9177
  //------------------------------------------------------------------------------------------------------------------
9135
- return (React__default.createElement(Grid, { container: true, direction: 'column', spacing: 1 },
9178
+ return (React__default.createElement(Grid, { container: true, direction: 'column', spacing: 1, className: classNames('SearchTable', className), style: style, sx: sx },
9136
9179
  React__default.createElement(Grid, { item: true, sx: { display: searchInfo.searchGroups ? undefined : 'none' } },
9137
- React__default.createElement(Search, __assign$1({}, searchInfo.props, { ref: function (commands) {
9180
+ React__default.createElement(Search, __assign$1({ color: color }, searchInfo.props, { ref: function (commands) {
9138
9181
  if (searchInfo.ref) {
9139
9182
  if (typeof searchInfo.ref === 'function') {
9140
9183
  searchInfo.ref(commands);