Closed bobbui closed 4 years ago
Hello @bobbui.
By default, there are two themes - light/dark. But you can define as many as you want. Here is the code segment (from the demo you've seen) where new themes are being defined.
to anyone who looking for the same information, take a look at this package : https://github.com/brijeshb42/monaco-themes
@suren-atoyan why are you installing monaco-themes as dev dependency.. any specific reason?
@adarshaacharya if you mean dev dependency of demo project, so it's just a mistake, I'll fix it, thank you.
@suren-atoyan I've used these themes but problem is why can't we use themes having space ' ' as you have done in timeof filtering theme use only theme which doesn't have white space.
I am sorry, but I don't understand what exactly you mean
Why can't we map all the themes ?
@adarshaacharya There was a problem with theme names, I've already fixed it, now you can use all of them.
I can't figure it out, can't implement a custom theme.
My Code:
import React from "react";
import { Props } from "./github-mardown.model";
import { ControlledEditor, monaco } from "@monaco-editor/react";
monaco
.init()
.then((monaco) => {
import("monaco-themes/themes/Blackboard.json").then((data) => {
monaco.editor.defineTheme("Blackboard", data);
});
})
.catch((error) =>
console.error("An error occurred during initialization of Monaco: ", error)
);
const CodeEditor: React.FC<Props> = (props: Props) => {
const { content, setContent } = props;
const handleChange = (event: any, value: string) => {
setContent(value);
};
return (
<div>
<ControlledEditor
width="100%"
height="calc(100vh - 154px)"
value={content }
onChange={handleChange}
theme="dark"
language="markdown"
/>
</div>
);
};
export default CodeEditor;
Hello @Prottoy2938. You load and define a theme called `Blackboard
, but you use theme dark
in the editor.
Here is an equivalent of your code.
The codesandbox you shared doesn't have the Blackboard
theme. The theme in there is plain white.
Example of a Blackboard
theme can be found here
What to do now?
Also, thanks for your response
Hey @Prottoy2938, the problem was that we tried to use a theme, which is not loaded yet. In the example, we did two jobs simultaneously. First, we tried to load monaco, after that a custom theme, and after that set it to the editor. And second, we tried to render an editor. So, when we rendered an editor, the theme not being loaded yet. I've fixed it. Please check it.
That fixes it. Thanks
Just a quick question. How to use a theme for example Github similar to what you have on the demo. I tried to set it in theme option but no luck Thanks in advance.