UNPKG

wix-style-react

Version:
88 lines (73 loc) 3.8 kB
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 { st, classes } from './SidebarHeader.st.css'; import { dataHooks } from './constants'; import Text from '../Text'; import { SidebarContext } from '../Sidebar/SidebarAPI'; import { sidebarSkins } from '../Sidebar/constants'; import Box from '../Box'; /** A header within the sidebar with title, subtitle and custom content at the bottom. */ var SidebarHeader = /*#__PURE__*/function (_React$PureComponent) { _inherits(SidebarHeader, _React$PureComponent); var _super = _createSuper(SidebarHeader); function SidebarHeader() { _classCallCheck(this, SidebarHeader); return _super.apply(this, arguments); } _createClass(SidebarHeader, [{ key: "render", value: function render() { var _this$props = this.props, dataHook = _this$props.dataHook, title = _this$props.title, subtitle = _this$props.subtitle, children = _this$props.children; return /*#__PURE__*/React.createElement(SidebarContext.Consumer, null, function (context) { var skin = context && context.getSkin() || sidebarSkins.dark; return /*#__PURE__*/React.createElement("div", { "data-hook": dataHook, className: st(classes.root, { skin: skin }) }, title && /*#__PURE__*/React.createElement(Box, null, /*#__PURE__*/React.createElement(Text, { dataHook: dataHooks.title, className: classes.title, size: "medium", weight: "bold", ellipsis: true, light: skin === sidebarSkins.dark }, title)), subtitle && /*#__PURE__*/React.createElement(Box, null, /*#__PURE__*/React.createElement(Text, { dataHook: dataHooks.subtitle, className: classes.subtitle, size: "tiny", weight: "thin", ellipsis: true, light: skin === sidebarSkins.dark }, subtitle)), children && /*#__PURE__*/React.createElement("div", { "data-hook": dataHooks.children }, children)); }); } }]); return SidebarHeader; }(React.PureComponent); _defineProperty(SidebarHeader, "displayName", 'SidebarHeader'); _defineProperty(SidebarHeader, "propTypes", { /** Applied as data-hook HTML attribute that can be used in the tests */ dataHook: PropTypes.string, /** A text to show as the header title */ title: PropTypes.string, /** A text to show as the header subtitle */ subtitle: PropTypes.string, /** A custom node to render from the bottom */ children: PropTypes.node }); export default SidebarHeader;