@gooddata/react-components
Version:
GoodData.UI - A powerful JavaScript library for building analytical applications
66 lines • 3.72 kB
JavaScript
;
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-2020 GoodData Corporation
var React = require("react");
var react_intl_1 = require("react-intl");
var set = require("lodash/set");
var Dropdown_1 = require("@gooddata/goodstrap/lib/Dropdown/Dropdown");
var DisabledBubbleMessage_1 = require("../DisabledBubbleMessage");
var translations_1 = require("../../utils/translations");
var alignPoints = ["bl tl", "tl bl", "br tr", "tr br"];
exports.DROPDOWN_ALIGMENTS = alignPoints.map(function (align) { return ({ align: align, offset: { x: 1, y: 0 } }); });
var DropdownControl = /** @class */ (function (_super) {
__extends(DropdownControl, _super);
function DropdownControl(props) {
var _this = _super.call(this, props) || this;
_this.onSelect = _this.onSelect.bind(_this);
return _this;
}
DropdownControl.prototype.render = function () {
var _a = this.props, disabled = _a.disabled, labelText = _a.labelText, value = _a.value, width = _a.width, items = _a.items, showDisabledMessage = _a.showDisabledMessage, intl = _a.intl;
var selectedItem = this.getSelectedItem(value) || {};
return (React.createElement(DisabledBubbleMessage_1.default, { showDisabledMessage: showDisabledMessage },
React.createElement("div", { className: "adi-properties-dropdown-container" },
React.createElement("span", { className: "input-label-text" }, translations_1.getTranslation(labelText, intl)),
React.createElement("label", { className: "adi-bucket-inputfield gd-input gd-input-small" },
React.createElement(Dropdown_1.default, { disabled: disabled, button: this.getDropdownButton(selectedItem), closeOnParentScroll: true, closeOnMouseDrag: true, alignPoints: exports.DROPDOWN_ALIGMENTS, body: React.createElement(Dropdown_1.DropdownBody, { width: width, items: items, onSelect: this.onSelect, selection: selectedItem }), className: "adi-bucket-dropdown" })))));
};
DropdownControl.prototype.getDropdownButton = function (selectedItem) {
var icon = selectedItem.icon, title = selectedItem.title;
return React.createElement(Dropdown_1.DropdownButton, { value: title, iconLeft: icon });
};
DropdownControl.prototype.onSelect = function (selectedItem) {
var _a = this.props, valuePath = _a.valuePath, properties = _a.properties, pushData = _a.pushData;
var newProperties = set(properties, "controls." + valuePath, selectedItem.value);
pushData({ properties: newProperties });
};
DropdownControl.prototype.getSelectedItem = function (value) {
if (this.props.items) {
return this.props.items.find(function (item) { return item.value === value; });
}
return undefined;
};
DropdownControl.defaultProps = {
value: "",
items: [],
disabled: false,
width: 117,
showDisabledMessage: false,
};
return DropdownControl;
}(React.PureComponent));
exports.default = react_intl_1.injectIntl(DropdownControl);
//# sourceMappingURL=DropdownControl.js.map