UNPKG

@panneau/layout

Version:
113 lines (99 loc) 4.61 kB
import _extends from "@babel/runtime/helpers/extends"; import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties"; 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"; var _excluded = ["urlGenerator", "titleLink", "navbar", "onNavbarClickTitle", "onNavbarClickItem", "gotoHome", "gotoLink", "gotoRoute"]; 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, { Component } from 'react'; import PropTypes from 'prop-types'; import isObject from 'lodash/isObject'; import { PropTypes as PanneauPropTypes, withUrlGenerator } from '@panneau/core'; import Navbar from './Navbar'; var styles = { "container": "panneau-layout-header-container", "navbar": "panneau-layout-header-navbar" }; var propTypes = { urlGenerator: PanneauPropTypes.urlGenerator, title: PropTypes.string, titleLink: PropTypes.string, navbar: PropTypes.oneOfType([PropTypes.bool, PropTypes.object]), gotoHome: PropTypes.func.isRequired, gotoLink: PropTypes.func.isRequired, gotoRoute: PropTypes.func.isRequired, onNavbarClickTitle: PropTypes.func, onNavbarClickItem: PropTypes.func }; var defaultProps = { urlGenerator: null, title: 'Panneau', titleLink: '/', navbar: true, onNavbarClickTitle: null, onNavbarClickItem: null }; var Header = /*#__PURE__*/function (_Component) { _inherits(Header, _Component); var _super = _createSuper(Header); function Header(props) { var _this; _classCallCheck(this, Header); _this = _super.call(this, props); _this.onNavbarClickTitle = _this.onNavbarClickTitle.bind(_assertThisInitialized(_this)); _this.onNavbarClickItem = _this.onNavbarClickItem.bind(_assertThisInitialized(_this)); return _this; } _createClass(Header, [{ key: "onNavbarClickTitle", value: function onNavbarClickTitle() { var onNavbarClickTitle = this.props.onNavbarClickTitle; if (onNavbarClickTitle !== null) { onNavbarClickTitle.apply(void 0, arguments); } } }, { key: "onNavbarClickItem", value: function onNavbarClickItem() { var onNavbarClickItem = this.props.onNavbarClickItem; if (onNavbarClickItem !== null) { onNavbarClickItem.apply(void 0, arguments); } } }, { key: "render", value: function render() { var _this$props = this.props, urlGenerator = _this$props.urlGenerator, titleLink = _this$props.titleLink, navbar = _this$props.navbar, onNavbarClickTitle = _this$props.onNavbarClickTitle, onNavbarClickItem = _this$props.onNavbarClickItem, gotoHome = _this$props.gotoHome, gotoLink = _this$props.gotoLink, gotoRoute = _this$props.gotoRoute, props = _objectWithoutProperties(_this$props, _excluded); return /*#__PURE__*/React.createElement("div", { className: styles.container }, navbar !== false ? /*#__PURE__*/React.createElement("div", { className: styles.navbar }, /*#__PURE__*/React.createElement(Navbar, _extends({ titleLink: urlGenerator !== null ? urlGenerator.route('home') : titleLink }, props, isObject(navbar) ? navbar : null, { gotoHome: gotoHome, gotoLink: gotoLink, gotoRoute: gotoRoute, onClickTitle: this.onNavbarClickTitle, onClickItem: this.onNavbarClickItem }))) : null); } }]); return Header; }(Component); Header.propTypes = propTypes; Header.defaultProps = defaultProps; export default withUrlGenerator()(Header);