1
mirror of https://github.com/jakejarvis/jarv.is.git synced 2026-06-19 11:55:30 -04:00

Tailwind redesign (#2387)

This commit is contained in:
2025-05-02 22:04:26 -04:00
committed by GitHub
parent c4f67f170b
commit 5058382f71
162 changed files with 2739 additions and 3554 deletions
+52
View File
@@ -0,0 +1,52 @@
import { codeToHtml } from "shiki";
import CopyButton from "@/components/copy-button";
import { cn } from "@/lib/utils";
import type { JSX } from "react";
export type CodeBlockProps = JSX.IntrinsicElements["pre"] & {
lineNumbers?: boolean;
};
const CodeBlock = async (props: CodeBlockProps) => {
// escape hatch if this code wasn't meant to be highlighted
if (!props.children || typeof props.children !== "object" || !("props" in props.children)) {
return <code {...props} />;
}
const codeProps = props.children.props as JSX.IntrinsicElements["code"];
const codeRaw = String(codeProps.children).trim();
const lang = codeProps.className?.split("language-")[1] ?? "";
const codeHighlighted = await codeToHtml(codeRaw.trim(), {
lang,
themes: {
light: "material-theme-lighter",
dark: "material-theme-darker",
},
});
return (
<div
className={cn(
"bg-muted/35 border-border relative my-4 w-full rounded-lg border-2 font-mono [font-variant-ligatures:none]",
props.className
)}
>
<div
className={cn(
"grid w-full overflow-x-auto p-4 text-sm leading-none [counter-reset:line] dark:**:text-[var(--shiki-dark)]! [&_.line]:inline-block [&_.line]:min-w-full [&_.line]:py-1 [&_.line]:whitespace-pre [&_.line]:after:hidden [&>pre]:bg-transparent! [&>pre]:whitespace-normal",
props.lineNumbers &&
"[&_.line]:before:text-muted-foreground [&_.line]:before:mr-4 [&_.line]:before:inline-block [&_.line]:before:w-5 [&_.line]:before:text-right [&_.line]:before:content-[counter(line)] [&_.line]:before:[counter-increment:line]"
)}
data-language={lang}
dangerouslySetInnerHTML={{ __html: codeHighlighted }}
/>
<CopyButton
source={codeRaw}
className="border-border text-foreground/85 hover:text-primary bg-muted/10 absolute top-0 right-0 size-[40px] rounded-tr-lg rounded-bl-lg border-b-2 border-l-2 p-0 backdrop-blur-xs [&>svg]:my-auto [&>svg]:inline-block [&>svg]:size-[18px] [&>svg]:align-middle"
/>
</div>
);
};
export default CodeBlock;