gd-bs
Version:
Bootstrap JavaScript, TypeScript and Web Components library.
94 lines (93 loc) • 3.59 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.Badge = exports.BadgeClassNames = exports.BadgeTypes = void 0;
var base_1 = require("../base");
var classNames_1 = require("../classNames");
var common_1 = require("../common");
var templates_1 = require("./templates");
/**
* Badge Types
*/
var BadgeTypes;
(function (BadgeTypes) {
BadgeTypes[BadgeTypes["Danger"] = 1] = "Danger";
BadgeTypes[BadgeTypes["Dark"] = 2] = "Dark";
BadgeTypes[BadgeTypes["Info"] = 3] = "Info";
BadgeTypes[BadgeTypes["Light"] = 4] = "Light";
BadgeTypes[BadgeTypes["Primary"] = 5] = "Primary";
BadgeTypes[BadgeTypes["Secondary"] = 6] = "Secondary";
BadgeTypes[BadgeTypes["Success"] = 7] = "Success";
BadgeTypes[BadgeTypes["Warning"] = 8] = "Warning";
})(BadgeTypes = exports.BadgeTypes || (exports.BadgeTypes = {}));
/**
* Badge Class Names
*/
exports.BadgeClassNames = new classNames_1.ClassNames([
"bg-danger",
"bg-dark",
"bg-info",
"bg-light",
"bg-primary",
"bg-secondary",
"bg-success",
"bg-warning"
]);
/**
* Badge
*/
var _Badge = /** @class */ (function (_super) {
__extends(_Badge, _super);
// Constructor
function _Badge(props, template) {
if (template === void 0) { template = props.href || props.onClick ? templates_1.HTMLLink : templates_1.HTMLSpan; }
var _this = _super.call(this, template, props) || this;
// Set the href property
props.href ? _this.el.setAttribute("href", props.href) : null;
// Configure the badge
_this.configure();
// Configure the events
_this.configureEvents();
// Configure the parent element
_this.configureParent();
return _this;
}
// Configure the badge
_Badge.prototype.configure = function () {
// See if this is a pill
if (this.props.isPill) {
// Add the class name
this.el.classList.add("rounded-pill");
}
// Set the default styling
this.el.classList.add(exports.BadgeClassNames.getByType(this.props.type) || exports.BadgeClassNames.getByType(BadgeTypes.Primary));
// Append the content
(0, common_1.appendContent)(this.el, this.props.content);
};
// Configures the events
_Badge.prototype.configureEvents = function () {
var _this = this;
// Set the click event
this.props.onClick ? this.el.addEventListener("click", function (ev) {
// Call the event
_this.props.onClick(_this.props, ev);
}) : null;
};
return _Badge;
}(base_1.Base));
var Badge = function (props, template) { return new _Badge(props, template); };
exports.Badge = Badge;