UNPKG

cloudhub-react-components

Version:
134 lines (101 loc) 6.49 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var _react = _interopRequireWildcard(require("react")); var _Button = _interopRequireDefault(require("@material-ui/core/Button")); var _CheckBox = _interopRequireDefault(require("@material-ui/icons/CheckBox")); var _green = _interopRequireDefault(require("@material-ui/core/colors/green")); var _CheckBoxOutlineBlank = _interopRequireDefault(require("@material-ui/icons/CheckBoxOutlineBlank")); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } } function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; } function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(source, true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(source).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; } function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); } function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); } function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } var checkbox = /*#__PURE__*/ function (_Component) { _inherits(checkbox, _Component); function checkbox(props) { var _this; _classCallCheck(this, checkbox); _this = _possibleConstructorReturn(this, _getPrototypeOf(checkbox).call(this, props)); _defineProperty(_assertThisInitialized(_this), "onCheck", function () { _this.setState(function (_ref) { var checkvalue = _ref.checkvalue; _this.props.input.onChange(!checkvalue); _this.props.onChange(!checkvalue); return { checkvalue: !checkvalue }; }); }); _this.state = { checkvalue: false }; return _this; } _createClass(checkbox, [{ key: "render", value: function render() { var _this$props = this.props, label = _this$props.label, height = _this$props.height; var checkvalue = this.state.checkvalue; return _react.default.createElement(_Button.default, { onClick: this.onCheck, style: { width: '100%', textTransform: 'none', display: 'flex', justifyContent: 'flex-start', padding: 0 } }, checkvalue ? _react.default.createElement(_CheckBox.default, { style: { height: height, width: height, color: _green.default[500], marginRight: 5 } }) : _react.default.createElement(_CheckBoxOutlineBlank.default, { style: { height: height, width: height, marginRight: 5 } }), label); } }], [{ key: "getDerivedStateFromProps", value: function getDerivedStateFromProps(nextProps, prevState) { var checkvalue = nextProps.input.value || nextProps.value; return _objectSpread({}, prevState, { checkvalue: checkvalue }); } }]); return checkbox; }(_react.Component); _defineProperty(checkbox, "defaultProps", { input: { value: null, onChange: function onChange() {} }, value: null, onChange: function onChange() {}, height: 32 }); var _default = checkbox; exports.default = _default; //# sourceMappingURL=CheckBox.js.map