gd-bs
Version:
Bootstrap JavaScript, TypeScript and Web Components library.
90 lines (89 loc) • 3.69 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.ButtonGroup = void 0;
var base_1 = require("../base");
var button_1 = require("../button");
var templates_1 = require("./templates");
/**
* Button Group
* @property props - The button group properties.
*/
var _ButtonGroup = /** @class */ (function (_super) {
__extends(_ButtonGroup, _super);
// Constructor
function _ButtonGroup(props, template, btnTemplate) {
if (template === void 0) { template = templates_1.HTML; }
var _this = _super.call(this, template, props) || this;
_this._buttons = null;
// Configure the button group
_this.configure(btnTemplate);
// Configure the parent
_this.configureParent();
return _this;
}
// Configure the button group
_ButtonGroup.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 buttons
this.renderButtons(btnTemplate);
};
// Render the buttons
_ButtonGroup.prototype.renderButtons = function (btnTemplate) {
// Clear the buttons
this._buttons = [];
// Parse the buttons
var buttons = this.props.buttons || [];
for (var i = 0; i < buttons.length; i++) {
// Render the button
this.renderButton(buttons[i], btnTemplate);
}
};
// Renders a button
_ButtonGroup.prototype.renderButton = function (props, template) {
// Set the property
props.type = props.type || this.props.buttonType;
// Create the button
var button = (0, button_1.Button)(props, template);
this._buttons.push(button);
// Append the button to the group
this.el.appendChild(button.el);
};
Object.defineProperty(_ButtonGroup.prototype, "buttons", {
/**
* Public Interface
*/
// Reference to the buttons
get: function () { return this._buttons; },
enumerable: false,
configurable: true
});
// Adds a button to the group
_ButtonGroup.prototype.add = function (props, btnTemplate) {
// Render the button
this.renderButton(props, btnTemplate);
};
return _ButtonGroup;
}(base_1.Base));
var ButtonGroup = function (props, template, btnTemplate) { return new _ButtonGroup(props, template, btnTemplate); };
exports.ButtonGroup = ButtonGroup;