UNPKG

@bigfishtv/cockpit

Version:

63 lines (46 loc) 2.5 kB
'use strict'; exports.__esModule = true; exports.default = undefined; var _class, _temp; var _propTypes = require('prop-types'); var _propTypes2 = _interopRequireDefault(_propTypes); var _react = require('react'); var _react2 = _interopRequireDefault(_react); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } /** * Wraps its children in a breadcrumb identifier, so the breadcrumb train can get updated based on scroll position */ var Breadcrumb = (_temp = _class = function (_Component) { _inherits(Breadcrumb, _Component); function Breadcrumb() { _classCallCheck(this, Breadcrumb); return _possibleConstructorReturn(this, _Component.apply(this, arguments)); } Breadcrumb.prototype.componentDidMount = function componentDidMount() { window.breadcrumbs && window.breadcrumbs.update(); }; Breadcrumb.prototype.componentDidUpdate = function componentDidUpdate(prevProps) { if (prevProps.title !== this.props.title || prevProps.url !== this.props.url) { window.breadcrumbs && window.breadcrumbs.update(); } }; Breadcrumb.prototype.render = function render() { return _react2.default.createElement( 'div', { className: 'breadcrumb', 'data-breadcrumb': this.props.title, 'data-breadcrumb-url': this.props.url }, this.props.children ); }; return Breadcrumb; }(_react.Component), _class.propTypes = { /** Breadcrumb title */ title: _propTypes2.default.string, /** Breacrumb url (if applicable) */ url: _propTypes2.default.string }, _class.defaultProps = { title: 'Section' }, _temp); exports.default = Breadcrumb;