mui-component
Version:
some custom mui components
128 lines • 8.12 kB
JavaScript
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
import { useCreation, useSafeState } from "ahooks";
import { Collapse, TableCell, TableRow } from "@mui/material";
import { createReactComponent } from "./tabler";
import { Cell } from "./Cell";
import { jsx as _jsx } from "react/jsx-runtime";
import { jsxs as _jsxs } from "react/jsx-runtime";
import { Fragment as _Fragment } from "react/jsx-runtime";
var OpenIcon = createReactComponent("outline", "square-plus", "IconSquarePlus", [["path", {
d: "M3 3m0 2a2 2 0 0 1 2 -2h14a2 2 0 0 1 2 2v14a2 2 0 0 1 -2 2h-14a2 2 0 0 1 -2 -2z",
key: "svg-0"
}], ["path", {
d: "M9 12l6 0",
key: "svg-1"
}], ["path", {
d: "M12 9l0 6",
key: "svg-2"
}]]);
var CloseIcon = createReactComponent("outline", "square-minus", "IconSquarePlus", [["path", {
d: "M3 3m0 2a2 2 0 0 1 2 -2h14a2 2 0 0 1 2 2v14a2 2 0 0 1 -2 2h-14a2 2 0 0 1 -2 -2z",
key: "svg-0"
}], ["path", {
d: "M9 12l6 0",
key: "svg-1"
}]]);
export var Row = function Row(props) {
var _expandIcon$, _expandIcon$2;
var columns = props.columns,
rowIndex = props.rowIndex,
hideHeader = props.hideHeader,
row = props.row,
showExpandColumn = props.showExpandColumn,
expandRowByClick = props.expandRowByClick,
expandColumnWidth = props.expandColumnWidth,
expandRowRender = props.expandRowRender,
expandable = props.expandable,
isExpandable = props.isExpandable,
expandIcon = props.expandIcon,
bordered = props.bordered,
unmountOnExit = props.unmountOnExit,
columnDefaultWidth = props.columnDefaultWidth;
var _useSafeState = useSafeState(false),
_useSafeState2 = _slicedToArray(_useSafeState, 2),
open = _useSafeState2[0],
setOpen = _useSafeState2[1];
var colSpans = useCreation(function () {
var _columns$length;
var cols = (_columns$length = columns === null || columns === void 0 ? void 0 : columns.length) !== null && _columns$length !== void 0 ? _columns$length : 0;
if (showExpandColumn) {
cols += 1;
}
return cols;
}, [columns === null || columns === void 0 ? void 0 : columns.length, showExpandColumn]);
return /*#__PURE__*/_jsxs(_Fragment, {
children: [/*#__PURE__*/_jsxs(TableRow, {
children: [expandable && showExpandColumn && /*#__PURE__*/_jsx(TableCell, {
align: "center",
width: rowIndex === -1 || rowIndex === 0 && hideHeader ? expandColumnWidth : undefined,
sx: bordered ? rowIndex === -1 || rowIndex === 0 && hideHeader ? {
borderTop: "1px solid rgba(224,224,224,1)",
borderLeft: "1px solid rgba(224,224,224,1)",
borderRight: "1px solid rgba(224,224,224,1)",
maxWidth: expandColumnWidth
} : {
borderLeft: "1px solid rgba(224,224,224,1)",
borderRight: "1px solid rgba(224,224,224,1)",
maxWidth: expandColumnWidth
} : undefined,
children: rowIndex > -1 && !!isExpandable && /*#__PURE__*/_jsx("span", {
onClick: function onClick() {
return setOpen(function (s) {
return !s;
});
},
style: {
cursor: "pointer"
},
children: open ? (_expandIcon$ = expandIcon === null || expandIcon === void 0 ? void 0 : expandIcon[0]) !== null && _expandIcon$ !== void 0 ? _expandIcon$ : /*#__PURE__*/_jsx(CloseIcon, {
size: "1.25rem"
}) : (_expandIcon$2 = expandIcon === null || expandIcon === void 0 ? void 0 : expandIcon[1]) !== null && _expandIcon$2 !== void 0 ? _expandIcon$2 : /*#__PURE__*/_jsx(OpenIcon, {
size: "1.25rem"
})
})
}), columns === null || columns === void 0 ? void 0 : columns.map(function (item, index) {
var _item$field;
return /*#__PURE__*/_jsx(Cell, _objectSpread({
row: row,
rowIndex: rowIndex,
hideHeader: hideHeader,
bordered: bordered,
expandRowByClick: isExpandable && expandRowByClick,
setOpen: setOpen,
expandIcon: expandIcon,
columnDefaultWidth: columnDefaultWidth
}, item), (_item$field = item === null || item === void 0 ? void 0 : item.field) !== null && _item$field !== void 0 ? _item$field : index);
})]
}), isExpandable && rowIndex > -1 && open && /*#__PURE__*/_jsx(TableRow, {
children: /*#__PURE__*/_jsx(TableCell, {
colSpan: colSpans,
sx: {
py: 0
},
style: bordered ? {
borderLeft: "1px solid rgba(224,224,224,1)",
borderRight: "1px solid rgba(224,224,224,1)"
} : undefined,
children: /*#__PURE__*/_jsx(Collapse, {
in: open,
timeout: "auto",
unmountOnExit: unmountOnExit,
children: expandRowRender === null || expandRowRender === void 0 ? void 0 : expandRowRender(row, rowIndex, open)
})
})
})]
});
};
Row.displayName = "iimm.Mui.SimpleTable.Row";