Skip to content

Commit 32e5745

Browse files
authored
Merge pull request #21 from pheralb/next
New Code-Block MDX + New Doc-Options + Improve Homepage + Update dependencies
2 parents 5026696 + 1d98225 commit 32e5745

31 files changed

Lines changed: 671 additions & 336 deletions

‎.gitignore‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,7 @@ yarn-error.log*
4343
next-env.d.ts
4444

4545
# content-collections
46-
.content-collections
46+
.content-collections
47+
48+
# agents
49+
.agents

‎apps/website/next.config.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ const nextConfig: NextConfig = {
1919
destination: "/docs/getting-started/prerequisites",
2020
permanent: true,
2121
},
22+
{
23+
source: "/docs/react/code-block-mdx",
24+
destination: "/docs/react/code-block-mdx-shiki",
25+
permanent: true,
26+
},
2227
{
2328
source: "/components",
2429
destination: "/docs/react/copy-button",

‎apps/website/src/app/page.tsx‎

Lines changed: 57 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,26 @@
11
import type { Metadata } from "next";
22

3+
import { cn } from "@/utils/cn";
34
import { globals } from "@/globals";
45
import { notFound } from "next/navigation";
56
import { getGeneralDocument } from "@/utils/docs";
67

7-
import MDX from "@/components/mdx";
88
import Article from "@/components/docs/doc-article";
99
import Container from "@/components/container";
1010

1111
import Header from "@/components/header";
1212
import Footer from "@/components/footer";
1313

14+
import { GitHub } from "@/components/ui/svgs";
15+
import { ArrowUpRightIcon } from "lucide-react";
16+
17+
import MDX from "@/components/mdx";
18+
import GetStartedLink from "@/components/home/get-started-link";
19+
import InstallCommands from "@/components/home/install-commands";
20+
21+
import { buttonVariants } from "@/components/ui/button";
22+
import { ExternalLink } from "@/components/ui/external-link";
23+
1424
export async function generateMetadata(): Promise<Metadata> {
1525
const websiteUrl = "https://code-blocks.pheralb.dev";
1626
const data = getGeneralDocument("home");
@@ -37,9 +47,52 @@ const Home = () => {
3747
<main className="pb-4">
3848
<Container>
3949
<Header layout="app" />
40-
<Article className="pb-8">
41-
<MDX code={document.mdx} />
42-
</Article>
50+
<div
51+
className={cn(
52+
"not-prose",
53+
"flex flex-col space-y-6 pt-10 md:pt-12",
54+
"animate-in fill-mode-backwards fade-in slide-in-from-bottom-2 duration-500",
55+
)}
56+
>
57+
<div className="flex flex-col items-start justify-center space-y-2 md:items-center">
58+
<h1 className="text-3xl font-semibold tracking-tight text-balance md:text-4xl lg:text-5xl">
59+
Build beautiful code blocks
60+
</h1>
61+
<p className="font-medium text-neutral-500 dark:text-neutral-400">
62+
Ready to use UI components and utilities to show your snippets
63+
beautifully.
64+
</p>
65+
</div>
66+
<div
67+
className={cn(
68+
"flex flex-row items-center justify-center space-x-2",
69+
)}
70+
>
71+
<GetStartedLink />
72+
<ExternalLink
73+
title="GitHub"
74+
href={globals.githubUrl}
75+
className={buttonVariants({
76+
size: "default",
77+
variant: "outline",
78+
className: "w-full no-underline md:w-40",
79+
})}
80+
>
81+
<div className="flex items-center space-x-2">
82+
<GitHub height={14} />
83+
<span>GitHub</span>
84+
</div>
85+
<ArrowUpRightIcon size={12} />
86+
</ExternalLink>
87+
</div>
88+
<InstallCommands />
89+
</div>
90+
<div className="animate-in fill-mode-backwards fade-in slide-in-from-bottom-4 duration-500 delay-100">
91+
<div className="my-8 h-px bg-neutral-200 dark:bg-neutral-800" />
92+
<Article className="prose-h2:border-0 prose-h2:pb-0 prose-h2:text-2xl pb-8">
93+
<MDX code={document.mdx} />
94+
</Article>
95+
</div>
4396
</Container>
4497
<Footer />
4598
</main>

‎apps/website/src/components/code-block/blocks/copy-text-morph.tsx‎

Lines changed: 2 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -1,97 +1,15 @@
11
"use client";
22

3-
import {
4-
useMemo,
5-
useId,
6-
useEffect,
7-
useState,
8-
type ComponentProps,
9-
} from "react";
10-
11-
import {
12-
motion,
13-
AnimatePresence,
14-
type Transition,
15-
type Variants,
16-
} from "motion/react";
17-
183
import { cn } from "@/utils/cn";
194
import { copyToClipboard } from "@/utils/copy";
5+
import { TextMorph } from "@/components/ui/text-morph";
6+
import { useEffect, useState, type ComponentProps } from "react";
207

218
interface CopyTextAnimatedProps extends ComponentProps<"button"> {
229
content: string;
2310
size?: "xs" | "sm";
2411
}
2512

26-
export type TextMorphProps = {
27-
children: string;
28-
as?: React.ElementType;
29-
className?: string;
30-
style?: React.CSSProperties;
31-
variants?: Variants;
32-
transition?: Transition;
33-
};
34-
35-
export function TextMorph({
36-
children,
37-
as: Component = "p",
38-
className,
39-
style,
40-
variants,
41-
transition,
42-
}: TextMorphProps) {
43-
const uniqueId = useId();
44-
45-
const characters = useMemo(() => {
46-
const charCounts: Record<string, number> = {};
47-
48-
return children.split("").map((char) => {
49-
const lowerChar = char.toLowerCase();
50-
charCounts[lowerChar] = (charCounts[lowerChar] || 0) + 1;
51-
52-
return {
53-
id: `${uniqueId}-${lowerChar}${charCounts[lowerChar]}`,
54-
label: char === " " ? "\u00A0" : char,
55-
};
56-
});
57-
}, [children, uniqueId]);
58-
59-
const defaultVariants: Variants = {
60-
initial: { opacity: 0 },
61-
animate: { opacity: 1 },
62-
exit: { opacity: 0 },
63-
};
64-
65-
const defaultTransition: Transition = {
66-
type: "spring",
67-
stiffness: 280,
68-
damping: 18,
69-
mass: 0.3,
70-
};
71-
72-
return (
73-
<Component className={cn(className)} aria-label={children} style={style}>
74-
<AnimatePresence mode="popLayout" initial={false}>
75-
{characters.map((character) => (
76-
<motion.span
77-
key={character.id}
78-
layoutId={character.id}
79-
className="inline-block"
80-
aria-hidden="true"
81-
initial="initial"
82-
animate="animate"
83-
exit="exit"
84-
variants={variants || defaultVariants}
85-
transition={transition || defaultTransition}
86-
>
87-
{character.label}
88-
</motion.span>
89-
))}
90-
</AnimatePresence>
91-
</Component>
92-
);
93-
}
94-
9513
const CopyTextMorph = ({
9614
content,
9715
size = "sm",

‎apps/website/src/components/code-block/client/shiki.tsx‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ const CodeblockShiki = ({
5252

5353
const classNames = cn("w-full overflow-x-auto", className);
5454

55-
// SSR fallback
5655
return highlightedHtml ? (
5756
<div
5857
className={classNames}
@@ -61,7 +60,7 @@ const CodeblockShiki = ({
6160
/>
6261
) : (
6362
<div className={classNames} {...props}>
64-
<pre>
63+
<pre className="px-4 py-3">
6564
<code>{code}</code>
6665
</pre>
6766
</div>

‎apps/website/src/components/code-block/mdx/pre-shiki.tsx‎

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import type { ComponentProps } from "react";
22
import type { MDXComponents } from "mdx/types";
33

4+
import { cn } from "@/utils/cn";
45
import { reactToText } from "@/utils/react-to-text";
56

67
import {
@@ -23,15 +24,23 @@ const PreShikiComponent: MDXComponents = {
2324
const title = props["data-title"];
2425
const language = props["data-language"];
2526
return (
26-
<CodeBlock>
27-
<CodeBlockHeader>
28-
<CodeBlockGroup>
29-
<CodeBlockIcon language={language} />
30-
<span>{title ?? `.${language}`}</span>
31-
</CodeBlockGroup>
32-
<CopyButton content={content} />
33-
</CodeBlockHeader>
34-
<CodeBlockContent>
27+
<CodeBlock className="group/code-block">
28+
{title && (
29+
<CodeBlockHeader>
30+
<CodeBlockGroup>
31+
<CodeBlockIcon language={language} />
32+
<span>{title}</span>
33+
</CodeBlockGroup>
34+
<CopyButton content={content} />
35+
</CodeBlockHeader>
36+
)}
37+
<CodeBlockContent className={cn(!title && "relative")}>
38+
{!title && (
39+
<CopyButton
40+
content={content}
41+
className="sticky top-3 right-3 z-50 float-right rounded-md text-neutral-950 opacity-0 transition-opacity group-hover/code-block:opacity-100 hover:opacity-70 dark:text-neutral-50"
42+
/>
43+
)}
3544
<pre {...props}>{children}</pre>
3645
</CodeBlockContent>
3746
</CodeBlock>

‎apps/website/src/components/code-block/mdx/pre-sugar-high.tsx‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import { reactToText } from "@/utils/react-to-text";
66

77
import {
88
CodeBlock,
9-
CodeBlockHeader,
109
CodeBlockContent,
1110
} from "@/components/code-block/code-block";
1211
import { CopyButton } from "@/components/code-block/copy-button";
@@ -20,12 +19,13 @@ const PreSugarHighComponent: MDXComponents = {
2019
code: content,
2120
});
2221
return (
23-
<CodeBlock>
24-
<CodeBlockHeader className="justify-end">
25-
<CopyButton content={content} />
26-
</CodeBlockHeader>
27-
<CodeBlockContent>
28-
<pre>
22+
<CodeBlock className="group/code-block">
23+
<CodeBlockContent className="relative">
24+
<CopyButton
25+
content={content}
26+
className="sticky top-3 right-3 z-50 float-right rounded-md text-neutral-950 opacity-0 transition-opacity group-hover/code-block:opacity-100 hover:opacity-70 dark:text-neutral-50"
27+
/>
28+
<pre className="sh-pre">
2929
<code dangerouslySetInnerHTML={{ __html: codeHTML }} />
3030
</pre>
3131
</CodeBlockContent>

0 commit comments

Comments
 (0)