gd-bs
Version:
Bootstrap JavaScript, TypeScript and Web Components library.
50 lines (49 loc) • 1.55 kB
JavaScript
import { ButtonClassNames } from "../button";
import { HTMLAction } from "./templates";
/**
* Card Action
*/
export class CardAction {
// Constructor
constructor(props, parent) {
this._el = null;
this._parent = null;
this._props = null;
// Save the properties
this._parent = parent;
this._props = props;
// Create the item
let elItem = document.createElement("div");
elItem.innerHTML = HTMLAction;
this._el = elItem.firstChild;
// Configure the item
this.configure();
// Configure the events
this.configureEvents();
}
// Configure the action
configure() {
// Set the attributes
this._el.href = this._props.href || this._el.href;
this._el.innerHTML = this._props.text == null ? "" : this._props.text;
// Set the default type
let defaultType = ButtonClassNames.getByType(this._props.buttonType) || "card-link";
this._el.classList.add(defaultType);
}
// Configure the events
configureEvents() {
// See if there is a click event
if (this._props.onClick) {
// Add a click event
this._el.addEventListener("click", ev => {
// Execute the event
this._props.onClick(this._props, this._parent.props, ev);
});
}
}
/**
* Public Interface
*/
// The component HTML element
get el() { return this._el; }
}