From 96dc8de92fb6bfc47bd642ecd3333656901a82d2 Mon Sep 17 00:00:00 2001 From: Liam Date: Mon, 22 Apr 2024 02:11:41 +0100 Subject: [PATCH] add language indicator to the code highlighter --- sentry.server.config.ts | 1 - src/app/(pages)/docs/[[...slug]]/page.tsx | 1 - src/app/components/code-highlighter.tsx | 16 +++++++++------- src/app/components/copy-button.tsx | 9 +++++++-- src/app/components/navbar.tsx | 2 +- 5 files changed, 17 insertions(+), 12 deletions(-) diff --git a/sentry.server.config.ts b/sentry.server.config.ts index e141971..13b2dff 100644 --- a/sentry.server.config.ts +++ b/sentry.server.config.ts @@ -15,5 +15,4 @@ Sentry.init({ // uncomment the line below to enable Spotlight (https://spotlightjs.com) // spotlight: process.env.NODE_ENV === 'development', - }); diff --git a/src/app/(pages)/docs/[[...slug]]/page.tsx b/src/app/(pages)/docs/[[...slug]]/page.tsx index b8deab8..6977028 100644 --- a/src/app/(pages)/docs/[[...slug]]/page.tsx +++ b/src/app/(pages)/docs/[[...slug]]/page.tsx @@ -13,7 +13,6 @@ import { import { capitalizeFirstLetter } from "@/app/common/string-utils"; import { notFound } from "next/navigation"; import { GithubLink } from "@/app/components/docs/github-link"; -import { CommandMenu } from "@/app/components/command-menu"; type DocumentationPageParams = { params: { diff --git a/src/app/components/code-highlighter.tsx b/src/app/components/code-highlighter.tsx index cd2e1ca..e5237a5 100644 --- a/src/app/components/code-highlighter.tsx +++ b/src/app/components/code-highlighter.tsx @@ -2,6 +2,8 @@ import { ReactElement } from "react"; import SyntaxHighlighter from "react-syntax-highlighter"; import createElement from "react-syntax-highlighter/dist/esm/create-element"; import { atomOneDark } from "react-syntax-highlighter/dist/esm/styles/hljs"; +import { cn } from "@/app/common/utils"; +import { capitalizeFirstLetter } from "@/app/common/string-utils"; type CodeHighlighterProps = { /** @@ -69,18 +71,18 @@ function rowRenderer({ export function CodeHighlighter({ code, language = "json", rounded = true }: CodeHighlighterProps): ReactElement { return ( -
+
+ {/* Language */} +
+ {capitalizeFirstLetter(language)} +
+ {code} diff --git a/src/app/components/copy-button.tsx b/src/app/components/copy-button.tsx index c4de9a0..a324366 100644 --- a/src/app/components/copy-button.tsx +++ b/src/app/components/copy-button.tsx @@ -10,6 +10,11 @@ type CopyButtonProps = { */ content: string; + /** + * The message to display when the content is copied. + */ + message?: string | boolean; + /** * The children for this element. */ @@ -22,7 +27,7 @@ type CopyButtonProps = { * @param props the properties for the button * @returns the copy button */ -export function CopyButton({ content, children }: CopyButtonProps): ReactElement { +export function CopyButton({ content, message, children }: CopyButtonProps): ReactElement { const { toast } = useToast(); return ( @@ -33,7 +38,7 @@ export function CopyButton({ content, children }: CopyButtonProps): ReactElement title: "Copied!", description: (

- Copied {content} to your clipboard. + Copied {!message ? content : message} to your clipboard.

), duration: 5000, diff --git a/src/app/components/navbar.tsx b/src/app/components/navbar.tsx index 1989391..766cc43 100644 --- a/src/app/components/navbar.tsx +++ b/src/app/components/navbar.tsx @@ -2,7 +2,7 @@ import Link from "next/link"; import { usePathname } from "next/navigation"; -import { ReactElement, useEffect, useState } from "react"; +import { ReactElement } from "react"; import { HrefButton } from "./href-button"; import Logo from "./logo"; import { ToggleThemeButton } from "./theme-toggle-button";