ExtendableContainer.js 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.default = void 0;
  6. var _react = _interopRequireDefault(require("react"));
  7. var _Module2 = _interopRequireDefault(require("../Module"));
  8. var _Container = _interopRequireDefault(require("./Container"));
  9. require("./ExtendableContainer.css");
  10. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  11. function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; var ownKeys = Object.keys(source); if (typeof Object.getOwnPropertySymbols === 'function') { ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) { return Object.getOwnPropertyDescriptor(source, sym).enumerable; })); } ownKeys.forEach(function (key) { _defineProperty(target, key, source[key]); }); } return target; }
  12. 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; }
  13. 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); }
  14. function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
  15. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  16. 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); } }
  17. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  18. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  19. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  20. function _get(target, property, receiver) { if (typeof Reflect !== "undefined" && Reflect.get) { _get = Reflect.get; } else { _get = function _get(target, property, receiver) { var base = _superPropBase(target, property); if (!base) return; var desc = Object.getOwnPropertyDescriptor(base, property); if (desc.get) { return desc.get.call(receiver); } return desc.value; }; } return _get(target, property, receiver || target); }
  21. function _superPropBase(object, property) { while (!Object.prototype.hasOwnProperty.call(object, property)) { object = _getPrototypeOf(object); if (object === null) break; } return object; }
  22. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  23. 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); }
  24. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  25. var ExtendableContainer =
  26. /*#__PURE__*/
  27. function (_Module) {
  28. _inherits(ExtendableContainer, _Module);
  29. function ExtendableContainer(props) {
  30. var _this;
  31. _classCallCheck(this, ExtendableContainer);
  32. _this = _possibleConstructorReturn(this, _getPrototypeOf(ExtendableContainer).call(this, props));
  33. _this.state = {
  34. extended: false
  35. };
  36. return _this;
  37. }
  38. _createClass(ExtendableContainer, [{
  39. key: "toggle",
  40. value: function toggle(e) {
  41. this.setState({
  42. extended: !this.state.extended
  43. });
  44. }
  45. }, {
  46. key: "render",
  47. value: function render() {
  48. var _this2 = this;
  49. var cprops = {};
  50. for (var i in _Container.default.Inputs) {
  51. cprops[i] = this[i].value;
  52. } // console.log(this.props, this.header.value);
  53. return !this.props.inverse ? _react.default.createElement("div", {
  54. key: 'openIt' + this.header.value,
  55. className: "ExtendableContainer ".concat(Object.getPrototypeOf(this) === ExtendableContainer.prototype ? this.props.className : ''),
  56. style: this.props.style
  57. }, _react.default.createElement("div", {
  58. onClick: function onClick() {
  59. return _this2.toggle();
  60. },
  61. className: "ExtendableContainerHeader"
  62. }, this.header.value || 'asd'), _react.default.createElement("div", {
  63. className: "ExtendableContainerContent ".concat(this.state.extended ? 'show' : '')
  64. }, _react.default.createElement(_Container.default, _extends({}, cprops, {
  65. style: {
  66. padding: 3
  67. }
  68. }), this.props.children || '')), _get(_getPrototypeOf(ExtendableContainer.prototype), "render", this).call(this, false)) : _react.default.createElement("div", {
  69. key: 'closeIt' + this.header.value,
  70. className: "ExtendableContainer ".concat(Object.getPrototypeOf(this) === ExtendableContainer.prototype ? this.props.className : ''),
  71. style: this.props.style
  72. }, _react.default.createElement("div", {
  73. className: "ExtendableContainerContent ".concat(this.state.extended ? 'show' : '')
  74. }, _get(_getPrototypeOf(ExtendableContainer.prototype), "render", this).call(this)), _react.default.createElement("div", {
  75. onClick: function onClick() {
  76. return _this2.toggle();
  77. },
  78. className: "ExtendableContainerHeader"
  79. }, this.header.value), _get(_getPrototypeOf(ExtendableContainer.prototype), "render", this).call(this, false));
  80. }
  81. }]);
  82. return ExtendableContainer;
  83. }(_Module2.default);
  84. ExtendableContainer.Inputs = _objectSpread({}, _Container.default.Inputs, {
  85. header: {
  86. type: _Module2.default.Types.Text,
  87. defaultValue: "Header"
  88. }
  89. });
  90. ExtendableContainer.Category = "Basic";
  91. var _default = ExtendableContainer;
  92. exports.default = _default;