From f208224eeebd25101c5568b867d11f31135a1014 Mon Sep 17 00:00:00 2001 From: Legit003 Date: Tue, 28 Jul 2026 17:41:20 +0000 Subject: [PATCH] feat(fwc26): add copy-to-clipboard buttons to SlaCard with success feedback - Implement useCopy hook (src/hooks/useCopy.ts) with: - handleCopy(text) API with async Clipboard API + execCommand fallback - copied boolean (true for 2s after success) for UI feedback - supported boolean to gate copy UI in unsupported environments - Timer restart on rapid re-clicks; cleanup on unmount - Add SlaCard page (src/pages/SlaCard.tsx) at /marketplace/grantfox-wave-compute/sla with: - Per-value copy buttons for all 8 SLA metrics - Green CheckIcon + 'Copied!' label on success - aria-live='polite' region per row for screen-reader announcements - Design-token-only colours; responsive single/two-column layout - WCAG 2.1 AA: focus ring, aria-labels, min touch target size - Register route in App.tsx - Update EmptyState to use new handleCopy API (keeps supported guard) - Add docs/SlaCard-CopyToClipboard.md with API, a11y, and token docs - 91 tests passing (7 useCopy, 22 SlaCard, 62 EmptyState) Closes #545 --- README.md | 2 + docs/SlaCard-CopyToClipboard.md | 148 +++++++++++ src/App.tsx | 5 + src/components/EmptyState.tsx | 7 +- src/hooks/useCopy.ts | 113 ++++++-- src/pages/SlaCard.test.tsx | 356 +++++++++++++++++++++++++ src/pages/SlaCard.tsx | 446 ++++++++++++++++++++++++++++++++ 7 files changed, 1049 insertions(+), 28 deletions(-) create mode 100644 docs/SlaCard-CopyToClipboard.md create mode 100644 src/pages/SlaCard.test.tsx create mode 100644 src/pages/SlaCard.tsx diff --git a/README.md b/README.md index 3899855..47ed680 100644 --- a/README.md +++ b/README.md @@ -26,6 +26,7 @@ Web app for the Callora API marketplace: developer dashboard, API management, an - **Global Command Palette**: Instantly jump to views, search APIs by name, cycle/toggle light & dark themes, or trigger vault deposits. Use `Cmd+K` on macOS or `Ctrl+K` on Windows/Linux to open. - **Pattern-based status badges**: Status indicators now use distinct textures in addition to color so they remain understandable for color-blind users and in grayscale displays. - **Response diff highlighting**: Pass a `compareWith` prop to `CallHistoryRow` to show a line-by-line diff between two call responses, with added (green), removed (red), and unchanged context lines. Includes a Diff/Raw toggle, before/after call labels, and full WCAG 2.1 AA accessibility. See [docs/ResponseDiff.md](docs/ResponseDiff.md). +- **SLA details card**: The GrantFox Wave Compute API SLA page (`/marketplace/grantfox-wave-compute/sla`) displays all SLA metrics with per-value copy-to-clipboard buttons. Each button shows a 2-second "Copied!" success state (green checkmark + label), announces the copy to screen readers via `aria-live`, and falls back to `execCommand` in non-HTTPS contexts. Powered by the reusable `useCopy` hook. See [docs/SlaCard-CopyToClipboard.md](docs/SlaCard-CopyToClipboard.md). - **Smooth theme transition**: Light/dark switches animate color tokens (background, text, border) over 240 ms instead of snapping. The transition is gated behind a `theme-transitions-ready` class that ThemeProvider adds after the first paint, preventing any flash on load. Animated elements (toasts, skeletons, spinners) are automatically excluded. Use the `.no-theme-transition` escape hatch on any element that must opt out. - **Endpoint hover preview**: On the API Detail documentation tab, hovering or focusing an individual endpoint card header reveals a compact floating panel showing the HTTP method badge, endpoint URL, parameter table (name / type / required), and an optional response-shape snippet. Keyboard accessible (Escape dismisses); all colours from design tokens. See `src/components/EndpointPreview.tsx`. @@ -90,6 +91,7 @@ The dashboard includes an accessible usage gauge that summarizes API spend for t | `/theme-playground` | Live theme token playground for designers | | `/500` | Server error page | | `*` | 404 not found | +| `/marketplace/grantfox-wave-compute/sla` | GrantFox Wave Compute API SLA details (FWC26) | ## Project layout diff --git a/docs/SlaCard-CopyToClipboard.md b/docs/SlaCard-CopyToClipboard.md new file mode 100644 index 0000000..ac73abe --- /dev/null +++ b/docs/SlaCard-CopyToClipboard.md @@ -0,0 +1,148 @@ +# SlaCard — Copy-to-Clipboard (Issue #545, FWC26 campaign) + +Added per-value copy-to-clipboard buttons to the GrantFox Wave Compute API SLA +details page, backed by the new `useCopy` hook. + +## Route + +``` +/marketplace/grantfox-wave-compute/sla +``` + +## What was added + +### `src/hooks/useCopy.ts` + +A reusable hook that writes text to the clipboard and drives a transient +"Copied!" feedback state. + +#### API + +```ts +import useCopy from "../hooks/useCopy"; +// or +import { useCopy } from "../hooks/useCopy"; + +const { copied, supported, handleCopy } = useCopy(); +``` + +| Member | Type | Description | +|--------|------|-------------| +| `copied` | `boolean` | `true` for 2 s after a successful copy. Use to swap labels / icons. | +| `supported` | `boolean` | `true` when the clipboard API *or* the `execCommand` fallback is available. Hide copy buttons when `false`. | +| `handleCopy` | `(text: string) => Promise` | Copies `text`; returns `true` on success. | + +#### Behaviour + +- **Clipboard API first**: uses `navigator.clipboard.writeText` when available + (requires HTTPS or `localhost`). +- **`execCommand` fallback**: creates an off-screen `