gd-bs
Version:
Bootstrap JavaScript, TypeScript and Web Components library.
68 lines (67 loc) • 2.2 kB
JavaScript
import { Base } from "../base";
import { ClassNames } from "../classNames";
import { HTML } from "./templates";
/**
* Spinner Types
*/
export var SpinnerTypes;
(function (SpinnerTypes) {
SpinnerTypes[SpinnerTypes["Danger"] = 1] = "Danger";
SpinnerTypes[SpinnerTypes["Dark"] = 2] = "Dark";
SpinnerTypes[SpinnerTypes["Info"] = 3] = "Info";
SpinnerTypes[SpinnerTypes["Light"] = 4] = "Light";
SpinnerTypes[SpinnerTypes["Primary"] = 5] = "Primary";
SpinnerTypes[SpinnerTypes["Secondary"] = 6] = "Secondary";
SpinnerTypes[SpinnerTypes["Success"] = 7] = "Success";
SpinnerTypes[SpinnerTypes["Warning"] = 8] = "Warning";
})(SpinnerTypes || (SpinnerTypes = {}));
/**
* Spinner Class Names
*/
export const SpinnerClassNames = new ClassNames([
"text-danger",
"text-dark",
"text-info",
"text-light",
"text-primary",
"text-secondary",
"text-success",
"text-warning"
]);
/**
* Spinner
* @param props The spinner properties.
*/
class _Spinner extends Base {
// Constructor
constructor(props, template = HTML) {
super(template, props);
// Configure the collapse
this.configure();
// Configure the parent
this.configureParent();
}
// Configure the card group
configure() {
// Set the class name
if (this.props.isGrowing) {
// Set the class
this.el.classList.add("spinner-grow" + (this.props.isSmall ? "-sm" : ""));
}
else {
// Set the class
this.el.classList.add("spinner-border" + (this.props.isSmall ? "-sm" : ""));
}
// Set the class name
this.el.classList.add(SpinnerClassNames.getByType(this.props.type) || SpinnerClassNames.getByType(SpinnerTypes.Primary));
// See if text is defined
if (this.props.text) {
// Update the text
let elSpan = this.el.querySelector("span");
if (elSpan) {
elSpan.innerHTML = this.props.text;
}
}
}
}
export const Spinner = (props, template) => { return new _Spinner(props, template); };