carlos / platform Public

console: native controls follow the dark theme (color-scheme); Continue to payment spins for at least 650 ms and can't be pressed twice (progressive enhancement; without JS the form submits as before)

Squashed from console-color-scheme into main.
Paul Campbell pushed by claude agent, operated by paul@keymail.dev 674fec48b7365f38af404c51436d4dba644f30de parent a953623
2 files changed, +48 −2
  • internal/console/templates/billing.html +2 −2
  • internal/console/templates/layout.html +46 −0

CI failed — run details

diff --git a/internal/console/templates/billing.html b/internal/console/templates/billing.html
index 570cdc9ea..8c73923dc 100644
--- a/internal/console/templates/billing.html
+++ b/internal/console/templates/billing.html
@@ -30,7 +30,7 @@
<button type="submit">{{billingText "button.confirm"}}</button>
</form></div>{{end}}
{{if eq . "continue"}}<div class="settings-row"><form method="get" action="{{$.Base}}/billing/continue">
- <button type="submit">{{billingText "button.continue"}}</button>
+ <button type="submit" data-busy>{{billingText "button.continue"}}</button>
</form></div>{{end}}
{{if eq . "start_over"}}<div class="settings-row"><form method="post" action="{{$.Base}}/billing/checkout">
<input type="hidden" name="csrf" value="{{$.CSRF}}">
@@ -95,7 +95,7 @@
</table>
</div>{{end}}
<div class="buy-foot">
- <button type="submit">{{billingText "buy.button"}}</button>
+ <button type="submit" data-busy>{{billingText "buy.button"}}</button>
</div>
</form>
{{end}}{{end}}
diff --git a/internal/console/templates/layout.html b/internal/console/templates/layout.html
index 1043ce9f7..de040377d 100644
--- a/internal/console/templates/layout.html
+++ b/internal/console/templates/layout.html
@@ -5,6 +5,9 @@
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>{{.Title}} ยท {{.Brand}}</title>
<style>
+ /* Native controls (number spinners, checkboxes, selects, scrollbars)
+ follow the theme, so they stay visible on the dark background. */
+ :root { color-scheme: light dark; }
:root {
--bg: #ffffff; --ink: #201d29; --muted: #6f6480;
--accent: #5b3e96; --accent-strong: #4c3380;
@@ -438,6 +441,19 @@
}
button:not(.linkish):hover, .btn:hover { background: var(--accent-strong); }
button.linkish.danger { color: var(--bad); }
+ /* A button marked data-busy shows a spinner once pressed (the script at
+ the end of the page); the label stays for screen readers. */
+ button[aria-busy="true"] { position: relative; color: transparent; cursor: progress; }
+ button[aria-busy="true"]::after {
+ content: ""; position: absolute; inset: 0; margin: auto;
+ width: 1.1em; height: 1.1em; border-radius: 50%;
+ border: 2px solid var(--bg); border-right-color: transparent;
+ animation: busy-spin 0.7s linear infinite;
+ }
+ @keyframes busy-spin { to { transform: rotate(360deg); } }
+ @media (prefers-reduced-motion: reduce) {
+ button[aria-busy="true"]::after { animation-duration: 2.4s; }
+ }
/* Actions that change what serves are BUTTONS, not links โ€” small enough to
sit inside a table row or a ladder rung, unmistakably a button all the
same. Danger is filled red: rollbacks and retirements should not dress
@@ -728,6 +744,36 @@
</main>
<footer>๐Ÿค– Console text written by an LLM, per <a href="https://11factor.org/#x">factor X</a>.</footer>
<script>
+// Enhancement only: a submit button marked data-busy can't be pressed twice
+// and shows a spinner for at least 650 ms before its form goes, so a fast
+// answer doesn't flash. With JS off the form submits as it always has.
+(function () {
+ var minBusy = 650;
+ document.addEventListener("submit", function (e) {
+ var f = e.target, b = e.submitter;
+ if (!b || !b.hasAttribute("data-busy")) return;
+ e.preventDefault();
+ if (f.hasAttribute("data-busy-sent")) return;
+ f.setAttribute("data-busy-sent", "");
+ b.setAttribute("aria-busy", "true");
+ b.disabled = true;
+ setTimeout(function () {
+ if (b.name) {
+ var h = document.createElement("input");
+ h.type = "hidden"; h.name = b.name; h.value = b.value;
+ f.appendChild(h);
+ }
+ f.submit();
+ }, minBusy);
+ });
+ // Coming back with the Back button restores the page from cache with the
+ // button still busy; give it back.
+ window.addEventListener("pageshow", function (e) {
+ if (!e.persisted) return;
+ document.querySelectorAll("form[data-busy-sent]").forEach(function (f) { f.removeAttribute("data-busy-sent"); });
+ document.querySelectorAll("button[aria-busy=true]").forEach(function (b) { b.disabled = false; b.removeAttribute("aria-busy"); });
+ });
+})();
// Enhancement only: <details> already opens, closes and focuses on its own.
// This adds the two behaviours a menu is expected to have and the element
// does not โ€” Escape closes it (returning focus to the trigger), and a click