Mercurial
view design_system/src/components/button.js @ 279:b3b547563ec7
Add Google connector service and agent wiki
Implement the C/Seobeo Google Drive and Gmail connector with encrypted OAuth storage, Zenbu authentication, browser testing, AI tool discovery, chunked HTTP decoding, and Bazel coverage. Consolidate repository guidance into progressive wiki documentation and enforce arena-first allocation for new first-party C code.
Co-authored-by: Copilot <[email protected]>
Copilot-Session: 84c338fd-0939-4bb3-b7f3-1062eb213e5d
| author | MrJuneJune <me@mrjunejune.com> |
|---|---|
| date | Mon, 17 Aug 2026 22:22:36 -0700 |
| parents | 2b6e732087ff |
| children |
line wrap: on
line source
/** * Enhances a native button or link with disabled and loading states. * * @extends {HTMLElement} */ export class ZenButton extends HTMLElement { static get observedAttributes() { return ["disabled", "loading"]; } connectedCallback() { if (!this._blockInteraction) { this._blockInteraction = event => { if (!this.hasAttribute("disabled") && !this.hasAttribute("loading")) return; event.preventDefault(); event.stopImmediatePropagation(); }; } this.addEventListener("click", this._blockInteraction, true); if (!this._observer) { this._observer = new MutationObserver(records => { for (const record of records) { for (const node of record.removedNodes) { if (node instanceof Element && node.matches("button, a")) { this.restoreManagedState(node); } } } this.sync(); }); } this._observer.observe(this, { childList: true }); this.sync(); } disconnectedCallback() { this._observer?.disconnect(); this.removeEventListener("click", this._blockInteraction, true); } attributeChangedCallback() { this.sync(); } sync() { const control = this.querySelector(":scope > button, :scope > a"); if (!control) return; const disabled = this.hasAttribute("disabled") || this.hasAttribute("loading"); if (disabled) { if (control.dataset.zenManagedAriaDisabled !== "true") { control.dataset.zenOriginalAriaDisabled = control.getAttribute("aria-disabled") ?? "__zen_missing__"; control.dataset.zenManagedAriaDisabled = "true"; } control.setAttribute("aria-disabled", "true"); } else { this.restoreDisabledState(control); } if (this.hasAttribute("loading")) { if (control.dataset.zenManagedAriaBusy !== "true") { control.dataset.zenOriginalAriaBusy = control.getAttribute("aria-busy") ?? "__zen_missing__"; control.dataset.zenManagedAriaBusy = "true"; } control.setAttribute("aria-busy", "true"); } else if (control.dataset.zenManagedAriaBusy === "true") { if (control.dataset.zenOriginalAriaBusy === "__zen_missing__") { control.removeAttribute("aria-busy"); } else { control.setAttribute( "aria-busy", control.dataset.zenOriginalAriaBusy, ); } delete control.dataset.zenManagedAriaBusy; delete control.dataset.zenOriginalAriaBusy; } } restoreDisabledState(control) { if (control.dataset.zenManagedAriaDisabled === "true") { if (control.dataset.zenOriginalAriaDisabled === "__zen_missing__") { control.removeAttribute("aria-disabled"); } else { control.setAttribute( "aria-disabled", control.dataset.zenOriginalAriaDisabled, ); } delete control.dataset.zenManagedAriaDisabled; delete control.dataset.zenOriginalAriaDisabled; } } restoreManagedState(control) { this.restoreDisabledState(control); if (control.dataset.zenManagedAriaBusy === "true") { if (control.dataset.zenOriginalAriaBusy === "__zen_missing__") { control.removeAttribute("aria-busy"); } else { control.setAttribute( "aria-busy", control.dataset.zenOriginalAriaBusy, ); } delete control.dataset.zenManagedAriaBusy; delete control.dataset.zenOriginalAriaBusy; } } } if (!customElements.get("zen-button")) { customElements.define("zen-button", ZenButton); }