function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); } function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a 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); } } function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } function _possibleConstructorReturn(self, call) { if (call && (typeof call === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); } function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); } function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } import * as React from 'react'; export default function PopupMixin(getModal, platformProps) { var _a; return _a = /*#__PURE__*/ function (_React$Component) { _inherits(_a, _React$Component); function _a(props) { var _this; _classCallCheck(this, _a); _this = _possibleConstructorReturn(this, _getPrototypeOf(_a).call(this, props)); _this.onPickerChange = function (pickerValue) { if (_this.state.pickerValue !== pickerValue) { _this.setState({ pickerValue: pickerValue }); var _this$props = _this.props, picker = _this$props.picker, pickerValueChangeProp = _this$props.pickerValueChangeProp; if (picker && picker.props[pickerValueChangeProp]) { picker.props[pickerValueChangeProp](pickerValue); } } }; _this.saveRef = function (picker) { _this.picker = picker; }; _this.onTriggerClick = function (e) { var child = _this.props.children; var childProps = child.props || {}; if (childProps[_this.props.triggerType]) { childProps[_this.props.triggerType](e); } _this.fireVisibleChange(!_this.state.visible); }; _this.onOk = function () { _this.props.onOk(_this.picker && _this.picker.getValue()); _this.fireVisibleChange(false); }; _this.getContent = function () { if (_this.props.picker) { var _React$cloneElement; var pickerValue = _this.state.pickerValue; if (pickerValue === null) { pickerValue = _this.props.value; } return React.cloneElement(_this.props.picker, (_React$cloneElement = {}, _defineProperty(_React$cloneElement, _this.props.pickerValueProp, pickerValue), _defineProperty(_React$cloneElement, _this.props.pickerValueChangeProp, _this.onPickerChange), _defineProperty(_React$cloneElement, "ref", _this.saveRef), _React$cloneElement)); } else { return _this.props.content; } }; _this.onDismiss = function () { _this.props.onDismiss(); _this.fireVisibleChange(false); }; _this.hide = function () { _this.fireVisibleChange(false); }; _this.state = { pickerValue: 'value' in _this.props ? _this.props.value : null, visible: _this.props.visible || false }; return _this; } _createClass(_a, [{ key: "componentWillReceiveProps", value: function componentWillReceiveProps(nextProps) { if ('value' in nextProps) { this.setState({ pickerValue: nextProps.value }); } if ('visible' in nextProps) { this.setVisibleState(nextProps.visible); } } }, { key: "setVisibleState", value: function setVisibleState(visible) { this.setState({ visible: visible }); if (!visible) { this.setState({ pickerValue: null }); } } }, { key: "fireVisibleChange", value: function fireVisibleChange(visible) { if (this.state.visible !== visible) { if (!('visible' in this.props)) { this.setVisibleState(visible); } this.props.onVisibleChange(visible); } } }, { key: "getRender", value: function getRender() { var props = this.props; var children = props.children; if (!children) { return getModal(props, this.state.visible, { getContent: this.getContent, onOk: this.onOk, hide: this.hide, onDismiss: this.onDismiss }); } var _this$props2 = this.props, WrapComponent = _this$props2.WrapComponent, disabled = _this$props2.disabled; var child = children; var newChildProps = {}; if (!disabled) { newChildProps[props.triggerType] = this.onTriggerClick; } return React.createElement(WrapComponent, { style: props.wrapStyle }, React.cloneElement(child, newChildProps), getModal(props, this.state.visible, { getContent: this.getContent, onOk: this.onOk, hide: this.hide, onDismiss: this.onDismiss })); } }, { key: "render", value: function render() { return this.getRender(); } }]); return _a; }(React.Component), _a.defaultProps = _extends({ onVisibleChange: function onVisibleChange(_) {}, okText: 'Ok', dismissText: 'Dismiss', title: '', onOk: function onOk(_) {}, onDismiss: function onDismiss() {} }, platformProps), _a; }