Skip to content

Commit bf7edac

Browse files
committed
packages/ui: Add code components
1 parent 4f4faa5 commit bf7edac

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+229
-631
lines changed

apps/dashboard/knip.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@
1414
"@types/color",
1515
"fast-xml-parser",
1616
"@workspace/ui",
17-
"tailwindcss-animate"
17+
"tailwindcss-animate",
18+
"@radix-ui/react-tooltip",
19+
"shiki"
1820
],
1921
"next": true,
2022
"project": ["src/**"]
Lines changed: 1 addition & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -1,71 +1,3 @@
11
"use client";
2-
import { keepPreviousData, useQuery } from "@tanstack/react-query";
3-
import type { BundledLanguage } from "shiki";
4-
import { getCodeHtml } from "./getCodeHtml";
5-
import { PlainTextCodeBlock } from "./plaintext-code";
6-
import { RenderCode } from "./RenderCode";
72

8-
export type CodeProps = {
9-
code: string;
10-
lang: BundledLanguage;
11-
className?: string;
12-
scrollableClassName?: string;
13-
keepPreviousDataOnCodeChange?: boolean;
14-
copyButtonClassName?: string;
15-
scrollableContainerClassName?: string;
16-
shadowColor?: string;
17-
ignoreFormattingErrors?: boolean;
18-
onCopy?: (code: string) => void;
19-
};
20-
21-
export const CodeClient: React.FC<CodeProps> = ({
22-
code,
23-
lang,
24-
className,
25-
scrollableClassName,
26-
keepPreviousDataOnCodeChange = false,
27-
copyButtonClassName,
28-
ignoreFormattingErrors,
29-
scrollableContainerClassName,
30-
shadowColor,
31-
onCopy,
32-
}) => {
33-
const codeQuery = useQuery({
34-
placeholderData: keepPreviousDataOnCodeChange
35-
? keepPreviousData
36-
: undefined,
37-
queryFn: () =>
38-
getCodeHtml(code, lang, {
39-
ignoreFormattingErrors: ignoreFormattingErrors,
40-
}),
41-
queryKey: ["html", code],
42-
retry: false,
43-
});
44-
45-
if (!codeQuery.data) {
46-
return (
47-
<PlainTextCodeBlock
48-
className={className}
49-
code={code}
50-
copyButtonClassName={copyButtonClassName}
51-
onCopy={onCopy}
52-
scrollableClassName={scrollableClassName}
53-
scrollableContainerClassName={scrollableContainerClassName}
54-
shadowColor={shadowColor}
55-
/>
56-
);
57-
}
58-
59-
return (
60-
<RenderCode
61-
className={className}
62-
code={codeQuery.data.formattedCode}
63-
copyButtonClassName={copyButtonClassName}
64-
html={codeQuery.data.html}
65-
onCopy={onCopy}
66-
scrollableClassName={scrollableClassName}
67-
scrollableContainerClassName={scrollableContainerClassName}
68-
shadowColor={shadowColor}
69-
/>
70-
);
71-
};
3+
export { CodeClient } from "@workspace/ui/components/code/code.client";
Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,4 @@
1-
import type { BundledLanguage } from "shiki";
2-
import { getCodeHtml } from "./getCodeHtml";
3-
import { RenderCode } from "./RenderCode";
4-
5-
export type CodeProps = {
6-
code: string;
7-
lang: BundledLanguage;
8-
className?: string;
9-
ignoreFormattingErrors?: boolean;
10-
};
11-
12-
export const CodeServer: React.FC<CodeProps> = async ({
13-
code,
14-
lang,
15-
className,
16-
ignoreFormattingErrors,
17-
}) => {
18-
const { html, formattedCode } = await getCodeHtml(code, lang, {
19-
ignoreFormattingErrors,
20-
});
21-
return <RenderCode className={className} code={formattedCode} html={html} />;
22-
};
1+
export {
2+
type CodeProps,
3+
CodeServer,
4+
} from "@workspace/ui/components/code/code.server";
Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1 @@
1-
import { cn } from "@/lib/utils";
2-
import { CodeBlockContainer } from "./CodeBlockContainer";
3-
4-
export function PlainTextCodeBlock(props: {
5-
code: string;
6-
copyButtonClassName?: string;
7-
className?: string;
8-
scrollableClassName?: string;
9-
codeClassName?: string;
10-
scrollableContainerClassName?: string;
11-
shadowColor?: string;
12-
onCopy?: (code: string) => void;
13-
}) {
14-
return (
15-
<CodeBlockContainer
16-
className={props.className}
17-
codeToCopy={props.code}
18-
copyButtonClassName={props.copyButtonClassName}
19-
onCopy={props.onCopy}
20-
scrollableClassName={props.scrollableClassName}
21-
scrollableContainerClassName={props.scrollableContainerClassName}
22-
shadowColor={props.shadowColor}
23-
>
24-
<code className={cn("block whitespace-pre", props.codeClassName)}>
25-
{props.code}
26-
</code>
27-
</CodeBlockContainer>
28-
);
29-
}
1+
export { PlainTextCodeBlock } from "@workspace/ui/components/code/plaintext-code";

apps/playground-web/knip.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
"server-only",
66
"@workspace/ui",
77
"tailwindcss-animate",
8-
"@radix-ui/react-tooltip"
8+
"@radix-ui/react-tooltip",
9+
"prettier"
910
],
1011
"next": true,
1112
"project": ["src/**"]

