@bigfishtv/cockpit
Version:
83 lines (67 loc) • 3.24 kB
JavaScript
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 React, { Component } from 'react';
/**
* Displays breadcrumb trail, hooks into global 'breadcrumbs' class to receive updates based on scroll position
*/
var BreadcrumbTrail = function (_Component) {
_inherits(BreadcrumbTrail, _Component);
function BreadcrumbTrail() {
var _temp, _this, _ret;
_classCallCheck(this, BreadcrumbTrail);
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
return _ret = (_temp = (_this = _possibleConstructorReturn(this, _Component.call.apply(_Component, [this].concat(args))), _this), _this.state = { trail: [] }, _this.focusChange = function (trail) {
_this.setState({ trail: trail });
}, _temp), _possibleConstructorReturn(_this, _ret);
}
BreadcrumbTrail.prototype.componentDidMount = function componentDidMount() {
if (window.breadcrumbs) window.breadcrumbs.addCallback(this.focusChange);else console.error('BreadcrumbsHandler not inited yet!');
};
BreadcrumbTrail.prototype.componentWillUnmount = function componentWillUnmount() {
window.breadcrumbs.removeCallback(this.focusChange);
};
BreadcrumbTrail.prototype.handleAnchorClick = function handleAnchorClick(elem) {
window.breadcrumbs.scrollTo(elem);
};
BreadcrumbTrail.prototype.render = function render() {
var _this2 = this;
return React.createElement(
'nav',
{ className: 'breadcrumbs' },
React.createElement(
'ul',
null,
this.state.trail.map(function (crumb, i) {
return React.createElement(
'li',
{ className: 'crumb', key: 'crumb_' + i },
crumb.url && React.createElement(
'a',
{ href: crumb.url },
crumb.title
),
!crumb.url && React.createElement(
'span',
{ onClick: _this2.handleAnchorClick.bind(_this2, crumb.elem) },
crumb.title
),
i !== _this2.state.trail.length - 1 && React.createElement(
'span',
{ className: 'breadcrumbs-divider' },
React.createElement(
'svg',
{ xmlns: 'http://www.w3.org/2000/svg', width: '18', height: '18', viewBox: '0 0 18 18' },
React.createElement('path', { d: 'M7.5 4.5L6.44 5.56 9.88 9l-3.44 3.44L7.5 13.5 12 9z' })
)
)
);
})
)
);
};
return BreadcrumbTrail;
}(Component);
export { BreadcrumbTrail as default };