import { html, type PropertyValues } from "lit"; import { styles } from "./styles.ts"; import { property } from "lit/decorators.js"; import { classMap } from "lit/directives/class-map.js"; import { consume } from "@lit/context"; import { BaseElement } from "../../core/base-element.ts"; import { oneOf } from "../../core/property-guards.ts"; import { applyThemeToElement, type CFTheme, cfThemeContext, type ColorIntent, type ComponentSize, defaultTheme, } from "../theme-context.ts"; /** * CFButton - Interactive button element with multiple variants and sizes * * @element cf-button * * @attr {string} color - Color intent: "neutral" | "primary" | "accent" | "danger" * @attr {string} variant - Visual style variant: "solid" | "outline" | "ghost" * @attr {string} size - Button size: "xs" | "sm" | "md" | "lg" | "xl" | "icon" * @attr {boolean} disabled - Whether the button is disabled * @attr {string} type - Button type: "button" | "submit" | "reset" * * @slot - Default slot for button content * * @example * console.log('Button clicked')}>Click Me */ export type ButtonVariant = "solid" | "outline" | "ghost"; export type ButtonSize = ComponentSize | "icon"; const buttonVariants = ["solid", "outline", "ghost"] as const; const buttonColors = ["neutral", "primary", "accent", "danger"] as const; const buttonSizes = ["xs", "sm", "md", "lg", "xl", "icon"] as const; const buttonTypes = ["button", "submit", "reset"] as const; // ── Accessibility strategy ─────────────────────────────────────────── // // The host carries role="button" so agents can find it via getByRole. // The shadow DOM contains a `; } private _handleClick(e: Event) { if (this.disabled) { e.preventDefault(); e.stopPropagation(); return; } // For submit/reset types, we need to manually find the ancestor cf-form // because the native button in our shadow DOM can't find forms across // shadow DOM boundaries if (this.type === "submit" || this.type === "reset") { const cfForm = this.closest("cf-form") as | (Element & { submit(): void; reset(): void }) | null; if (cfForm) { e.preventDefault(); // Prevent native form lookup (which would fail) if (this.type === "submit") { cfForm.submit(); } else { cfForm.reset(); } } // If no cf-form found, let native behavior try (might work with light DOM forms) return; } } }