You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
UX: create mechanism for themes to provide multiple variants #5534
@bonanitech this will be of interest to you. A common pattern is for a theme to have both light and dark equivalents. The idea here is to make it easy for a plugin to bundle both and allow the user to switch between them within the editor.
Any thoughts/ideas/suggestions on this are welcome.
How are you planning to implement this? Based on the user's operating system setting for light/dark mode (using prefers-color-scheme), through an option in the settings, or maybe a different approach?
The first option seems easier to me as it only depends on CSS. I tried implementing this in my plugin some time ago, and it worked well; the challenge was figuring out how to switch the Monaco and Mermaid themes dynamically.
Most websites use a mix of the first and second options, where users can select a specific theme or have it synced with the OS.
@bonanitech at this stage, I don't have a concrete plan for it. But this ultimate goal is for the user to be able to pick between light/dark - if the theme plugin provides them.
I have not yet looked at how a theme would provide both variants, and how we'd apply them without requiring a full reload of the editor - but doing it via a top-level CSS class seems the right sort of approach. I had not yet thought about monaco/mermaid at all; so any thoughts you have there would be welcome.
I have not yet looked at how a theme would provide both variants, and how we'd apply them without requiring a full reload of the editor - but doing it via a top-level CSS class seems the right sort of approach.
Load Node-RED with the theme below and then switch your OS between light and dark modes. You'll see the NR editor changing its colors immediately, no need to reload.
The code includes light (default) and dark variations.
:root{/* Light variation */}@media(prefers-color-scheme: dark){:root{/* Dark variation */}}
By default, the light variation is used. If the OS is set to dark mode, @media (prefers-color-scheme: dark) tells the browser to use the dark variation.
We need a way for a theme to declare that it provides light/dark schemes within the single theme. This then allows the editor to provide the choice of auto/light/dark. If a theme doesn't declare its schemes, then the editor doesn't show the choice and the user gets the theme as-is.
With the current work to introduce a dark theme to the core, the editor toggles the nr-theme-dark class on the root html element based on the user selection. A theme that provides both light and dark should scope the dark theme to this class.
The call to registerPlugin should then include a schemes property:
The schemes property, if set, should list the colour schemes the plugin includes. If it lists both light and dark, then the editor will allow the user to select (or auto select). If it just lists one, then the editor will apply that one; meaning if it is dark then nr-theme-dark will be applied.
If it doesn't include the schemes property, no option will be shown to the user and the css will just be applied as-is - how it works today.
@bonanitech the current approach doesn't require the media selectors - the editor will apply the nr-theme-dark class based on the user's preference. That preference can be to use the browser's preferred scheme, or the user can override with light or dark explicitly.
html {
/* light variation */
}
html.nr-theme-dark {
/* dark variation */
}
I couldn't think of a clean way to determine if it provides both light and dark. We'd also need to be able to examine just the css from the theme to see if that selector existed as it would exist in the base theme that is already loaded - not so familiar with the available apis for working at this level.
Allowing the user to pick between themes (rather than just variants within the theme) is a much more complicated piece of work and not in scope for this iteration.
Valid entries: 'light', 'dark'. Anything else is ignored.
Editor Behavior
schemes
Selector
nr-theme-dark
absent
hidden
not managed (theme renders as-is)
['light', 'dark']
shown
toggled per user choice (auto/light/dark)
['dark']
hidden
forced on
['light']
hidden
forced off
'auto' follows the OS prefers-color-scheme live.
Limitations
When the editor manages the scheme, Monaco swaps vs/vs-dark and Mermaid swaps default/dark — per-scheme overrides aren't part of this API. The plugin's monacoOptions / mermaid keys still load once but don't switch with the scheme. A richer per-scheme block (variants) is the natural follow-up if needed.
Manual Test Plan
All tests passed!
Case 1 — no plugin active
Comment out theme: in settings.js (or set theme: ""). Restart.
Settings → View → "Dark theme" dropdown is visible
Choose dark → built-in dark applies (nr-theme-dark on <html>)
Choose light → nr-theme-dark removed
Choose auto with OS in dark mode → dark applies; flips live when OS toggles
Regression: with view-dark-theme previously set to dark in localStorage, reload — dropdown still works
Case 2 — plugin without schemes
Edit index.js: remove the schemes line. Restart.
Dropdown is hidden
nr-theme-dark is never present on <html>, regardless of prior view-dark-theme localStorage value
Theme CSS renders as-is (header is blue — light rules apply)
Activity
knolleary commentedon Mar 9, 2026
@bonanitech this will be of interest to you. A common pattern is for a theme to have both light and dark equivalents. The idea here is to make it easy for a plugin to bundle both and allow the user to switch between them within the editor.
Any thoughts/ideas/suggestions on this are welcome.
bonanitech commentedon Mar 9, 2026
Thanks for the heads up, Nick.
How are you planning to implement this? Based on the user's operating system setting for light/dark mode (using
prefers-color-scheme), through an option in the settings, or maybe a different approach?The first option seems easier to me as it only depends on CSS. I tried implementing this in my plugin some time ago, and it worked well; the challenge was figuring out how to switch the Monaco and Mermaid themes dynamically.
Most websites use a mix of the first and second options, where users can select a specific theme or have it synced with the OS.
knolleary commentedon Mar 9, 2026
@bonanitech at this stage, I don't have a concrete plan for it. But this ultimate goal is for the user to be able to pick between light/dark - if the theme plugin provides them.
I have not yet looked at how a theme would provide both variants, and how we'd apply them without requiring a full reload of the editor - but doing it via a top-level CSS class seems the right sort of approach. I had not yet thought about monaco/mermaid at all; so any thoughts you have there would be welcome.
bonanitech commentedon Mar 9, 2026
Load Node-RED with the theme below and then switch your OS between light and dark modes. You'll see the NR editor changing its colors immediately, no need to reload.
light.dark.mov
knolleary commentedon Mar 9, 2026
@bonanitech to save me picking through it all, can you give a quick explanation how that is working?
dceejay commentedon Mar 9, 2026
just ask claude to explain it ;-)
bonanitech commentedon Mar 9, 2026
The code includes light (default) and dark variations.
By default, the light variation is used. If the OS is set to dark mode,
@media (prefers-color-scheme: dark)tells the browser to use the dark variation.bonanitech commentedon Mar 23, 2026
This would probably be better.
And a dropbox in the settings with the following options:
color-scheme: lightcolor-scheme: darkknolleary commentedon Apr 28, 2026
We need a way for a theme to declare that it provides light/dark schemes within the single theme. This then allows the editor to provide the choice of auto/light/dark. If a theme doesn't declare its schemes, then the editor doesn't show the choice and the user gets the theme as-is.
With the current work to introduce a dark theme to the core, the editor toggles the
nr-theme-darkclass on the roothtmlelement based on the user selection. A theme that provides both light and dark should scope the dark theme to this class.The call to
registerPluginshould then include aschemesproperty:The
schemesproperty, if set, should list the colour schemes the plugin includes. If it lists both light and dark, then the editor will allow the user to select (or auto select). If it just lists one, then the editor will apply that one; meaning if it isdarkthennr-theme-darkwill be applied.If it doesn't include the
schemesproperty, no option will be shown to the user and the css will just be applied as-is - how it works today.knolleary commentedon Apr 28, 2026
@bonanitech would appreciate your input on this as its the approach we'll be working on this week
bonanitech commentedon Apr 28, 2026
What would be the content of
theme.css(with variations) in this case? Something like this?knolleary commentedon Apr 28, 2026
@bonanitech the current approach doesn't require the media selectors - the editor will apply the
nr-theme-darkclass based on the user's preference. That preference can be to use the browser's preferred scheme, or the user can override with light or dark explicitly.bonanitech commentedon Apr 28, 2026
I wonder if the
schemesproperty is really necessary. A simple check to see if thehtml.nr-theme-darkselector exists in the CSS would do (I think).Unless there are plans to support themes with more than two variations.
knolleary commentedon Apr 28, 2026
I couldn't think of a clean way to determine if it provides both light and dark. We'd also need to be able to examine just the css from the theme to see if that selector existed as it would exist in the base theme that is already loaded - not so familiar with the available apis for working at this level.
bonanitech commentedon Apr 28, 2026
I just had a crazy thought. What if the theme selector worked like GitHub's, where the user decides which theme is used for each
color-scheme?knolleary commentedon Apr 28, 2026
Allowing the user to pick between themes (rather than just variants within the theme) is a much more complicated piece of work and not in scope for this iteration.
n-lark commentedon Apr 28, 2026
Theme Schemes Plugin API
PR here.
Lets a theme plugin declare which color schemes it provides so the editor can offer Auto/Light/Dark.
Plugin Declaration
Valid entries:
'light','dark'. Anything else is ignored.Editor Behavior
schemesnr-theme-dark['light', 'dark']['dark']['light']'auto'follows the OSprefers-color-schemelive.Limitations
When the editor manages the scheme, Monaco swaps
vs/vs-darkand Mermaid swapsdefault/dark— per-scheme overrides aren't part of this API. The plugin'smonacoOptions/mermaidkeys still load once but don't switch with the scheme. A richer per-scheme block (variants) is the natural follow-up if needed.Manual Test Plan
All tests passed!
Case 1 — no plugin active
Comment out
theme:insettings.js(or settheme: ""). Restart.dark→ built-in dark applies (nr-theme-darkon<html>)light→nr-theme-darkremovedautowith OS in dark mode → dark applies; flips live when OS togglesview-dark-themepreviously set todarkin localStorage, reload — dropdown still worksCase 2 — plugin without
schemesEdit
index.js: remove theschemesline. Restart.nr-theme-darkis never present on<html>, regardless of priorview-dark-themelocalStorage valueCase 3 —
schemes: ['light', 'dark']Edit
index.js:schemes: ['light', 'dark']. Restart.dark→ header turns purple,nr-theme-darkpresentlight→ header turns blue,nr-theme-darkabsentautowith OS in dark → header purpledark, reload — still dark on first paint (small FOUC is expected)vs-darkwhen dark,vswhen lightmermaidblock — diagram re-themes when switchingCase 4 —
schemes: ['dark']Edit
index.js:schemes: ['dark']. Restart.nr-theme-darkon)view-dark-themelocalStorage value is'light'Case 5 —
schemes: ['light']Edit
index.js:schemes: ['light']. Restart.nr-theme-darkabsent)view-dark-themelocalStorage value is'dark'knolleary commentedon Apr 29, 2026
Closed via #5659