@makeen.io/material-ui-kit
Version:
Makeen UI components kit. Based on material-ui.
56 lines • 2.78 kB
JavaScript
import _extends from "@babel/runtime/helpers/extends";import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";import React, { Fragment } from "react";
import MuiRadio from "@material-ui/core/Radio";
import BaseMatrix from "../BaseMatrix";
export default (function (_ref) {var matrix = _ref.matrix,selections = _ref.selections,onSelectionUpdate = _ref.onSelectionUpdate,disabled = _ref.disabled,rest = _objectWithoutProperties(_ref, ["matrix", "selections", "onSelectionUpdate", "disabled"]);
var isSelected = function isSelected(rowIndex, colIndex) {
var selectStatus = false;
if (selections && selections.length > 0) {
// eslint-disable-next-line @typescript-eslint/prefer-for-of,@typescript-eslint/tslint/config
for (var i = 0; i < selections.length; i++) {
var currentSelection = selections[i];
if (currentSelection[0] === rowIndex &&
currentSelection[1] === colIndex &&
currentSelection[2] === true) {
selectStatus = true;
break;
} else
{
selectStatus = false;
}
}
}
return selectStatus;
};
var handleSelectionUpdate = function handleSelectionUpdate(rowIndex, colIndex) {var param = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
var updateObject = {
added: null,
modified: null,
removed: null,
selections: []
};
updateObject.added = [rowIndex, colIndex, param];
var recentSelections = _toConsumableArray(selections) || [];
if (recentSelections.length > 0) {
recentSelections.forEach(function (currentSelection, selectionIndex) {
if (currentSelection[0] === rowIndex && currentSelection[2] === true) {
updateObject.removed = _toConsumableArray(currentSelection);
recentSelections.splice(selectionIndex, 1);
}
});
}
recentSelections.push(updateObject.added);
updateObject.selections = recentSelections;
if (onSelectionUpdate != null) {
onSelectionUpdate(updateObject);
}
};
var renderElement = function renderElement(_ref2) {var rowIndex = _ref2.rowIndex,colIndex = _ref2.colIndex;
return /*#__PURE__*/React.createElement(MuiRadio, { color: "primary", size: "small", disabled: disabled, checked: isSelected(rowIndex, colIndex), onClick: function onClick(ev) {
// setRadioState(rowIndex, colIndex, true)
handleSelectionUpdate(rowIndex, colIndex, true);
} });
};
return /*#__PURE__*/React.createElement(Fragment, null, /*#__PURE__*/
React.createElement(BaseMatrix, _extends({ matrix: matrix, renderElement: renderElement }, rest)));
});
//# sourceMappingURL=index.js.map