Skip to content

Closes #497 Implemented: feat(docs): add code-sample language selector#566

Open
Promise278 wants to merge 1 commit into
StableRoute-Org:mainfrom
Promise278:feature/docs-01-lang-selector
Open

Closes #497 Implemented: feat(docs): add code-sample language selector#566
Promise278 wants to merge 1 commit into
StableRoute-Org:mainfrom
Promise278:feature/docs-01-lang-selector

Conversation

@Promise278

Copy link
Copy Markdown

Closes #497
Add a per-endpoint language selector (cURL / JavaScript) to the docs page. Each endpoint now shows a code sample with a radio-group toggle, a copy-to-clipboard button, and session-persisted language preference.

  • New CodeSample client component with accessible radiogroup and copy
  • New docLanguage helper for sessionStorage read/write with SSR guards
  • Endpoint metadata extended with multi-language code samples
  • Session-persisted via stableroute.docs.lang sessionStorage key
  • Copy-to-clipboard works per active language
  • Edge cases: single-language endpoints, corrupt stored values

Coverage: 100% statements, branches, functions, lines on new modules. All 863 tests pass, lint clean, build succeeds.

Summary

Add a per-endpoint language selector (cURL / JavaScript) to the docs page with session-persisted preference and copy-to-clipboard.
What changed:

  • New src/components/CodeSample.tsx — Client component with radio-group language toggle, copy button, session persistence via stableroute.docs.lang sessionStorage key
  • New src/lib/docLanguage.ts — SSR-safe sessionStorage read/write helpers with fallback logic
  • src/app/docs/page.tsx — Endpoint metadata extended with multi-language code samples; renders per endpoint
  • src/app/docs/page.test.tsx — Added tests for code samples, radio groups, copy buttons

Key behaviors:

  • Languages: cURL, JavaScript per endpoint
  • Persisted to stableroute.docs.lang in sessionStorage (session-only, not跨-tab)
  • Single-language endpoints show a static label instead of a selector
  • Copy-to-clipboard works per active language with toast feedback
  • Corrupt/missing stored values fall back to cURL

Edge cases covered:

  • Endpoint with one language only (selector hidden)
  • Unknown stored language value (falls back to cURL)
  • Storage quota exceeded / private mode (graceful fallback)
  • Clipboard API unavailable (error toast)

Test results:

  • 863 tests pass, lint clean, build succeeds
  • 100% coverage on CodeSample.tsx and docLanguage.ts

Type Of Change

  • Bug fix
  • Feature
  • Documentation
  • Refactor or maintenance

Add a per-endpoint language selector (cURL / JavaScript) to the docs
page. Each endpoint now shows a code sample with a radio-group toggle,
a copy-to-clipboard button, and session-persisted language preference.

- New CodeSample client component with accessible radiogroup and copy
- New docLanguage helper for sessionStorage read/write with SSR guards
- Endpoint metadata extended with multi-language code samples
- Session-persisted via stableroute.docs.lang sessionStorage key
- Copy-to-clipboard works per active language
- Edge cases: single-language endpoints, corrupt stored values

Coverage: 100% statements, branches, functions, lines on new modules.
All 863 tests pass, lint clean, build succeeds.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add a language selector to the code samples on the docs page

1 participant