apps/playground-web/src/app/insight/[blueprint_slug]/blueprint-playground.client.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import {
1717
useForm,
1818
} from "react-hook-form";
1919
import { z } from "zod";
20-
import { CodeClient, CodeLoading } from "@/components/code/code.client";
20+
import { CodeClient } from "@/components/code/code.client";
2121
import { Badge } from "@/components/ui/badge";
2222
import { Button } from "@/components/ui/button";
2323
import { Form, FormField, FormItem, FormMessage } from "@/components/ui/form";
@@ -724,7 +724,6 @@ function ResponseSection(props: {
724724
className="rounded-none border-none bg-transparent"
725725
code={formattedData || ""}
726726
lang="json"
727-
loader={<CodeLoading />}
728727
scrollableClassName="h-full"
729728
scrollableContainerClassName="h-full"
730729
// shadowColor="hsl(var(--muted)/50%)"

apps/playground-web/src/app/payments/components/CodeGen.tsx

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,26 @@
11
import { lazy, Suspense } from "react";
2-
import { CodeLoading } from "../../../components/code/code.client";
2+
import { LoadingDots } from "../../../components/ui/LoadingDots";
33
import type { BridgeComponentsPlaygroundOptions } from "./types";
44

5-
const CodeClient = lazy(() => import("../../../components/code/code.client"));
5+
const CodeClient = lazy(() =>
6+
import("../../../components/code/code.client").then((m) => ({
7+
default: m.CodeClient,
8+
})),
9+
);
10+
11+
function CodeLoading() {
12+
return (
13+
<div className="flex min-h-[300px] grow items-center justify-center bg-card border rounded-lg">
14+
<LoadingDots />
15+
</div>
16+
);
17+
}
618

719
export function CodeGen(props: { options: BridgeComponentsPlaygroundOptions }) {
820
return (
921
<div className="flex w-full grow flex-col">
1022
<Suspense fallback={<CodeLoading />}>
11-
<CodeClient
12-
className="grow"
13-
code={getCode(props.options)}
14-
lang="tsx"
15-
loader={<CodeLoading />}
16-
/>
23+
<CodeClient className="grow" code={getCode(props.options)} lang="tsx" />
1724
</Suspense>
1825
</div>
1926
);

apps/playground-web/src/app/transactions/airdrop-tokens/_components/airdrop-code.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Code } from "../../../../components/code/code";
1+
import { CodeServer } from "@/components/code/code";
22
import { airdropExample } from "../constants";
33

44
export function AirdropCode() {
@@ -15,7 +15,7 @@ export function AirdropCode() {
1515
<h3 className="mb-2 font-semibold text-xl tracking-tight">
1616
Send Airdrop Transaction Request
1717
</h3>
18-
<Code code={engineAirdropSendCode} lang="typescript" />
18+
<CodeServer code={engineAirdropSendCode} lang="typescript" />
1919

2020
<div className="h-8" />
2121

@@ -28,7 +28,7 @@ export function AirdropCode() {
2828
of the transaction using the following code.
2929
</p>
3030
</div>
31-
<Code code={engineAirdropGetStatus} lang="typescript" />
31+
<CodeServer code={engineAirdropGetStatus} lang="typescript" />
3232
</div>
3333
);
3434
}

apps/playground-web/src/app/transactions/mint-tokens/_components/mint-code.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Code } from "../../../../components/code/code";
1+
import { CodeServer } from "@/components/code/code";
22
import { mintExample } from "../constants";
33

44
export function MintCode() {
@@ -15,7 +15,7 @@ export function MintCode() {
1515
<h3 className="mb-2 font-semibold text-xl tracking-tight">
1616
Send Transaction Request to Mint Dynamic NFTs
1717
</h3>
18-
<Code code={engineMintCode} lang="typescript" />
18+
<CodeServer code={engineMintCode} lang="typescript" />
1919

2020
<div className="h-8" />
2121

@@ -28,7 +28,7 @@ export function MintCode() {
2828
the transaction using the following code.
2929
</p>
3030
</div>
31-
<Code code={getEngineStatusCode} lang="typescript" />
31+
<CodeServer code={getEngineStatusCode} lang="typescript" />
3232
</div>
3333
);
3434
}

apps/playground-web/src/app/transactions/webhooks/_components/webhooks-preview.tsx

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@ import {
1919
FormMessage,
2020
} from "@/components/ui/form";
2121
import { Input } from "@/components/ui/input";
22-
import CodeClient from "../../../../components/code/code.client";
23-
import { LoadingDots } from "../../../../components/ui/LoadingDots";
22+
import { CodeClient } from "../../../../components/code/code.client";
2423
import { Label } from "../../../../components/ui/label";
2524
import { Spinner } from "../../../../components/ui/Spinner";
2625
import { THIRDWEB_CLIENT } from "../../../../lib/client";
@@ -147,11 +146,6 @@ export function EngineWebhooksPreview() {
147146
className="grow rounded-none border-none"
148147
code={JSON.stringify(engineTxStatusQuery.data, null, 2)}
149148
lang="json"
150-
loader={
151-
<div className="flex grow items-center justify-center">
152-
<LoadingDots />
153-
</div>
154-
}
155149
scrollableContainerClassName="h-full"
156150
/>
157151
</div>

0 commit comments

Comments
 (0)