@dock365/reform-fabric-fields
Version:
fabric fields reform
75 lines • 3.68 kB
JavaScript
"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 __());
};
})();
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
result["default"] = mod;
return result;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
var React = __importStar(require("react"));
var Editor_1 = __importDefault(require("./Editor/Editor"));
var Viewer_1 = __importDefault(require("./Viewer/Viewer"));
var OptionsPickerMenu = /** @class */ (function (_super) {
__extends(OptionsPickerMenu, _super);
function OptionsPickerMenu(props) {
var _this = _super.call(this, props) || this;
_this.state = {
edit: false,
};
_this._onStatusSelect = _this._onStatusSelect.bind(_this);
_this._toggleEdit = _this._toggleEdit.bind(_this);
return _this;
}
OptionsPickerMenu.prototype.componentDidUpdate = function (prevProps) {
if (this.props.activeOptionId && prevProps.activeOptionId !== this.props.activeOptionId ||
prevProps.options.length !== this.props.options.length) {
if (this.props.activeOptionId)
this._setActiveOption(this.props.activeOptionId);
}
};
OptionsPickerMenu.prototype.render = function () {
return (React.createElement("div", null,
React.createElement("div", { style: { backgroundColor: "#fff" } }, this.state.edit ?
React.createElement(Editor_1.default, { availableColors: [], options: this.props.options, onSaveChanges: this.props.onSaveChange, toggleEdit: this._toggleEdit, colors: this.props.colors }) :
React.createElement(Viewer_1.default, { onSelect: this._onStatusSelect, toggleEdit: this._toggleEdit, options: this.props.options, editable: this.props.editable, colors: this.props.colors }))));
};
OptionsPickerMenu.prototype._onStatusSelect = function (e) {
var _this = this;
this._setActiveOption(parseInt(e.currentTarget.value), function () {
if (_this.props.onSelect && _this.state.activeOption)
_this.props.onSelect(_this.state.activeOption);
});
if (this.props.closeCallback) {
this.props.closeCallback();
}
};
OptionsPickerMenu.prototype._setActiveOption = function (id, callback) {
var option = this.props.options.find(function (_option) { return _option.id === id; });
this.setState({ activeOption: option }, callback);
};
OptionsPickerMenu.prototype._toggleEdit = function () {
this.setState(function (prevState) { return ({
edit: !prevState.edit,
}); });
};
return OptionsPickerMenu;
}(React.Component));
exports.default = OptionsPickerMenu;
//# sourceMappingURL=OptionsPickerMenu.js.map