gd-bs
Version:
Bootstrap JavaScript, TypeScript and Web Components library.
97 lines (96 loc) • 4.08 kB
JavaScript
;
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
if (typeof b !== "function" && b !== null)
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.TooltipGroup = void 0;
var base_1 = require("../base");
var tooltip_1 = require("../tooltip");
var templates_1 = require("./templates");
/**
* Tooltip Group
* @property props - The tooltip group properties.
*/
var _TooltipGroup = /** @class */ (function (_super) {
__extends(_TooltipGroup, _super);
// Constructor
function _TooltipGroup(props, template, btnTemplate) {
if (template === void 0) { template = templates_1.HTML; }
var _this = _super.call(this, template, props) || this;
_this._tooltips = null;
// Configure the tooltip group
_this.configure(btnTemplate);
// Configure the parent
_this.configureParent();
return _this;
}
// Configure the tooltip group
_TooltipGroup.prototype.configure = function (btnTemplate) {
// Set the attributes
this.props.id ? this.el.id = this.props.id : null;
this.props.label ? this.el.setAttribute("aria-label", this.props.label) : null;
// Set the class names
this.el.classList.add(this.props.isVertical ? "btn-group-vertical" : "btn-group");
this.props.isLarge ? this.el.classList.add("btn-group-lg") : null;
this.props.isSmall ? this.el.classList.add("btn-group-sm") : null;
// Render the tooltips
this.renderTooltips(btnTemplate);
};
// Render the tooltips
_TooltipGroup.prototype.renderTooltips = function (btnTemplate) {
// Clear the tooltips
this._tooltips = [];
// Parse the tooltips
var tooltips = this.props.tooltips || [];
for (var i = 0; i < tooltips.length; i++) {
// Render the tooltip
this.renderTooltip(tooltips[i], btnTemplate);
}
};
// Renders a tooltip
_TooltipGroup.prototype.renderTooltip = function (props, btnTemplate) {
// Set the properties
props.options = props.options || this.props.tooltipOptions;
props.placement = props.placement || this.props.tooltipPlacement;
props.type = props.type || this.props.tooltipType;
// See if the button props exists
if (props.btnProps) {
// Set the button type
props.btnProps.type = props.btnProps.type || this.props.buttonType;
}
// Create the tooltip
var tooltip = (0, tooltip_1.Tooltip)(props, btnTemplate);
this._tooltips.push(tooltip);
// Append the tooltip to the group
this.el.appendChild(tooltip.el);
};
/**
* Public Interface
*/
// Adds a button to the group
_TooltipGroup.prototype.add = function (props, tooltipTemplate) {
// Render the tooltip
this.renderTooltip(props);
};
Object.defineProperty(_TooltipGroup.prototype, "tooltips", {
// Reference to the tooltips
get: function () { return this._tooltips; },
enumerable: false,
configurable: true
});
return _TooltipGroup;
}(base_1.Base));
var TooltipGroup = function (props, template, tooltipTemplate) { return new _TooltipGroup(props, template, tooltipTemplate); };
exports.TooltipGroup = TooltipGroup;