UNPKG

react-widgetconfigurator

Version:

A React app for to generate out of box widgets

203 lines (181 loc) 7.77 kB
'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); var _createClass = 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); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); var _react = require('react'); var _react2 = _interopRequireDefault(_react); var _reactstrap = require('reactstrap'); var _ColorPicker = require('./ColorPicker'); var _ColorPicker2 = _interopRequireDefault(_ColorPicker); var _ChartTypePicker = require('./ChartTypePicker'); var _ChartTypePicker2 = _interopRequireDefault(_ChartTypePicker); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } var SettingsModal = function (_React$Component) { _inherits(SettingsModal, _React$Component); function SettingsModal(props) { _classCallCheck(this, SettingsModal); var _this = _possibleConstructorReturn(this, (SettingsModal.__proto__ || Object.getPrototypeOf(SettingsModal)).call(this, props)); _this.state = { modal: false, colors: ['#fdb921', '#0033a0', '#7ED321', '#1DB2B8'], charttype: ['bar', 'spline'] }; _this.toggle = _this.toggle.bind(_this); _this.applyParent = _this.applyParent.bind(_this); _this.applyParentDefault = _this.applyParentDefault.bind(_this); // this.callParentSetColor = this.callParentSetColor.bind(this); return _this; } _createClass(SettingsModal, [{ key: 'toggle', value: function toggle() { this.setState({ modal: !this.state.modal }); } }, { key: 'SetColorfromChild', value: function SetColorfromChild(cindex, selectedcolor) { var colors = this.state.colors; colors[cindex] = selectedcolor.hex; this.setState({ colors: colors }); } }, { key: 'SetChartTypefromChild', value: function SetChartTypefromChild(ctindex, selectedcharttype) { var charttype = this.state.charttype; charttype[ctindex] = selectedcharttype; this.setState({ charttype: charttype }); } }, { key: 'applyParent', value: function applyParent() { console.log('apply click', this.props); this.props.ChildSettings(this.state.colors, this.state.charttype); this.setState({ modal: !this.state.modal }); } }, { key: 'applyParentDefault', value: function applyParentDefault() { this.props.ChildSettings(['#fdb921', '#0033a0', '#7ED321', '#1DB2B8'], ['spline', 'bar']); } }, { key: 'render', value: function render() { return _react2.default.createElement( 'div', null, _react2.default.createElement( _reactstrap.Button, { color: 'primary', className: 'btnsettings', onClick: this.toggle }, 'Advanced Settings' ), _react2.default.createElement( _reactstrap.Modal, { isOpen: this.state.modal, toggle: this.toggle, className: this.props.className }, _react2.default.createElement( _reactstrap.ModalHeader, { toggle: this.toggle }, 'Color Settings' ), _react2.default.createElement( _reactstrap.ModalBody, null, _react2.default.createElement( _reactstrap.Container, null, _react2.default.createElement( _reactstrap.Row, null, _react2.default.createElement( _reactstrap.Col, { xs: '6' }, 'Chart option 1' ), _react2.default.createElement( _reactstrap.Col, { xs: '6' }, _react2.default.createElement(_ColorPicker2.default, { color: this.state.colors[0], ParentSetColor: this.SetColorfromChild.bind(this, 0) }) ) ), _react2.default.createElement( _reactstrap.Row, null, _react2.default.createElement( _reactstrap.Col, { xs: '6' }, 'Chart option 2' ), _react2.default.createElement( _reactstrap.Col, { xs: '6' }, _react2.default.createElement(_ColorPicker2.default, { color: this.state.colors[1], ParentSetColor: this.SetColorfromChild.bind(this, 1) }) ) ), _react2.default.createElement( _reactstrap.Row, null, _react2.default.createElement( _reactstrap.Col, { xs: '6' }, 'Chart option 3' ), _react2.default.createElement( _reactstrap.Col, { xs: '6' }, _react2.default.createElement(_ColorPicker2.default, { color: this.state.colors[2], ParentSetColor: this.SetColorfromChild.bind(this, 2) }) ) ), _react2.default.createElement( _reactstrap.Row, null, _react2.default.createElement( _reactstrap.Col, { xs: '6' }, 'Chart option 4' ), _react2.default.createElement( _reactstrap.Col, { xs: '6' }, _react2.default.createElement(_ColorPicker2.default, { color: this.state.colors[3], ParentSetColor: this.SetColorfromChild.bind(this, 3) }) ) ) ) ), _react2.default.createElement( _reactstrap.ModalFooter, null, _react2.default.createElement( _reactstrap.Button, { color: 'primary', onClick: this.applyParent }, 'Apply' ), _react2.default.createElement( _reactstrap.Button, { color: 'secondary', onClick: this.toggle }, 'Cancel' ) ) ), _react2.default.createElement( _reactstrap.Button, { color: 'primary', className: 'btnreset', onClick: this.applyParentDefault }, 'Reset to Default' ) ); } }]); return SettingsModal; }(_react2.default.Component); exports.default = SettingsModal; module.exports = exports['default'];