Closed ryendu closed 1 year ago
Oh, so exciting :). The first issue!
You need to import @mdxeditor/editor/style.css
in there. This assumes that your bundling respects this package line. If not, the actual css file is here.
Please let me know how it goes, I am happy to help with your evaluation. It's a new project of mine, and I am happy to receive and act on feedback.
Added this to the getting started docs.
it worked, thanks!!
@petyosi Any suggestions for how to get styles included with a simple import rather than manually copying styles in?
Is it webpack that's unable to incorporate the exports key in your package.json
?
I'm using:
@braincore I'm not sure what you mean. What's the problem you have?
The toolbar had no styling before and after adding import '@mdxeditor/editor/style.css';
. I assumed (but did not independently verify) that it's as you said: the bundler (webpack) does not respect the exports line in package.json.
If you don't think that's it, I'll dig in further.
Thanks for the clarification.
As far as I can tell, exports should work with your webpack version. Do you see any kind of error? Does it work if you use '@mdxeditor/editor/dist/style.css'
(the actual location of the file?).
If you have the whole thing reproducible somewhere, I should be able to help further and document it properly. Thank you!
Sorry for the delay.
Using '@mdxeditor/editor/dist/style.css'
doesn't work: ./dist/style.css is not exported from package
.
I'm trying to test this with a large existing project so I don't have anything small and reproducible unfortunately. I assume it works for a fresh project.
@braincore in this case, it looks like your system does understand the exports
field, but something else goes in the way. I'm not sure what goes on, but I would suggest that you poke around with the webdev tools and see where the style.css ends up. It could be many things, hard to say without being familiar with the project structure.
I am facing this same issue. The styling is missing from the mdx-editor components after running npm build
in a standard create-react-app. I can confirm the browser receives the @mdxeditor/editor/style.css
stylesheet after npm build
, but the styles are not applied.
You might say the useEffect()
block with the CSS editing is the issue, but even when that's completely removed, the basic CSS is missing after the build.
When I run it via npm start
it looks like this:
When I run it after building in a docker container, it looks like this:
I found a workaround for the issue by using react-helmet to inject the mdxeditor style into the style in the page's head. I have little experience with frontend dev, and I am not proud of this solution, yet it works. I am open to any suggestions.
More specifically, below you can see at the top of my js component mentioned earlier, I added the following snippet to inject the mdxeditor into the style component of the page's head:
import {mdEditorStyle} from "./MdEditorStyle";
...
<Box id={props.uniqueId} sx={{ p: "1px", width: 1 }}>
<Helmet>
<style type="text/css">{mdEditorStyle}</style>
</Helmet>
<MDXEditor
markdown={value}
onChange={onChange}
...
The ./MdEditorStyle
file contains a string with the CSS from the @mdxeditor/editor/style.css
:
export const mdEditorStyle = `
:root, .light-theme {
--blue1: hsl(206, 100%, 99.2%);
--blue2: hsl(210, 100%, 98.0%);
--blue3: hsl(209, 100%, 96.5%);
...
`
I hope this helps
When I run it after building in a docker container, it looks like this:
@HWilliams64 this sounds like a build step issue. Your workaround is dangerous; the package may update its CSS contents, breaking your app in subtle ways. I may suggest that you debug what happens in the production step using your web inspector.
For anyone who finds this issue and experiences something similar: there's nothing special about the MDXEditor styling setup - it boils down to including a style file from an NPM package. The style file is declared as an export field. All modern bundlers understand that.
The mdx-editor organization includes several sample setups in Next.js (both routers), CRA, and Vite. If you have problems with the styling, compare your setup with the respective repo. If you still have troubles, isolate your problem down to a simple reproduction in a public repo and open a new issue. I should be able to help you if I can reproduce the problem on my side.
I am going to lock this issue as it turns into a catch-all problem of unrelated reports.
Hi, first of all, thanks for much for this repo, it's amazing! I tried using MDXEditor in my React project but couldn't figure out a way to style it. This is what it looks like when imported.
I'm using
I'm using MDXEditor inside a client component in NextJS. This is how I'm setting it up: