stack/docs-mintlify/snippets/sdk-type-components.jsx
Madison 13fccd32b6
Some checks failed
all-good: Did all the other checks pass? / all-good (push) Has been cancelled
Ensure Prisma migrations are in sync with the schema / check_prisma_migrations (22.x) (push) Has been cancelled
DB migration compat / Check if migrations changed (push) Has been cancelled
Docker Server Build and Push / Docker Build and Push Server (push) Has been cancelled
Docker Server Build and Run / docker (push) Has been cancelled
Runs E2E API Tests (Local Emulator) / E2E Tests (Local Emulator, Node ${{ matrix.node-version }}) (22.x) (push) Has been cancelled
Runs E2E API Tests / E2E Tests (Node ${{ matrix.node-version }}, Freestyle ${{ matrix.freestyle-mode }}) (mock, 22.x) (push) Has been cancelled
Runs E2E API Tests / E2E Tests (Node ${{ matrix.node-version }}, Freestyle ${{ matrix.freestyle-mode }}) (prod, 22.x) (push) Has been cancelled
Runs E2E API Tests with custom port prefix / build (22.x) (push) Has been cancelled
Lint & build / lint_and_build (latest) (push) Has been cancelled
Dev Environment Test With Custom Base Port / restart-dev-and-test-with-custom-base-port (push) Has been cancelled
Dev Environment Test / restart-dev-and-test (push) Has been cancelled
Run setup tests with custom base port / setup-tests-with-custom-base-port (push) Has been cancelled
Run setup tests / setup-tests (push) Has been cancelled
TOC Generator / TOC Generator (push) Has been cancelled
DB migration compat / Back-compat — Current branch migrations with ${{ needs.check-migrations-changed.outputs.base_branch }} branch code (push) Has been cancelled
DB migration compat / Forward-compat — Current branch code with ${{ needs.check-migrations-changed.outputs.base_branch }} branch migrations (push) Has been cancelled
DB migration compat / No migration changes (skipped) (push) Has been cancelled
Add docs-mintlify to root
2026-04-01 14:58:41 -05:00

171 lines
5.3 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

export const ClickableTableOfContents = ({ title, code }) => {
const lines = String(code ?? "").replace(/\r\n/g, "\n").split("\n");
return (
<div className="not-prose my-6 overflow-hidden rounded-2xl border border-zinc-950/10 bg-zinc-950/[0.03] dark:border-white/10 dark:bg-white/[0.03]">
{title ? (
<div className="border-b border-zinc-950/10 px-4 py-3 text-sm font-medium text-zinc-950/80 dark:border-white/10 dark:text-white/80">
{title}
</div>
) : null}
<pre className="overflow-x-auto px-2 py-3 text-[13px] leading-6 text-zinc-900 dark:text-zinc-100">
<code>
{lines.map((line, index) => {
if (line.trim().startsWith("// NEXT_LINE_PLATFORM")) {
return null;
}
const match = line.match(/^(.*?)(?:\s*\/\/\s*\$stack-link-to:(#[a-zA-Z0-9_-]+))\s*$/);
const href = match?.[2] ?? null;
const text = match?.[1] ?? line;
if (text.trim() === "") {
return <span key={`blank-${index}`} className="block h-6" />;
}
const content = (
<span className="block whitespace-pre rounded-lg px-3 py-0.5">
{text.replace(/\s+$/, "")}
</span>
);
if (!href) {
return (
<span
key={`line-${index}`}
className="block text-zinc-700 dark:text-zinc-300"
>
{content}
</span>
);
}
return (
<a
key={`line-${index}`}
href={href}
className="block no-underline transition-colors hover:bg-zinc-950/[0.04] hover:text-zinc-950 dark:hover:bg-white/[0.05] dark:hover:text-white"
>
{content}
</a>
);
})}
</code>
</pre>
</div>
);
};
export const CollapsibleTypesSection = ({
type,
property,
signature,
defaultOpen = false,
badge,
children,
}) => {
const id = `${String(type ?? "")
.toLowerCase()
.replace(/[^a-z0-9]/g, "")}${String(property ?? "")
.toLowerCase()
.replace(/[^a-z0-9]/g, "")}`;
const [isOpen, setIsOpen] = useState(defaultOpen);
useEffect(() => {
if (typeof window === "undefined") {
return undefined;
}
const syncWithHash = () => {
if (window.location.hash === `#${id}`) {
setIsOpen(true);
}
};
syncWithHash();
window.addEventListener("hashchange", syncWithHash);
return () => window.removeEventListener("hashchange", syncWithHash);
}, [id]);
const label = signature ? `${property}(${signature})` : property;
const fullLabel = type ? `${type}.${label}` : label;
return (
<details
id={id}
open={isOpen}
onToggle={(event) => setIsOpen(event.currentTarget.open)}
className="not-prose my-4 scroll-mt-24 overflow-hidden rounded-2xl border border-zinc-950/10 bg-white dark:border-white/10 dark:bg-zinc-950"
>
<summary className="cursor-pointer list-none px-4 py-4 [&::-webkit-details-marker]:hidden">
<div className="flex items-center gap-3">
<code className="text-[15px] font-medium text-zinc-950 dark:text-white">{fullLabel}</code>
<span className="ml-auto flex items-center gap-2">
{badge ?? null}
<span
aria-hidden="true"
className="text-sm text-zinc-500 transition-transform dark:text-zinc-400"
>
{isOpen ? "▾" : ""}
</span>
</span>
</div>
</summary>
<div className="border-t border-zinc-950/10 px-4 py-5 dark:border-white/10">
{children}
</div>
</details>
);
};
export const MethodLayout = ({ children }) => (
<div className="grid gap-4 md:grid-cols-2 md:items-start xl:gap-6">
{children}
</div>
);
export const MethodContent = ({ children }) => (
<div className="min-w-0 space-y-4">{children}</div>
);
export const MethodAside = ({ title, children }) => (
<div className="min-w-0 self-start space-y-4 rounded-2xl border border-zinc-950/10 bg-zinc-950/[0.02] p-4 dark:border-white/10 dark:bg-white/[0.03]">
{title ? (
<p className="m-0 text-sm font-medium text-zinc-950 dark:text-white">{title}</p>
) : null}
<div className="space-y-4">{children}</div>
</div>
);
export const AsideSection = ({ title, children }) => (
<div className="space-y-3">
{title ? (
<p className="m-0 text-sm font-medium text-zinc-950 dark:text-white">{title}</p>
) : null}
<div className="space-y-3">{children}</div>
</div>
);
export const ContentSection = ({ title, children }) => (
<div className="space-y-3">
{title ? (
<p className="m-0 text-sm font-medium text-zinc-950 dark:text-white">{title}</p>
) : null}
<div className="space-y-3">{children}</div>
</div>
);
export const MethodReturns = ({ type, children }) => (
<ContentSection title="Returns">
<code className="inline-flex rounded-md border border-zinc-950/10 bg-zinc-950/[0.04] px-2 py-0.5 text-[13px] font-medium text-zinc-950 dark:border-white/10 dark:bg-white/[0.08] dark:text-white">
{type}
</code>
{children ? (
<div className="text-sm leading-6 text-zinc-700 dark:text-zinc-300">{children}</div>
) : null}
</ContentSection>
);