mirror of
https://github.com/better-auth/better-auth.git
synced 2026-05-25 08:31:37 -05:00
67 lines
1.8 KiB
TypeScript
67 lines
1.8 KiB
TypeScript
import { useAtom } from "jotai";
|
|
import { js_beautify } from "js-beautify";
|
|
import { useMemo, useState } from "react";
|
|
import { optionsAtom } from "../store";
|
|
import { CodeEditor } from "./code-editor";
|
|
import { resolveNextJSFiles } from "./frameworks/nextjs";
|
|
import { resolveNuxtFiles } from "./frameworks/nuxt";
|
|
import { resolveSvelteKitFiles } from "./frameworks/svelte-kit";
|
|
import { TabBar } from "./tab-bar";
|
|
|
|
export default function CodeTabs({ framework }: { framework: string }) {
|
|
const [options] = useAtom(optionsAtom);
|
|
|
|
const files = useMemo(() => {
|
|
switch (framework) {
|
|
case "nextjs":
|
|
return resolveNextJSFiles(options);
|
|
case "nuxt":
|
|
return resolveNuxtFiles(options);
|
|
case "svelte-kit":
|
|
return resolveSvelteKitFiles(options);
|
|
case "solid-start":
|
|
break;
|
|
}
|
|
|
|
console.error("Invalid framework", framework);
|
|
return [];
|
|
}, [framework, options]);
|
|
|
|
const [activeFileId, setActiveFileId] = useState(files[0].id);
|
|
|
|
const handleTabClick = (fileId: string) => {
|
|
setActiveFileId(fileId);
|
|
};
|
|
|
|
const handleTabClose = (fileId: string) => {
|
|
if (activeFileId === fileId) {
|
|
setActiveFileId(files[0].id);
|
|
}
|
|
};
|
|
|
|
const activeFile = files.find((file) => file.id === activeFileId);
|
|
|
|
return (
|
|
<div className="w-full mr-auto max-w-[60.65rem] mt-8 border border-border rounded-md overflow-hidden">
|
|
<TabBar
|
|
files={files}
|
|
activeFileId={activeFileId}
|
|
onTabClick={handleTabClick}
|
|
onTabClose={handleTabClose}
|
|
/>
|
|
<div className="">
|
|
{activeFile && (
|
|
<CodeEditor
|
|
language={activeFile.name.endsWith(".tsx") ? "tsx" : "typescript"}
|
|
code={
|
|
activeFile.name.endsWith(".ts")
|
|
? js_beautify(activeFile.content)
|
|
: activeFile.content.replace(/\n{3,}/g, "\n\n")
|
|
}
|
|
/>
|
|
)}
|
|
</div>
|
|
</div>
|
|
);
|
|
}
|