@bigfishtv/cockpit
Version:
51 lines (40 loc) • 2.2 kB
JavaScript
var _class, _temp;
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; }
import PropTypes from 'prop-types';
import React, { Component } from 'react';
/**
* 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 React.createElement(
'div',
{ className: 'breadcrumb', 'data-breadcrumb': this.props.title, 'data-breadcrumb-url': this.props.url },
this.props.children
);
};
return Breadcrumb;
}(Component), _class.propTypes = {
/** Breadcrumb title */
title: PropTypes.string,
/** Breacrumb url (if applicable) */
url: PropTypes.string
}, _class.defaultProps = {
title: 'Section'
}, _temp);
export { Breadcrumb as default };