Skip to content

Commit 4fdc348

Browse files
authored
fix: updated tryIt button structure (#2224)
1 parent 97835c5 commit 4fdc348

File tree

5 files changed

+39
-19
lines changed

5 files changed

+39
-19
lines changed

packages/fern-docs/ui/src/api-reference/endpoints/EndpointContentCodeSnippets.tsx

+2-8
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import {
2222
useRef,
2323
} from "react";
2424
import { FernErrorTag } from "../../components/FernErrorBoundary";
25-
import { PlaygroundButton } from "../../playground/PlaygroundButton";
25+
import { PlaygroundButtonTray } from "../../playground/PlaygroundButtonTray";
2626
import { usePlaygroundBaseUrl } from "../../playground/utils/select-environment";
2727
import { AudioExample } from "../examples/AudioExample";
2828
import {
@@ -216,13 +216,7 @@ const UnmemoizedEndpointContentCodeSnippets: React.FC<
216216
</>
217217
) : undefined
218218
}
219-
tryIt={
220-
node != null ? (
221-
<>
222-
<PlaygroundButton state={node} />
223-
</>
224-
) : undefined
225-
}
219+
tryIt={node != null ? <PlaygroundButtonTray state={node} /> : undefined}
226220
code={resolveEnvironmentUrlInCodeSnippet(
227221
endpoint,
228222
requestCodeSnippet,

packages/fern-docs/ui/src/api-reference/examples/TitledExample.tsx

+1-5
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,7 @@ export const TitledExample = forwardRef<
8585
</div>
8686
</div>
8787
{children}
88-
{tryIt ? (
89-
<div className="border-card-border bg-tag-default-soft flex h-10 justify-end border-t p-2">
90-
<div className="flex max-w-[76px] items-center">{tryIt}</div>
91-
</div>
92-
) : undefined}
88+
{tryIt}
9389
</div>
9490
);
9591
});

packages/fern-docs/ui/src/api-reference/web-socket/WebSocket.tsx

+4-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import { WithAside } from "../../contexts/api-page";
2020
import { useHref } from "../../hooks/useHref";
2121
import { Markdown } from "../../mdx/Markdown";
2222
import { PlaygroundButton } from "../../playground/PlaygroundButton";
23+
import { PlaygroundButtonTray } from "../../playground/PlaygroundButtonTray";
2324
import { usePlaygroundBaseUrl } from "../../playground/utils/select-environment";
2425
import { getSlugFromChildren } from "../../util/getSlugFromText";
2526
import { EndpointParameter } from "../endpoints/EndpointParameter";
@@ -375,7 +376,9 @@ const WebhookContent: FC<WebhookContentProps> = ({
375376
<TitledExample
376377
title={"Handshake"}
377378
tryIt={
378-
node != null ? <PlaygroundButton state={node} /> : undefined
379+
node != null ? (
380+
<PlaygroundButtonTray state={node} />
381+
) : undefined
379382
}
380383
disableClipboard={true}
381384
>

packages/fern-docs/ui/src/mdx/components/snippets/EndpointRequestSnippet.tsx

+6-5
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,11 @@ export function EndpointRequestSnippetInternal({
7878
options={endpoint.environments}
7979
/>
8080
}
81+
// add the api reference button here to place correctly
8182
languages={
82-
availableLanguages.length > 1 ? (
83-
<>
83+
<>
84+
{slug != null ? <ApiReferenceButton slug={slug} /> : undefined}
85+
{availableLanguages.length > 1 ? (
8486
<CodeExampleClientDropdown
8587
languages={availableLanguages}
8688
onValueChange={(language) =>
@@ -91,10 +93,9 @@ export function EndpointRequestSnippetInternal({
9193
}
9294
value={selectedExampleKey.language}
9395
/>
94-
</>
95-
) : undefined
96+
) : undefined}
97+
</>
9698
}
97-
tryIt={slug != null ? <ApiReferenceButton slug={slug} /> : undefined}
9899
code={selectedExample.code}
99100
language={selectedExampleKey.language}
100101
json={EMPTY_OBJECT}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import * as FernNavigation from "@fern-api/fdr-sdk/navigation";
2+
import { useAtomValue } from "jotai";
3+
import { FC } from "react";
4+
import { IS_PLAYGROUND_ENABLED_ATOM } from "../atoms";
5+
import { usePlaygroundSettings } from "../hooks/usePlaygroundSettings";
6+
import { PlaygroundButton } from "./PlaygroundButton";
7+
8+
export const PlaygroundButtonTray: FC<{
9+
state: FernNavigation.NavigationNodeApiLeaf;
10+
className?: string;
11+
}> = ({ state, className }) => {
12+
const isPlaygroundEnabled = useAtomValue(IS_PLAYGROUND_ENABLED_ATOM);
13+
const settings = usePlaygroundSettings(state.id ?? state);
14+
15+
if (!isPlaygroundEnabled || settings?.disabled) {
16+
return null;
17+
}
18+
19+
return (
20+
<div className="border-card-border bg-tag-default-soft flex h-10 justify-end border-t p-2">
21+
<div className="flex max-w-[76px] items-center">
22+
<PlaygroundButton state={state} className={className} />
23+
</div>
24+
</div>
25+
);
26+
};

0 commit comments

Comments
 (0)