Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions app/docs/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -445,3 +445,7 @@ aside[aria-label*="On this page" i] > div:first-child,
}
}

/* Add extra horizontal padding to the first button in response tablist */
div [role="tablist"] button:first-child {
padding-left: 0.5rem !important;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just make sure you really need !important - it causes pain sometimes

}
26 changes: 26 additions & 0 deletions components/api/api-open-body.client.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
"use client";
import { useEffect } from "react";

// automatically open the Body section on OpenAPI pages
export function OpenBodySection() {
useEffect(() => {
const openBodySection = () => {
const buttons = Array.from(document.querySelectorAll("button"));

buttons.forEach((button) => {
if (
button.textContent?.trim().startsWith("Body") &&
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A bit too hacky, can you just add a class/id to the button instead of relying on text?

button.getAttribute("data-state") === "closed"
) {
button.click();
}
});
};

openBodySection();
const timer = setTimeout(openBodySection, 100);
return () => clearTimeout(timer);
}, []);

return null;
}
7 changes: 6 additions & 1 deletion components/api/api-pages.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import metricsApiClient from './metrics-api-page.client';
import pchainApiClient from './pchain-api-page.client';
import cchainApiClient from './cchain-api-page.client';
import xchainApiClient from './xchain-api-page.client';
import { OpenBodySection } from "./api-open-body.client";

const DataAPIPageBase = createAPIPage(dataApi, {
client: dataApiClient,
Expand All @@ -13,6 +14,7 @@ const DataAPIPageBase = createAPIPage(dataApi, {
export function DataAPIPage(props: any) {
return (
<div className="data-api-playground">
<OpenBodySection />
<DataAPIPageBase {...props} />
</div>
);
Expand All @@ -25,6 +27,7 @@ const MetricsAPIPageBase = createAPIPage(metricsApi, {
export function MetricsAPIPage(props: any) {
return (
<div className="metrics-api-playground">
<OpenBodySection />
<MetricsAPIPageBase {...props} />
</div>
);
Expand All @@ -37,6 +40,7 @@ const PChainAPIPageBase = createAPIPage(pChainApi, {
export function PChainAPIPage(props: any) {
return (
<div className="pchain-api-playground">
<OpenBodySection />
<PChainAPIPageBase {...props} />
</div>
);
Expand All @@ -49,6 +53,7 @@ const CChainAPIPageBase = createAPIPage(cChainApi, {
export function CChainAPIPage(props: any) {
return (
<div className="cchain-api-playground">
<OpenBodySection />
<CChainAPIPageBase {...props} />
</div>
);
Expand All @@ -61,8 +66,8 @@ const XChainAPIPageBase = createAPIPage(xChainApi, {
export function XChainAPIPage(props: any) {
return (
<div className="xchain-api-playground">
<OpenBodySection />
<XChainAPIPageBase {...props} />
</div>
);
}