UNPKG

@gooddata/react-components

Version:

GoodData.UI - A powerful JavaScript library for building analytical applications

71 lines 3.56 kB
"use strict"; var __extends = (this && this.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); Object.defineProperty(exports, "__esModule", { value: true }); // (C) 2019 GoodData Corporation var React = require("react"); var react_intl_1 = require("react-intl"); var noop = require("lodash/noop"); var set = require("lodash/set"); var DisabledBubbleMessage_1 = require("../DisabledBubbleMessage"); var translations_1 = require("../../utils/translations"); var ConfigSubsection = /** @class */ (function (_super) { __extends(ConfigSubsection, _super); function ConfigSubsection(props) { var _this = _super.call(this, props) || this; _this.toggleValue = _this.toggleValue.bind(_this); return _this; } ConfigSubsection.prototype.render = function () { var _a = this.props, title = _a.title, intl = _a.intl; var className = "configuration-subsection " + this.getTestClassName(); return (React.createElement("div", { className: className }, React.createElement("fieldset", null, React.createElement("legend", null, React.createElement("span", { className: "legend-title" }, translations_1.getTranslation(title, intl)), this.renderToggleSwitch()), React.createElement("div", null, this.props.children)))); }; ConfigSubsection.prototype.renderToggleSwitch = function () { if (this.props.canBeToggled) { var _a = this.props, toggledOn = _a.toggledOn, toggleDisabled = _a.toggleDisabled, showDisabledMessage = _a.showDisabledMessage; return (React.createElement(DisabledBubbleMessage_1.default, { className: "input-checkbox-toggle", showDisabledMessage: showDisabledMessage }, React.createElement("label", { className: "s-checkbox-toggle-label" }, React.createElement("input", { type: "checkbox", checked: toggledOn, disabled: toggleDisabled, onChange: this.toggleValue, className: "s-checkbox-toggle" }), React.createElement("span", { className: "input-label-text" })))); } return null; }; ConfigSubsection.prototype.toggleValue = function (event) { var _a = this.props, valuePath = _a.valuePath, properties = _a.properties, pushData = _a.pushData; if (valuePath && properties && pushData) { var newProperties = set(properties, "controls." + valuePath, event.target.checked); pushData({ properties: newProperties }); } }; ConfigSubsection.prototype.getTestClassName = function () { return "s-configuration-subsection-" + this.props.title.replace(/\./g, "-"); }; ConfigSubsection.defaultProps = { collapsed: true, canBeToggled: false, toggleDisabled: false, toggledOn: true, pushData: noop, showDisabledMessage: false, }; return ConfigSubsection; }(React.Component)); exports.default = react_intl_1.injectIntl(ConfigSubsection); //# sourceMappingURL=ConfigSubsection.js.map