question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Summary

I want to change dark mode of the editor when user clicks on the button.

Screenshots

Screenshot from 2021-07-01 08-16-29

In the above picture, you can see i have added a dark mode button. I want to change mode from light to dark and dark to light when user click on the button.

Version

latest

Additional context

I am using ReactJS.

export default function App() {
  const [theme, setTheme] = useState("light");
  let darkModeOn = false;
  
  console.log(darkModeOn,theme)
  const toggleDarkMode=()=>{
    darkModeOn = !darkModeOn;
    setTheme(darkModeOn?"light":"dark");
  }

  return <Editor
    initialValue="# hello react editor world!"
    previewStyle={previewStyle}
    height="400px"
    initialEditType="markdown"
    useCommandShortcut={true}
    theme={theme}

    toolbarItems={[
      ...items, [{
        el: toggleFullScreen(editorRef),
        tooltip: 'Toggle Full Screen'
      }, {
        el: previewStyleButton(),
        tooltip: "Preview Style"
      }, {
        el: darkMode(toggleDarkMode),
        tooltip: "Preview Style"
      }],
      ['scrollSync']
    ]}
  />
}
  />
}

When user click on the button then toggleDarkMode function will be executed. Although, theme state variable is changeing, but UI is not updating.

live

https://codesandbox.io/s/still-night-0feor?file=/src/App.js

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:2
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
js87zzcommented, Jul 1, 2021

@ats1999 There are currently no APIs for changing themes. Your method is correct, and I will think about adding API. Thank you!

1reaction
ats1999commented, Jul 1, 2021

Current workaround is

 const toggleDarkMode=()=>{
    let el = document.getElementsByClassName("toastui-editor-defaultUI")[0];
    if(el.classList.contains("toastui-editor-dark"))
      el.classList.remove("toastui-editor-dark");
    else el.classList.add("toastui-editor-dark");
  }

It’s working perfectly, but still if there is any other way then let me know.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Switch between dark and light theme on the fly with Nightlight
Switch between dark and light theme on Windows with just two clicks using the open source program, Nightlight.
Read more >
Dark theme - Android Developers
Dark theme applies to both the Android system UI and apps running on the device. There are three ways to enable Dark theme...
Read more >
Designing for dark mode - Help Center - WordFly
Introduction to dark mode. Dark mode is a device or application setting that allows people to work with backgrounds that are dark.
Read more >
Switch to dark mode — Flipboard Help Center
You can also flip your theme from light to dark on the fly. Just go to your Profile menu and toggle Dark on...
Read more >
How to change messenger to dark mode in FLY Champ?, how to
How to activate Messenger Dark Mode in FLY Champ? · In the first step, tap on the Messenger app icon from the apps...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found