diff --git a/website/README.md b/website/README.md index a5176b603..825214c15 100644 --- a/website/README.md +++ b/website/README.md @@ -3,7 +3,13 @@ This is a [Next.js](https://nextjs.org) project bootstrapped with ## Getting Started -First, run the development server: +First, install dependencies and populate the `timestamps.json` file: + +``` +pnpm setup +``` + +Then, run the development server: ```bash npm run dev diff --git a/website/mdx-components.tsx b/website/mdx-components.tsx index fac8add8a..368f45087 100644 --- a/website/mdx-components.tsx +++ b/website/mdx-components.tsx @@ -1,14 +1,11 @@ import type { MDXComponents } from "mdx/types"; +import CodeBlock from "@/components/CodeBlock"; export function useMDXComponents(components: MDXComponents): MDXComponents { return { - // Flowbite typography and highlight together create ugly code block - // offspring, so disable typography for code blocks. - pre: ({ children }) => ( -
-
{children}
-
- ), + pre: ({ children }) => { + return {children}; + }, ...components, }; } diff --git a/website/package.json b/website/package.json index 0afa277ab..8ae656004 100644 --- a/website/package.json +++ b/website/package.json @@ -3,6 +3,7 @@ "version": "0.1.0", "private": true, "scripts": { + "setup": "pnpm install && bash ./timestamps.sh", "dev": "next dev", "prebuild": "bash ./timestamps.sh", "build": "next build", diff --git a/website/src/components/Clipboard/index.tsx b/website/src/components/Clipboard/index.tsx new file mode 100644 index 000000000..2e43a71cd --- /dev/null +++ b/website/src/components/Clipboard/index.tsx @@ -0,0 +1,21 @@ +import { Clipboard as FlowbiteClipboard } from "flowbite-react"; +import type { CustomFlowbiteTheme } from "flowbite-react"; + +const clipboardTheme: CustomFlowbiteTheme["clipboard"] = { + withIcon: { + base: "absolute end-2 top-2 inline-flex items-center justify-center rounded p-1.5 text-neutral-500 transition transform duration-200 hover:text-neutral-800 hover:bg-neutral-50", + icon: { + defaultIcon: "h-4 w-4", + successIcon: "h-4 w-4 text-accent-500", + }, + }, +}; + +export default function Clipboard({ valueToCopy }: { valueToCopy: string }) { + return ( + + ); +} diff --git a/website/src/components/CodeBlock/index.tsx b/website/src/components/CodeBlock/index.tsx index 7d0cf7219..573615f5e 100644 --- a/website/src/components/CodeBlock/index.tsx +++ b/website/src/components/CodeBlock/index.tsx @@ -1,17 +1,35 @@ "use client"; -import SyntaxHighlighter from "react-syntax-highlighter"; -import { a11yDark } from "react-syntax-highlighter/dist/esm/styles/hljs"; -export default function CodeBlock({ - language, - codeString, -}: { - language: string; - codeString: string; -}) { +import Clipboard from "@/components/Clipboard"; +import { useState, useRef, useEffect } from "react"; + +export default function CodeBlock({ children }: { children: React.ReactNode }) { + const [isHovered, setIsHovered] = useState(false); + const [codeString, setCodeString] = useState(""); + const preRef = useRef(null); + + useEffect(() => { + if (preRef.current) { + const codeElement = preRef.current.querySelector("code"); + if (codeElement) { + setCodeString(codeElement.innerText); + } + } + }, []); + return ( - - {codeString} - +
setIsHovered(true)} + onMouseLeave={() => setIsHovered(false)} + ref={preRef} + > +
+        {children}
+        {isHovered && }
+      
+
); }