gd-bs
Version:
Bootstrap JavaScript, TypeScript and Web Components library.
62 lines (61 loc) • 2.03 kB
JavaScript
import { Base } from "../base";
import { appendContent } from "../common";
import { HTML } from "./templates";
/**
* Icon Link Types
*/
export var IconLinkTypes;
(function (IconLinkTypes) {
IconLinkTypes[IconLinkTypes["AfterText"] = 1] = "AfterText";
IconLinkTypes[IconLinkTypes["BeforeText"] = 2] = "BeforeText";
})(IconLinkTypes || (IconLinkTypes = {}));
/**
* Icon Link
* @property props - The list box properties.
*/
class _IconLink extends Base {
// Constructor
constructor(props, template = HTML) {
super(template, props);
this._elIcon = null;
// Configure the list box
this.configure();
// Configure the events
this.configureEvents();
// Configure the parent
this.configureParent();
}
// Configures the list box
configure() {
// Render the content
appendContent(this.el, this.props.content);
// Set the icon if it exists
if (this.props.iconType) {
if (typeof (this.props.iconType) === "function") {
// Set the icon
this._elIcon = this.props.iconType(this.props.iconSize, this.props.iconSize, this.props.iconClassName);
}
// Else, it's an element
else if (typeof (this.props.iconType) === "object") {
// Set the icon
this._elIcon = this.props.iconType;
}
else {
return;
}
// See if we are rendering the content first
if (this.props.type == IconLinkTypes.AfterText) {
// Append the icon
this.el.appendChild(this._elIcon);
}
else {
// Prepend the icon
this.el.prepend(this._elIcon);
}
}
}
// Configures the events
configureEvents() {
}
}
export const IconLink = (props, template) => { return new _IconLink(props, template); };