import { LitElement, TemplateResult, html, nothing } from "lit"; import { customElement, property } from "lit/decorators.js"; import { translateText } from "../../Utils"; type ButtonVariant = "primary" | "secondary" | "danger" | "ghost"; type ButtonSize = "xs" | "sm" | "md" | "lg"; type ButtonWidth = "auto" | "block" | "blockDesktop" | "fill"; type IconPosition = "left" | "right" | "only"; @customElement("o-button") export class OButton extends LitElement { @property() title = ""; @property() translationKey = ""; @property() variant: ButtonVariant = "primary"; @property() size: ButtonSize = "md"; @property() width: ButtonWidth = "auto"; @property() iconPosition: IconPosition = "left"; @property({ attribute: false }) icon?: TemplateResult; @property({ type: Boolean }) disable = false; @property({ type: Boolean }) submit = false; createRenderRoot() { return this; } private readonly BASE = "font-bold uppercase tracking-wider rounded-xl border border-transparent " + "transition-all duration-300 transform hover:-translate-y-px " + "outline-none text-center whitespace-normal break-words leading-tight overflow-hidden relative " + "disabled:cursor-not-allowed disabled:hover:translate-y-0 disabled:opacity-70"; private variantClasses(): string { switch (this.variant) { case "primary": return "bg-malibu-blue hover:bg-aquarius text-white disabled:bg-gray-600 disabled:text-gray-300"; case "secondary": return "bg-gray-700 hover:bg-gray-600 text-white disabled:bg-gray-800 disabled:text-gray-400"; case "danger": return "bg-red-600 hover:bg-red-500 text-white disabled:bg-red-900 disabled:text-gray-300"; case "ghost": return "bg-transparent hover:bg-white/10 text-malibu-blue disabled:text-gray-500 disabled:hover:bg-transparent"; } } private sizeClasses(): string { if (this.iconPosition === "only") { switch (this.size) { case "xs": return "w-6 h-6 text-xs"; case "sm": return "w-8 h-8 text-sm"; case "md": return "w-10 h-10 text-base"; case "lg": return "w-12 h-12 text-lg"; } } switch (this.size) { case "xs": return "py-1 px-2 text-xs"; case "sm": return "py-1.5 px-3 text-sm"; case "md": return "py-3 px-4 text-base lg:text-lg"; case "lg": return "py-4 px-6 text-lg lg:text-xl"; } } private widthClasses(): string { switch (this.width) { case "auto": return "inline-flex items-center justify-center gap-2"; case "block": return "flex w-full items-center justify-center gap-2"; case "blockDesktop": return "flex w-full items-center justify-center gap-2 lg:w-1/2 lg:mx-auto"; case "fill": return "flex w-full h-full items-center justify-center gap-2"; } } render() { const label = this.translationKey === "" ? this.title : translateText(this.translationKey); const iconOnly = this.iconPosition === "only"; const classes = `${this.BASE} ${this.variantClasses()} ${this.sizeClasses()} ${this.widthClasses()}`; return html` `; } }