UNPKG

gd-bs

Version:

Bootstrap JavaScript, TypeScript and Web Components library.

69 lines (68 loc) 2.6 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.CarouselItem = void 0; var common_1 = require("../common"); var templates_1 = require("./templates"); /** * Carousel Item */ var CarouselItem = /** @class */ (function () { // Constructor function CarouselItem(props, template) { if (template === void 0) { template = templates_1.HTMLItem; } this._el = 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 item CarouselItem.prototype.configure = function () { // Set the class names (0, common_1.setClassNames)(this._el, this._props.className); // Set the attributes this._props.isActive ? this._el.classList.add("active") : null; // Get the image elements var captions = this._el.querySelector(".carousel-caption"); var img = this._el.querySelector("img"); // See if we are rendering an image if (this._props.imageUrl) { // Set the image properties img.alt = this._props.imageAlt == null ? "" : this._props.imageAlt; img.src = this._props.imageUrl == null ? "" : this._props.imageUrl; // Set the captions captions.innerHTML = this._props.captions == null ? "" : this._props.captions; } else { // Remove the elements this._el.removeChild(captions); this._el.removeChild(img); // Append the content (0, common_1.appendContent)(this._el, this._props.content); } // Call the event if it exists this._props.onRendered ? this._props.onRendered(this._el, this._props) : null; }; Object.defineProperty(CarouselItem.prototype, "el", { /** * Public Properties */ // The component HTML element get: function () { return this._el; }, enumerable: false, configurable: true }); Object.defineProperty(CarouselItem.prototype, "isActive", { // Returns true if this slide is active get: function () { return this._el.classList.contains("active"); }, enumerable: false, configurable: true }); return CarouselItem; }()); exports.CarouselItem = CarouselItem;