wix-style-react
Version:
wix-style-react
103 lines (85 loc) • 4.13 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 _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; }
/* eslint-disable */
var ExampleControlledMouse = function (_React$Component) {
_inherits(ExampleControlledMouse, _React$Component);
function ExampleControlledMouse(props) {
_classCallCheck(this, ExampleControlledMouse);
var _this = _possibleConstructorReturn(this, (ExampleControlledMouse.__proto__ || Object.getPrototypeOf(ExampleControlledMouse)).call(this, props));
_this.state = {
open: false
};
_this._open = _this._open.bind(_this);
_this._close = _this._close.bind(_this);
_this._onKeyDown = _this._onKeyDown.bind(_this);
return _this;
}
_createClass(ExampleControlledMouse, [{
key: '_open',
value: function _open() {
this.setState({ open: true });
}
}, {
key: '_close',
value: function _close() {
this.setState({ open: false });
}
}, {
key: '_onKeyDown',
value: function _onKeyDown(e, delegateKeyDown) {
var eventWasHandled = delegateKeyDown(e);
// We'll open the list when pressing the Enter key
if (!eventWasHandled && e.key === 'Enter') {
this._open();
e.preventDefault();
return;
}
// Close on escape
if (e.key === 'Escape') {
this._close();
e.preventDefault();
}
}
}, {
key: 'render',
value: function render() {
var _this2 = this;
var open = this.state.open;
return React.createElement(
DropdownBase,
{
'data-hook': 'story-dropdown-base-controlled-mouse',
showArrow: true,
open: open,
onMouseEnter: this._open,
onMouseLeave: this._close,
onSelect: this._close,
options: [{ id: 0, value: 'First option' }, { id: 1, value: 'Second option' }, { id: 2, value: 'Third option' }, { id: 3, value: 'Fourth option' }, { id: 4, value: 'Fifth option' }, { id: 5, value: 'Sixth option' }]
},
function (_ref) {
var delegateKeyDown = _ref.delegateKeyDown,
_ref$selectedOption = _ref.selectedOption,
selectedOption = _ref$selectedOption === undefined ? {} : _ref$selectedOption;
return React.createElement(
Button,
{
upgrade: true,
onKeyDown: function onKeyDown(e) {
return _this2._onKeyDown(e, delegateKeyDown);
}
},
selectedOption.value || 'Nothing is selected'
);
}
);
}
}]);
return ExampleControlledMouse;
}(React.Component);
render(React.createElement(
'div',
{ style: { textAlign: 'center' } },
React.createElement(ExampleControlledMouse, null)
));