wix-style-react
Version:
122 lines (100 loc) • 4.96 kB
JavaScript
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 from 'react';
import PropTypes from 'prop-types';
import { SidebarNextContext } from '../SidebarNext/SidebarNextAPI';
import { st, classes } from './SidebarItemNext.st.css';
import { withFocusable } from "wix-ui-core/dist/es/src/hocs/Focusable";
import { dataHooks } from './constants';
import { sidebarSkins } from '../Sidebar/constants';
import Text from '../Text';
/** An item for the section within the sidebar */
var SidebarItemNext = /*#__PURE__*/function (_React$PureComponent) {
_inherits(SidebarItemNext, _React$PureComponent);
var _super = _createSuper(SidebarItemNext);
function SidebarItemNext() {
var _this;
_classCallCheck(this, SidebarItemNext);
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), "renderSuffix", function () {
var _this$props = _this.props,
suffix = _this$props.suffix,
disabled = _this$props.disabled;
return !disabled && suffix && /*#__PURE__*/React.createElement("span", {
"data-hook": dataHooks.suffix,
className: classes.suffix
}, suffix);
});
return _this;
}
_createClass(SidebarItemNext, [{
key: "render",
value: function render() {
var _this2 = this;
var _this$props2 = this.props,
dataHook = _this$props2.dataHook,
children = _this$props2.children,
disabled = _this$props2.disabled,
onClick = _this$props2.onClick,
className = _this$props2.className,
focusableOnFocus = _this$props2.focusableOnFocus,
focusableOnBlur = _this$props2.focusableOnBlur,
itemKey = _this$props2.itemKey;
return /*#__PURE__*/React.createElement(SidebarNextContext.Consumer, null, function (context) {
var selected = context && context.selectedKey === itemKey;
var skin = context && context.skin;
return /*#__PURE__*/React.createElement("button", {
"data-hook": dataHook,
"data-selected": selected,
"data-skin": skin,
"data-disabled": disabled,
onClick: onClick,
onFocus: focusableOnFocus,
onBlur: focusableOnBlur,
disabled: disabled,
type: "button",
className: st(classes.root, {
selected: selected,
disabled: disabled,
skin: skin
}, className)
}, /*#__PURE__*/React.createElement(Text, {
"data-hook": dataHooks.title,
className: classes.text,
size: "small",
weight: 'normal',
secondary: skin === sidebarSkins.light,
light: skin === sidebarSkins.dark,
skin: disabled && 'disabled'
}, children), _this2.renderSuffix());
});
}
}]);
return SidebarItemNext;
}(React.PureComponent);
_defineProperty(SidebarItemNext, "displayName", 'SidebarItemNext');
_defineProperty(SidebarItemNext, "propTypes", {
/** Applied as data-hook HTML attribute that can be used in the tests */
dataHook: PropTypes.string,
/** A css class to be applied to the component's root element */
className: PropTypes.string,
/** An element to appear at the end of the text */
suffix: PropTypes.node,
/** Indicates whether to display the item as disabled */
disabled: PropTypes.bool,
/** A callback to be triggered on click */
onClick: PropTypes.func,
/** unique identifier per item, used to mark it for navigation and selection */
itemKey: PropTypes.string
});
export default withFocusable(SidebarItemNext);