wix-style-react
Version:
wix-style-react
125 lines (103 loc) • 4.88 kB
JavaScript
var _createClass = 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); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
import React from 'react';
import Tooltip from 'wix-style-react/Tooltip';
import EditableSelector from 'wix-style-react/EditableSelector';
import Button from 'wix-style-react/Button';
var PopoverWithEditableSelector = function (_React$Component) {
_inherits(PopoverWithEditableSelector, _React$Component);
function PopoverWithEditableSelector(props) {
_classCallCheck(this, PopoverWithEditableSelector);
var _this = _possibleConstructorReturn(this, (PopoverWithEditableSelector.__proto__ || Object.getPrototypeOf(PopoverWithEditableSelector)).call(this, props));
_this.onOptionAdded = function (_ref) {
var newTitle = _ref.newTitle;
_this.setState({
options: [].concat(_toConsumableArray(_this.state.options), [{ title: newTitle, isSelected: true }])
});
};
_this.onOptionEdit = function (_ref2) {
var newTitle = _ref2.newTitle,
index = _ref2.index;
_this.setState({
options: _this.state.options.map(function (option, i) {
return index === i ? { title: newTitle } : option;
})
});
};
_this.onOptionToggle = function (index) {
_this.setState({
options: _this.state.options.map(function (option, i) {
if (index === i) {
option.isSelected = !option.isSelected;
return option;
} else {
return option;
}
})
});
};
_this.onOptionDelete = function (_ref3) {
var index = _ref3.index;
_this.setState({
options: _this.state.options.filter(function (option, i) {
return index !== i;
})
});
};
_this.state = {
options: [{ title: 'Marc Banks' }, { title: 'Bernard Park' }, { title: 'Carlos Dunn' }, { title: 'Norman Reeves' }, { title: 'Richard Medina' }]
};
return _this;
}
_createClass(PopoverWithEditableSelector, [{
key: 'render',
value: function render() {
var _this2 = this;
var content = React.createElement(EditableSelector, {
onOptionAdded: function onOptionAdded(params) {
return _this2.onOptionAdded(params);
},
onOptionEdit: function onOptionEdit(params) {
return _this2.onOptionEdit(params);
},
onOptionDelete: function onOptionDelete(params) {
return _this2.onOptionDelete(params);
},
onOptionToggle: function onOptionToggle(params) {
return _this2.onOptionToggle(params);
},
options: this.state.options
});
return React.createElement(
'div',
{
style: {
backgroundColor: '#f0f4f7',
minHeight: '300px',
padding: '20px'
}
},
React.createElement(
Tooltip,
{
textAlign: 'start',
placement: 'bottom',
content: content,
showTrigger: 'click',
hideTrigger: 'click'
},
React.createElement(
Button,
null,
'click me'
)
)
);
}
}]);
return PopoverWithEditableSelector;
}(React.Component);
export default PopoverWithEditableSelector;