UNPKG

@dock365/reform-fabric-fields

Version:
83 lines 4.49 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 __()); }; })(); 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 Callout_1 = require("office-ui-fabric-react/lib/Callout"); var OptionsPickerMenu_1 = __importDefault(require("./OptionsPickerMenu/OptionsPickerMenu")); var OptionsPicker = /** @class */ (function (_super) { __extends(OptionsPicker, _super); function OptionsPicker(props) { var _this = _super.call(this, props) || this; _this._menuButtonElement = React.createRef(); _this.state = { callout: false, }; _this._onToggleCalloutClick = _this._onToggleCalloutClick.bind(_this); return _this; } OptionsPicker.prototype.render = function () { var _this = this; var options = this.props.options; var activeOption; activeOption = typeof this.props.activeOption === "number" ? options.find(function (option) { return option.id === _this.props.activeOption; }) : this.props.activeOption; return (React.createElement("div", { style: { position: "relative", display: "inline-block", } }, React.createElement("button", { ref: this._menuButtonElement, onClick: this._onToggleCalloutClick, type: "button", disabled: this.props.readOnly, style: { padding: 0, margin: 0, border: "none", backgroundColor: "transparent", verticalAlign: "middle", width: "100%", } }, this.props.children || React.createElement("div", { style: { backgroundColor: activeOption && activeOption.id ? activeOption.color && (this.props.colors[activeOption.color] || activeOption.color) : "#ccc", height: "32px", lineHeight: "31px", border: "none", width: "140px", padding: "0 8px", whiteSpace: "pre", overflow: "hidden", textOverflow: "ellipsis", margin: "0 auto", } }, activeOption && activeOption.title || "")), React.createElement(Callout_1.Callout, { className: "ms-CalloutExample-callout", ariaLabelledBy: 'callout-label-1', ariaDescribedBy: 'callout-description-1', role: 'alertdialog', gapSpace: 0, target: this._menuButtonElement.current, onDismiss: function () { return _this.setState({ callout: false }); }, setInitialFocus: true, hidden: !this.state.callout }, React.createElement(OptionsPickerMenu_1.default, { closeCallback: function () { return _this.setState({ callout: false }); }, activeOptionId: activeOption && activeOption.id, options: options || [], onSelect: this.props.onSelect, onSaveChange: this.props.onSaveChange, editable: this.props.editable, colors: this.props.colors })))); }; OptionsPicker.prototype._onToggleCalloutClick = function (e) { this.setState(function (prevState) { return ({ callout: !prevState.callout }); }); // this.props.onClick(e); }; return OptionsPicker; }(React.Component)); exports.default = OptionsPicker; //# sourceMappingURL=OptionsPicker.js.map