gd-bs
Version:
Bootstrap JavaScript, TypeScript and Web Components library.
85 lines (84 loc) • 2.99 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.BreadcrumbItem = void 0;
var common_1 = require("../common");
var templates_1 = require("./templates");
/**
* Breadcrumb Item
*/
var BreadcrumbItem = /** @class */ (function () {
// Constructor
function BreadcrumbItem(props, template) {
if (template === void 0) { template = props.href && !props.isActive ? templates_1.HTMLLink : templates_1.HTMLItem; }
this._el = null;
this._elLink = null;
this._props = null;
// Save the properties
this._props = props;
// Create the item
var elItem = document.createElement("div");
elItem.innerHTML = template;
this._el = elItem.firstChild;
// Configure the item
this.configure();
// Configure the events
this.configureEvents();
}
// Configure the item
BreadcrumbItem.prototype.configure = function () {
// Set the class names
(0, common_1.setClassNames)(this._el, this._props.className);
// See if this item is active
if (this._props.isActive) {
// Add the class name
this._el.classList.add("active");
// Set the attribute
this._el.setAttribute("aria-current", "page");
}
// See if a name exists
if (this._props.name) {
// Set the name
this._el.setAttribute("data-name", this._props.name);
}
// See if this is a link
this._elLink = this.el.querySelector("a");
if (this._elLink) {
// Configure the link
this._elLink.href = this._props.href;
this._elLink.innerHTML = this._props.text == null ? "" : this._props.text;
}
else {
// Configure the item
this._el.innerHTML = this._props.text == null ? "" : this._props.text;
}
};
// Configure the events
BreadcrumbItem.prototype.configureEvents = function () {
var _this = this;
// See if there is a click event
if (this._props.onClick) {
// Add the click event
(this._elLink || this._el).addEventListener("click", function (ev) {
// Call the click event
_this._props.onClick(_this._props, ev);
});
}
};
Object.defineProperty(BreadcrumbItem.prototype, "el", {
/**
* Public Properties
*/
// The component HTML element
get: function () { return this._el; },
enumerable: false,
configurable: true
});
Object.defineProperty(BreadcrumbItem.prototype, "props", {
// The componen properties
get: function () { return this._props; },
enumerable: false,
configurable: true
});
return BreadcrumbItem;
}());
exports.BreadcrumbItem = BreadcrumbItem;