UNPKG

fumadocs-openapi

Version:

Generate MDX docs for your OpenAPI spec

71 lines (68 loc) 2.52 kB
'use client'; import { cn } from "../../utils/cn.js"; import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "../components/select.js"; import { createContext, use, useMemo, useState } from "react"; import { jsx, jsxs } from "react/jsx-runtime"; import { Check, Copy } from "lucide-react"; import { buttonVariants } from "fumadocs-ui/components/ui/button"; import { useCopyButton } from "fumadocs-ui/utils/use-copy-button"; //#region src/ui/operation/client.tsx function CopyResponseTypeScript({ code }) { const [isChecked, onCopy] = useCopyButton(() => { navigator.clipboard.writeText(code); }); return /* @__PURE__ */ jsxs("div", { className: "flex items-start justify-between gap-2 bg-fd-card text-fd-card-foreground border rounded-xl p-3 not-prose mb-4 last:mb-0", children: [/* @__PURE__ */ jsxs("div", { children: [/* @__PURE__ */ jsx("p", { className: "font-medium text-sm mb-2", children: "TypeScript Definitions" }), /* @__PURE__ */ jsx("p", { className: "text-xs text-fd-muted-foreground", children: "Use the response body type in TypeScript." })] }), /* @__PURE__ */ jsxs("button", { onClick: onCopy, className: cn(buttonVariants({ color: "secondary", className: "p-2 gap-2", size: "sm" })), children: [isChecked ? /* @__PURE__ */ jsx(Check, { className: "size-3.5" }) : /* @__PURE__ */ jsx(Copy, { className: "size-3.5" }), "Copy"] })] }); } const Context = createContext(null); function SelectTabs({ defaultValue, children }) { const [type, setType] = useState(defaultValue ?? null); return /* @__PURE__ */ jsx(Context, { value: useMemo(() => ({ type, setType }), [type]), children }); } function SelectTab({ value, ...props }) { if (value !== use(Context)?.type) return; return /* @__PURE__ */ jsx("div", { ...props, children: props.children }); } function SelectTabTrigger({ items, className, ...props }) { const { type, setType } = use(Context); return /* @__PURE__ */ jsxs(Select, { value: type ?? "", onValueChange: setType, children: [/* @__PURE__ */ jsx(SelectTrigger, { className: cn("not-prose w-fit min-w-0 *:min-w-0", className), ...props, children: /* @__PURE__ */ jsx(SelectValue, {}) }), /* @__PURE__ */ jsx(SelectContent, { children: items.map(({ label, value }) => /* @__PURE__ */ jsx(SelectItem, { value, children: label }, value)) })] }); } //#endregion export { CopyResponseTypeScript, SelectTab, SelectTabTrigger, SelectTabs }; //# sourceMappingURL=client.js.map