From 34afa659de379fbd5078925f84393f5becf9cfd1 Mon Sep 17 00:00:00 2001
From: Maxwell <145994855+ping-maxwell@users.noreply.github.com>
Date: Sat, 30 Aug 2025 15:35:44 +1000
Subject: [PATCH] docs(api-method): fixed syntax highlighting refreshing on tab
change (#4309)
---
docs/app/docs/[[...slug]]/page.tsx | 10 +--
docs/components/api-method-tabs.tsx | 98 +++++++++++++++++++++++++++++
docs/components/api-method.tsx | 51 ++++++++-------
3 files changed, 131 insertions(+), 28 deletions(-)
create mode 100644 docs/components/api-method-tabs.tsx
diff --git a/docs/app/docs/[[...slug]]/page.tsx b/docs/app/docs/[[...slug]]/page.tsx
index fa6e771d06..6bb97f1fc4 100644
--- a/docs/app/docs/[[...slug]]/page.tsx
+++ b/docs/app/docs/[[...slug]]/page.tsx
@@ -59,7 +59,7 @@ export default async function Page({
>
{page.data.title}
{!avoidLLMHeader.includes(page.data.title) && (
-
+
{props.children}
@@ -85,7 +85,7 @@ export default async function Page({
return (
);
},
@@ -94,9 +94,9 @@ export default async function Page({
},
pre: (props) => {
return (
-
+
diff --git a/docs/components/api-method-tabs.tsx b/docs/components/api-method-tabs.tsx
new file mode 100644
index 0000000000..036bcee7d8
--- /dev/null
+++ b/docs/components/api-method-tabs.tsx
@@ -0,0 +1,98 @@
+"use client";
+
+import * as React from "react";
+
+import { cn } from "@/lib/utils";
+
+const provider = React.createContext<{
+ current: string | null;
+ setCurrent: (value: string | null) => void;
+}>({
+ current: null,
+ setCurrent: () => {},
+});
+
+function ApiMethodTabs({
+ className,
+ ...props
+}: React.ComponentProps<"div"> & { defaultValue: string | null }) {
+ const [current, setCurrent] = React.useState(
+ props.defaultValue || null,
+ );
+ return (
+
+
+
+ );
+}
+
+const useApiMethodTabs = () => {
+ return React.useContext(provider);
+};
+
+function ApiMethodTabsList({
+ className,
+ ...props
+}: React.ComponentProps<"div">) {
+ return (
+
+ );
+}
+
+function ApiMethodTabsTrigger({
+ className,
+ ...props
+}: React.ComponentProps<"button"> & { value: string }) {
+ const { setCurrent, current } = useApiMethodTabs();
+ return (
+
-
-
-
+
@@ -179,8 +184,8 @@ export const APIMethod = ({
Client
-
-
+
@@ -196,20 +201,20 @@ export const APIMethod = ({
/>
Server
-
+
-
-
+
+
{isServerOnly ? null : (
) : null}
-
+
{isServerOnly ? (
-
+
This is a server-only endpoint
) : null}
{!isServerOnly ?
: null}
-
-
+
+
{isClientOnly ? null : (
) : null}
-
+
{serverCodeBlock}
{isClientOnly ? (
-
+
This is a client-only endpoint
) : null}
{!isClientOnly ?
: null}
-
-
+
+
>
);
};
@@ -328,7 +333,7 @@ function TypeTable({
if (!props.length) return null;
return (
-
+
Prop
@@ -354,7 +359,7 @@ function TypeTable({
) : null}
-
+
{tsxifyBackticks(prop.description ?? "")}
@@ -709,8 +714,8 @@ function createServerBody({
function Note({ children }: { children: ReactNode }) {
return (
-
-
+
+
Notes
{children as any}