Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dark mode on fly #1618

Open
ats1999 opened this issue Jul 1, 2021 · 8 comments
Open

dark mode on fly #1618

ats1999 opened this issue Jul 1, 2021 · 8 comments
Labels
Enhancement Enhance performance or improve usability of original features. Question

Comments

@ats1999
Copy link
Contributor

ats1999 commented Jul 1, 2021

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

@ats1999
Copy link
Contributor Author

ats1999 commented Jul 1, 2021

We just need to add the class name toastui-editor-dark here. But, doing it by traversing DOM is not good. Is there any way to do it?

Screenshot from 2021-07-01 08-31-14

@ats1999
Copy link
Contributor Author

ats1999 commented 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.

@js87zz
Copy link
Contributor

js87zz commented 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!

@ats1999 ats1999 closed this as completed Jul 1, 2021
@js87zz js87zz reopened this Jul 1, 2021
@js87zz js87zz added the Enhancement Enhance performance or improve usability of original features. label Jul 1, 2021
@ajruckman
Copy link

Hi, I have a use case for this too, would love to see it added to the API :)

@leangseu
Copy link

leangseu commented Oct 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.

The other work around is that you can just add the class to the wrapper dom. Seem like it always overwrite the default. I would love to have direct API for this though.

     <div className={`editor-panel-editor${theme == 'dark' ?  ' toastui-editor-dark': ''}`}>
        <Editor
          ref={editorRef}
          initialValue={content}
          previewStyle="vertical"
          height="600px"
          initialEditType="markdown"
          useCommandShortcut={true}
          plugins={[[codeSyntaxHighlight, { highlighter: Prism }]]}
        />
      </div>

@ats1999
Copy link
Contributor Author

ats1999 commented Oct 22, 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.

The other work around is that you can just add the class to the wrapper dom. Seem like it always overwrite the default. I would love to have direct API for this though.

     <div className={`editor-panel-editor${theme == 'dark' ?  ' toastui-editor-dark': ''}`}>
        <Editor
          ref={editorRef}
          initialValue={content}
          previewStyle="vertical"
          height="600px"
          initialEditType="markdown"
          useCommandShortcut={true}
          plugins={[[codeSyntaxHighlight, { highlighter: Prism }]]}
        />
      </div>

both of them would work and wait for this feature to be inbuilt.

@gautam-bmdi
Copy link

Would love to see this feature too!

@aaronvegh
Copy link

I would like a vote for this feature as well, for what it's worth. 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement Enhance performance or improve usability of original features. Question
Projects
None yet
Development

No branches or pull requests

6 participants