UNPKG

wix-style-react

Version:
71 lines (57 loc) 3.06 kB
import _classCallCheck from "@babel/runtime/helpers/classCallCheck"; import _createClass from "@babel/runtime/helpers/createClass"; import _assertThisInitialized from "@babel/runtime/helpers/assertThisInitialized"; import _inherits from "@babel/runtime/helpers/inherits"; import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn"; import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf"; import _defineProperty from "@babel/runtime/helpers/defineProperty"; function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; } function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } import React, { PureComponent } from 'react'; import { SidebarContext, SidebarItemContext } from '../SidebarAPI'; export var SidebarItem = /*#__PURE__*/function (_PureComponent) { _inherits(SidebarItem, _PureComponent); var _super = _createSuper(SidebarItem); function SidebarItem() { var _this; _classCallCheck(this, SidebarItem); for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { args[_key] = arguments[_key]; } _this = _super.call.apply(_super, [this].concat(args)); _defineProperty(_assertThisInitialized(_this), "displayName", 'SidebarItem'); return _this; } _createClass(SidebarItem, [{ key: "render", value: function render() { var _this2 = this; var dataHook = this.props.dataHook; return /*#__PURE__*/React.createElement(SidebarContext.Consumer, null, function (context) { return /*#__PURE__*/React.createElement("div", { "data-hook": dataHook, onClick: function onClick(e) { if (!_this2.props.disable) { if (_this2.props.onClick) { _this2.props.onClick(_this2.props.itemKey, e); } if (!e.defaultPrevented) { context.itemClicked(_this2.props.itemKey); } } } }, /*#__PURE__*/React.createElement(SidebarItemContext.Provider, { value: { selected: function selected() { return context.getSelectedKey() === _this2.props.itemKey; }, getIsMenuExpanded: function getIsMenuExpanded() { return context.getIsMenuExpanded(); } } }, _this2.props.children)); }); } }]); return SidebarItem; }(PureComponent);