const { FlexLayout } = require("../common/utils"); const { getAnimations } = require("../getStyles"); class Card { constructor({ width = 100, height = 100, colors = {}, title = "", titlePrefixIcon, }) { this.width = width; this.height = height; this.hideBorder = false; this.hideTitle = false; // returns theme based colors with proper overrides and defaults this.colors = colors; this.title = title; this.css = ""; this.paddingX = 25; this.paddingY = 35; this.titlePrefixIcon = titlePrefixIcon; this.animations = true; } disableAnimations() { this.animations = false; } setCSS(value) { this.css = value; } setHideBorder(value) { this.hideBorder = value; } setHideTitle(value) { this.hideTitle = value; if (value) { this.height -= 30; } } setTitle(text) { this.title = text; } renderTitle() { const titleText = ` ${this.title} `; const prefixIcon = ` ${this.titlePrefixIcon} `; return ` ${FlexLayout({ items: [this.titlePrefixIcon && prefixIcon, titleText], gap: 25, }).join("")} `; } renderGradient() { if (typeof this.colors.bgColor !== "object") return; const gradients = this.colors.bgColor.slice(1); return typeof this.colors.bgColor === "object" ? ` ${gradients.map((grad, index) => { let offset = (index * 100) / (gradients.length - 1); return ``; })} ` : ""; } render(body) { return ` ${this.renderGradient()} ${this.hideTitle ? "" : this.renderTitle()} ${body} `; } } module.exports = Card;