Skip to content

Commit 383de77

Browse files
added editor themes changes
1 parent 074730d commit 383de77

File tree

7 files changed

+67
-14
lines changed

7 files changed

+67
-14
lines changed

app/components/code-capture/code-image-preview.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ export default function CodeImagePreview() {
1212
<div className="preview-box w-full mt-40">
1313
{/* frame */}
1414
<div
15-
className="frame mx-auto max-w-full bg-gradient-to-tr to-purple-600 from-blue-400 rounded-md border border-red-500 px-4 py-4"
15+
className="frame mx-auto max-w-full bg-gradient-to-tr to-purple-600 from-blue-400 rounded-md px-4 py-4"
1616
style={{
1717
width: windowWidth + 32,
1818
}}
1919
>
2020
<div
21-
className="window flex flex-col bg-[#353742af] border rounded-md border-[#82738E] border-yellow-600"
21+
className="window flex flex-col bg-[#353742af] border rounded-md border-[#82738E]"
2222
style={{
2323
width: windowWidth,
2424
}}

app/components/code-capture/controls/control-options.tsx

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,17 @@ import {
55
SelectContent,
66
SelectGroup,
77
SelectItem,
8-
SelectLabel,
98
SelectTrigger,
109
SelectValue,
1110
} from "@/components/ui/select";
11+
import useStore from "@/lib/store/store";
12+
import { setTheme } from "@/lib/themes/change-theme";
13+
14+
import themeList from "monaco-themes/themes/themelist.json";
1215

1316
export default function ControlOptions() {
17+
const changeEditorTheme = useStore((state) => state.changeEditorTheme);
18+
1419
return (
1520
<div className="options space-y-4 p-2">
1621
<div className="language w-full flex gap-2 items-center">
@@ -35,16 +40,21 @@ export default function ControlOptions() {
3540
<div className="theme w-full flex gap-2 items-center">
3641
<div className="option-name w-1/3">Theme</div>
3742
<div className="option-input w-full">
38-
<Select>
43+
<Select
44+
onValueChange={(value) => {
45+
console.log("value", value);
46+
changeEditorTheme(value);
47+
setTheme(value);
48+
}}
49+
>
3950
<SelectTrigger>
40-
<SelectValue placeholder="Night-Owl" />
51+
<SelectValue placeholder="Night Owl" />
4152
</SelectTrigger>
4253
<SelectContent>
4354
<SelectGroup>
44-
<SelectItem value="andromeda">Andromeda</SelectItem>
45-
<SelectItem value="night-owl">Night-Owl</SelectItem>
46-
<SelectItem value="vs-code">Vs-Code</SelectItem>
47-
<SelectItem value="github-dark">Github-Dark</SelectItem>
55+
{Object.values(themeList).map((theme) => (
56+
<SelectItem value={theme}>{theme}</SelectItem>
57+
))}
4858
</SelectGroup>
4959
</SelectContent>
5060
</Select>

lib/monoco-editor.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,20 @@
33
import { Editor, MonacoDiffEditor } from "@monaco-editor/react";
44
import React from "react";
55
import useStore from "./store/store";
6+
import { setTheme } from "./themes/change-theme";
67

78
export default function MonacoEditor() {
89
const editorRef = React.useRef<MonacoDiffEditor>(null);
910

1011
const windowWidth = useStore((state) => state.windowWidth);
1112
const changeWindowWidth = useStore((state) => state.changeWindowWidth);
13+
const editorTheme = useStore((state) => state.editorTheme);
1214

1315
// Example function to log scroll width
14-
const logScrollWidth = () => {
16+
const controlEditorWidth = () => {
1517
if (editorRef.current) {
1618
const scrollWidth = editorRef.current.getScrollWidth();
1719

18-
console.log("width", windowWidth);
19-
console.log("Scroll width:", scrollWidth);
20-
2120
if (scrollWidth + 28 > windowWidth) {
2221
console.log("yes");
2322
changeWindowWidth(scrollWidth + 28);
@@ -33,9 +32,10 @@ export default function MonacoEditor() {
3332
theme="vs-dark"
3433
onMount={(editor) => {
3534
editorRef.current = editor;
35+
setTheme(editorTheme);
3636
}}
3737
onChange={() => {
38-
logScrollWidth();
38+
controlEditorWidth();
3939
}}
4040
options={{
4141
lineNumbers: "off",

lib/store/store.tsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ import { create } from "zustand";
33
interface StoreStates {
44
windowWidth: number;
55
changeWindowWidth: (newWidth: number) => void;
6+
7+
editorTheme: string;
8+
changeEditorTheme: (theme: string) => void;
69
}
710

811
const useStore = create<StoreStates>()((set) => ({
@@ -11,6 +14,12 @@ const useStore = create<StoreStates>()((set) => ({
1114
set(() => ({
1215
windowWidth: newWidth,
1316
})),
17+
18+
editorTheme: "Night Owl",
19+
changeEditorTheme: (theme) =>
20+
set(() => ({
21+
editorTheme: theme,
22+
})),
1423
}));
1524

1625
export default useStore;

lib/themes/change-theme.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { loader } from "@monaco-editor/react";
2+
3+
const setTheme = async (themeName: string) => {
4+
console.log(themeName);
5+
let themeData = await import(`monaco-themes/themes/${themeName}.json`);
6+
themeData = { ...themeData };
7+
8+
themeName &&
9+
loader.init().then((monaco) => {
10+
if (themeName.split(" ").length > 1) {
11+
console.log("yes");
12+
themeName = themeName.split(" ")[0] + "-" + themeName.split(" ")[1];
13+
}
14+
monaco.editor.defineTheme(themeName, themeData);
15+
monaco.editor.setTheme(themeName);
16+
});
17+
18+
return { ...themeData };
19+
};
20+
21+
export { setTheme };

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
"class-variance-authority": "^0.7.0",
1515
"clsx": "^2.1.1",
1616
"lucide-react": "^0.395.0",
17+
"monaco-themes": "^0.4.4",
1718
"next": "14.2.3",
1819
"react": "^18",
1920
"react-dom": "^18",

yarn.lock

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1875,6 +1875,11 @@ fast-levenshtein@^2.0.6:
18751875
resolved "https://registry.yarnpkg.com/fast-levenshtein/-/fast-levenshtein-2.0.6.tgz#3d8a5c66883a16a30ca8643e851f19baa7797917"
18761876
integrity sha512-DCXu6Ifhqcks7TZKY3Hxp3y6qphY5SJZmrWMDrKcERSOXWQdMhU9Ig/PYrzyw/ul9jOIyh0N4M0tbC5hodg8dw==
18771877

1878+
fast-plist@^0.1.3:
1879+
version "0.1.3"
1880+
resolved "https://registry.yarnpkg.com/fast-plist/-/fast-plist-0.1.3.tgz#328cd9335e93a2479ac90814a1302437574ea925"
1881+
integrity sha512-d9cEfo/WcOezgPLAC/8t8wGb6YOD6JTCPMw2QcG2nAdFmyY+9rTUizCTaGjIZAloWENTEUMAPpkUAIJJJ0i96A==
1882+
18781883
fastq@^1.6.0:
18791884
version "1.17.1"
18801885
resolved "https://registry.yarnpkg.com/fastq/-/fastq-1.17.1.tgz#2a523f07a4e7b1e81a42b91b8bf2254107753b47"
@@ -2733,6 +2738,13 @@ mkdirp@^2.1.6:
27332738
resolved "https://registry.yarnpkg.com/mkdirp/-/mkdirp-2.1.6.tgz#964fbcb12b2d8c5d6fbc62a963ac95a273e2cc19"
27342739
integrity sha512-+hEnITedc8LAtIP9u3HJDFIdcLV2vXP33sqLLIzkv1Db1zO/1OxbvYf0Y1OC/S/Qo5dxHXepofhmxL02PsKe+A==
27352740

2741+
monaco-themes@^0.4.4:
2742+
version "0.4.4"
2743+
resolved "https://registry.yarnpkg.com/monaco-themes/-/monaco-themes-0.4.4.tgz#28ab13e538c4867a9bc89dc67f15dfaf3fc69de1"
2744+
integrity sha512-Hbb9pvRrpSi0rZezcB/IOdQnpx10o55Lx4zFdRAAVpFMa1HP7FgaqEZdKffb4ovd90fETCixeFO9JPYFMAq+TQ==
2745+
dependencies:
2746+
fast-plist "^0.1.3"
2747+
27362748
27372749
version "2.1.2"
27382750
resolved "https://registry.yarnpkg.com/ms/-/ms-2.1.2.tgz#d09d1f357b443f493382a8eb3ccd183872ae6009"

0 commit comments

Comments
 (0)