Repository navigation
ApiDoc: add a layout switch and optionally enable side bar - #98
Merged
Merged
Conversation
Scalar's classic layout never updates the URL hash for individual
operations, so there is no way to link to an endpoint; the modern
layout does. Let readers pick between the two:
- New `layoutSwitch` prop renders a Modern / Classic switch in the top
right corner and remembers the choice in localStorage (key
`dracor.apiDocLayout`, configurable via `storageKey`).
`configuration.layout` is the starting layout. Switching remounts
Scalar rather than reconfiguring the live instance.
- `layoutSwitch.configurations` takes per-layout configuration merged
on top of `configuration` (`customCss` is appended), e.g.
`{ modern: { showSidebar: true } }` -- on wide screens the modern
layout only offers search inside the sidebar.
- Below Scalar's `lg` breakpoint the modern layout's sticky header is
kept clear of the switch: the search button is capped at the classic
width, a sidebar breadcrumb is truncated, and the header gets some
space below its border.
Also disable the "Generate MCP" (`mcp.disabled`) and "Open API Client"
(`hideClientButton`) sidebar buttons by default, and add a
`hidePoweredBy` prop that hides the "Powered by Scalar" link via CSS,
since Scalar has no option for it.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #98 +/- ##
==========================================
- Coverage 95.62% 95.41% -0.21%
==========================================
Files 34 34
Lines 320 349 +29
Branches 109 122 +13
==========================================
+ Hits 306 333 +27
- Misses 3 4 +1
- Partials 11 12 +1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
`layoutSwitch={{ modern: { showSidebar: true } }}` reads better than
nesting the layouts under a `configurations` key. The layout names and
the switch's own options (`storageKey`) don't overlap.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Scalar's classic layout never updates the URL hash for individual operations, so it is not obvious to readers how to link to a specific endpoint. The modern layout does. This PR lets readers switch between the two layouts, and hides Scalar's promotional sidebar buttons.
Layout switch
layoutSwitch(trueor an options object) shows a Modern / Classic switch in the top right corner.dracor.apiDocLayoutby default.storageKeychanges the key.configuration.layoutsets the layout used until the reader picks one.layoutSwitch.modern/layoutSwitch.classicapply extra configuration only while that layout is active. Each is merged on top ofconfiguration, and itscustomCssis added rather than replacing the base CSS.lgbreakpoint, the modern layout shows a sticky header. To keep it clear of the switch:max-w-64);The sidebar is still off by default (
showSidebar: false).Scalar promo buttons
mcp: { disabled: true }andhideClientButton: true. These remove the "Generate MCP" button (shown on localhost) and the "Open API Client" button (shown elsewhere) from the sidebar footer. The per-endpoint "Test Request" buttons have their own option and are not affected.hidePoweredByprop: hides the "Powered by Scalar" link with CSS, since Scalar has no option for it. It is off by default.Notes
.t-doc__header,.darklight-reference). They may need updating when Scalar changes its markup.package.jsonis still on 1.9.0. Since this only adds props, it can go out as 1.10.0.Testing
hidePoweredByCSS. All 16ApiDoctests pass, as dopnpm lintandpnpm build.LayoutSwitchStorybook story./doc/api) with a packed tarball.🤖 Generated with Claude Code