wix-style-react
Version:
99 lines (83 loc) • 4.4 kB
JavaScript
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
import _createClass from "@babel/runtime/helpers/createClass";
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 ChevronLeft from 'wix-ui-icons-common/ChevronLeft';
import Text from '../Text';
import { st, classes } from './SidebarBackButton.st.css';
import { SidebarContext } from '../Sidebar/SidebarAPI';
import { sidebarSkins } from '../Sidebar/constants';
import { withFocusable } from "wix-ui-core/dist/es/src/hocs/Focusable";
import { FontUpgradeContext } from '../FontUpgrade/context';
import { WixStyleReactContext } from '../WixStyleReactProvider/context';
/** button with an animated back arrow */
var SidebarBackButton = /*#__PURE__*/function (_React$PureComponent) {
_inherits(SidebarBackButton, _React$PureComponent);
var _super = _createSuper(SidebarBackButton);
function SidebarBackButton() {
_classCallCheck(this, SidebarBackButton);
return _super.apply(this, arguments);
}
_createClass(SidebarBackButton, [{
key: "render",
value: function render() {
var _this$props = this.props,
children = _this$props.children,
animateArrow = _this$props.animateArrow,
onClick = _this$props.onClick,
dataHook = _this$props.dataHook,
className = _this$props.className,
focusableOnFocus = _this$props.focusableOnFocus,
focusableOnBlur = _this$props.focusableOnBlur;
return /*#__PURE__*/React.createElement(WixStyleReactContext.Consumer, null, function () {
return /*#__PURE__*/React.createElement(SidebarContext.Consumer, null, function (context) {
var skin = context && context.getSkin() || sidebarSkins.dark;
return /*#__PURE__*/React.createElement("button", {
className: st(classes.root, {
skin: skin
}, className),
"data-hook": dataHook,
onClick: onClick,
onFocus: focusableOnFocus,
onBlur: focusableOnBlur,
type: "button",
tabIndex: "0"
}, /*#__PURE__*/React.createElement(ChevronLeft, {
className: st(classes.arrow, {
animated: animateArrow
})
}), /*#__PURE__*/React.createElement(FontUpgradeContext.Consumer, null, function (_ref) {
var isMadefor = _ref.active;
return /*#__PURE__*/React.createElement(Text, {
weight: isMadefor ? 'normal' : 'bold',
size: "small",
secondary: skin === sidebarSkins.light,
light: skin === sidebarSkins.dark
}, children);
}));
});
});
}
}]);
return SidebarBackButton;
}(React.PureComponent);
_defineProperty(SidebarBackButton, "displayName", 'SidebarBackButton');
_defineProperty(SidebarBackButton, "propTypes", {
/** Applied as data-hook HTML attribute that can be used to create driver in testing */
dataHook: PropTypes.string,
/** A css class to be applied to the component's root element */
className: PropTypes.string,
/** click event handler */
onClick: PropTypes.func,
/** Text for the button */
children: PropTypes.string,
/** Whether or not to constantly animate the arrow */
animateArrow: PropTypes.bool
});
export default withFocusable(SidebarBackButton);