-
-
Notifications
You must be signed in to change notification settings - Fork 228
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: support code editor * Update codeblock * refactor: remove unused class --------- Co-authored-by: Mauricio Siu <47042324+Siumauricio@users.noreply.github.com>
- Loading branch information
1 parent
ed6e4e8
commit 4d3e342
Showing
12 changed files
with
349 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import React from "react"; | ||
import type React from "react"; | ||
import { | ||
Dialog, | ||
DialogContent, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import CodeMirror, { type ReactCodeMirrorProps } from "@uiw/react-codemirror"; | ||
import { yaml } from "@codemirror/lang-yaml"; | ||
import { json } from "@codemirror/lang-json"; | ||
import { githubLight, githubDark } from "@uiw/codemirror-theme-github"; | ||
import { cn } from "@/lib/utils"; | ||
import { useTheme } from "next-themes"; | ||
|
||
interface Props extends ReactCodeMirrorProps { | ||
wrapperClassName?: string; | ||
disabled?: boolean; | ||
} | ||
|
||
export const CodeEditor = ({ | ||
className, | ||
wrapperClassName, | ||
...props | ||
}: Props) => { | ||
const { resolvedTheme } = useTheme(); | ||
|
||
return ( | ||
<div className={cn("relative overflow-auto", wrapperClassName)}> | ||
<CodeMirror | ||
basicSetup={{ | ||
lineNumbers: true, | ||
foldGutter: true, | ||
highlightSelectionMatches: true, | ||
highlightActiveLine: !props.disabled, | ||
allowMultipleSelections: true, | ||
}} | ||
theme={resolvedTheme === "dark" ? githubDark : githubLight} | ||
extensions={[yaml(), json()]} | ||
{...props} | ||
editable={!props.disabled} | ||
className={cn( | ||
"w-full h-full text-sm leading-relaxed", | ||
`cm-theme-${resolvedTheme}`, | ||
className, | ||
)} | ||
/> | ||
{props.disabled && ( | ||
<div className="absolute top-0 left-0 w-full h-full flex items-center justify-center z-[10] [background:var(--overlay)]" /> | ||
)} | ||
</div> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.