uiwjs / react-md-editor

A simple markdown editor with preview, implemented with React.js and TypeScript.
https://uiwjs.github.io/react-md-editor
MIT License
2.17k stars 157 forks source link

Respect previewOptions className #287

Closed malcolm-kee closed 2 years ago

malcolm-kee commented 2 years ago

Right now the preview className is fixed as ${prefixCls}-preview due to https://github.com/uiwjs/react-md-editor/blob/master/src/Editor.tsx#L276.

I think it should use className from previewOptions if it is provided.

If that's not what you intends, then maybe remove className from previewOptions type definition.

Either way, happy to create a PR if you can confirm the intentional behavior. Thanks!

jaywcjlove commented 2 years ago

https://github.com/uiwjs/react-md-editor/blob/cf68ab6c3aa254a112e515512687717322df6430/src/Editor.tsx#L164

className is passed to the outermost box.

@malcolm-kee

malcolm-kee commented 2 years ago

previewOptions object has className.

jaywcjlove commented 2 years ago

@malcolm-kee Yes, it is passed to the @uiw/react-markdown-preview component.

https://github.com/uiwjs/react-md-editor/blob/cf68ab6c3aa254a112e515512687717322df6430/src/Editor.tsx#L2

malcolm-kee commented 2 years ago

@jaywcjlove it is not.

Reproduction: https://codesandbox.io/s/markdown-editor-for-react-forked-ieyf2?file=/index.js

jaywcjlove commented 2 years ago
<MDEditor.Markdown
  source={value}
  linkTarget="_blank"
+  className="red-bg"
-  previewOptions={{
-    // this applied but ignore
-    className: "red-bg"
-  }}
/>

@malcolm-kee

malcolm-kee commented 2 years ago

@jaywcjlove sorry the previous code is wrong 😅 .

I just updated my example:

function App() {
  const [value, setValue] = React.useState(mkdStr);
  return (
    <div className="container">
      <div className="red-bg">style applied</div>
      <MDEditor
        height={200}
        value={value}
        onChange={setValue}
        previewOptions={{
          // this applied but ignore
          className: "red-bg"
        }}
      />
    </div>
  );
}
jaywcjlove commented 2 years ago

I fixed this issue. @malcolm-kee

malcolm-kee commented 2 years ago

Thanks for the quick fix! You're awesome!