-
-
Notifications
You must be signed in to change notification settings - Fork 8.6k
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
Support separate config for mermaid dark mode #10251
Comments
The API design is the easy part of implementing Mermaid light/dark mode support. We might as well do Keep in mind that we really want to move to server-rendered Mermaid diagrams (once available or through headless browser rendering). We don't want Mermaid in the client Docusaurus bundle (unlike now) and have layout shifts due to rendering diagrams client-side. See also:
In an ideal world, we'd want to only render one Mermaid diagram per color mode, and use something like CSS variables to theme it. In a less ideal world, we'd have to render the 2 diagrams at build time, append them both to the page, and depending on We really want to get rid of client-rendered layout shifts, and should avoid relying on React client-side code to choose which of the 2 diagrams to render, because until React hydration completes we might render the wrong diagram, or a spinner/placeholder. export function useMermaidConfig(): MermaidConfig {
const {colorMode} = useColorMode(); We use this at the moment, but to be honest it's not a great solution. And this React hook to get the
See also #7986 We could support what you request, but to be honest I'm afraid supporting it might make our task to have proper support (build time, no layout shifts) for simpler Mermaid use-cases might become harder if we add support for more advanced Mermaid use-cases. Do you think it could be the case? What is the main reason for us to have support for themed config/options? Please redirect your user requests to this issue so that we can understand better the context of this feature request. |
I have a working version here, without the docs changes. We can tweak to use
Completely agree. That was the first thing I checked when I first heard the requirement. But that's currently not possible due to how mermaid is implemented (we calculate related colors based on hex values passed in options/themes). I have a proposal to change that, but it will require a major overhaul of the theming engine. We are currently doing some refactorings on rendering which would make this a bit easier, but a proper solution is going to take some time.
This is a great alternative.
I would also love to have SSR, and we are making some initial steps to change our rendering pipeline to support SSR sometime in the far future. It is possible to render using headless browsers (in your case, at build time?), you can utilise mermaid-cli for it now.
I think the proposed approach of having two sets of configs would actually make it simpler in the case of SSR, as we can render both the light & dark images with corresponding configs. Currently, docusaurus supports light/dark mode partially, so users who need to customise the themes for light/dark mode don't have a choice. By extending the config to support dark and light, we can offer full customisation for both, whether we use CSR or SSR. One downside of this approach is that the users will have to duplicate options that are common for both themes. We could handle it in a few ways, but it'll add more complexity internally.
Currently, to support dark & light mode diagrams that match the look and feel of the website. Who plans to use it exactly, and how? The current request came from @altitude, as part of their work on updating the theme on their doc site. What is the expected output? The mermaid diagrams on their site matches the overall color scheme on light and dark mode. Screen.Recording.2024-06-27.at.12.48.13.PM.mov |
Have you read the Contributing Guidelines on issues?
Description
Currently, there is support to use different themes based on light/dark mode, but the options passed is the same.
So if a user wants to set different theme colors for light/dark mode, that is not possible.
Has this been requested on Canny?
No response
Motivation
This feature was requested in Mermaid's discord by users.
Upon further investigation, allowing an extra config option like the theme would enable users to pass different options based on the light/dark mode.
This would help users who are customising the diagram using themeVariables.
API design
Current type
Proposed option 1
This is a non-breaking change, but it differs from the pattern used in
theme
Proposed option 2
By changing the key to
config
, it aligns with the typemermaidAPI.Config
, and also allows us to retain options as a fallback in case config is not provided. This also aligns with the pattern followed intheme
.or, to ensure only one of config/options is present.
Have you tried building it?
Yes, by changing
useMermaidConfig
to the following, whereoptions
is used as a fallback in case config key is not provided.Self-service
The text was updated successfully, but these errors were encountered: