UNPKG

@makeen.io/material-ui-kit

Version:
56 lines 2.84 kB
import _extends from "@babel/runtime/helpers/extends";import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";import React from "react"; import Checkbox from "@material-ui/core/Checkbox"; import BaseMatrix from "../BaseMatrix"; var CheckboxMatrix = function CheckboxMatrix(_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, checkState) { var updateObject = { added: null, modified: null, removed: null, selections: [] }; var recentSelections = _toConsumableArray(selections) || []; if (checkState) { updateObject.added = [rowIndex, colIndex, checkState]; recentSelections.push(updateObject.added); updateObject.selections = recentSelections; } else { for (var i = 0; i < recentSelections.length; i++) { var currentSelection = recentSelections[i]; if (currentSelection[0] === rowIndex && currentSelection[1] === colIndex) { updateObject.removed = _toConsumableArray(currentSelection); recentSelections.splice(i, 1); updateObject.selections = recentSelections; } } } // eslint-disable-next-line @typescript-eslint/tslint/config onSelectionUpdate && onSelectionUpdate(updateObject); }; var renderElement = function renderElement(_ref2) {var rowIndex = _ref2.rowIndex,colIndex = _ref2.colIndex;return /*#__PURE__*/React.createElement(Checkbox, { color: "primary", size: "small", disabled: disabled, checked: isSelected(rowIndex, colIndex), onChange: function onChange(ev) {return handleSelectionUpdate(rowIndex, colIndex, ev.target.checked);} });}; return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/ React.createElement(BaseMatrix, _extends({ matrix: matrix, renderElement: renderElement }, rest))); }; export default CheckboxMatrix; //# sourceMappingURL=index.js.map