diff --git a/docs/plugins/development/user-interface.md b/docs/plugins/development/user-interface.md new file mode 100644 index 000000000..a918eb185 --- /dev/null +++ b/docs/plugins/development/user-interface.md @@ -0,0 +1,14 @@ +# User Interface + +## Light & Dark Mode + +The NetBox user interface supports toggling between light and dark versions of the theme. If needed, a plugin can determine the currently active color theme by inspecting `window.localStorage['netbox-color-mode']`, which will indicate either `light` or `dark`. + +Additionally, when the color scheme is toggled by the user, a custom event `netbox.colorModeChanged` indicating the new scheme is dispatched. A plugin can listen for this event if needed to react to the change: + +```typescript +window.addEventListener('netbox.colorModeChanged', e => { + const customEvent = e as CustomEvent; + console.log('New color mode:', customEvent.detail.netboxColorMode); +}); +``` diff --git a/mkdocs.yml b/mkdocs.yml index 4e5f484c7..585c8448c 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -144,6 +144,7 @@ nav: - Search: 'plugins/development/search.md' - Event Types: 'plugins/development/event-types.md' - Data Backends: 'plugins/development/data-backends.md' + - User Interface: 'plugins/development/user-interface.md' - REST API: 'plugins/development/rest-api.md' - GraphQL API: 'plugins/development/graphql-api.md' - Background Jobs: 'plugins/development/background-jobs.md' diff --git a/netbox/project-static/dist/netbox.js b/netbox/project-static/dist/netbox.js index 9e2d6b383..ed5971014 100644 Binary files a/netbox/project-static/dist/netbox.js and b/netbox/project-static/dist/netbox.js differ diff --git a/netbox/project-static/dist/netbox.js.map b/netbox/project-static/dist/netbox.js.map index 0ba7a62d1..295f03aca 100644 Binary files a/netbox/project-static/dist/netbox.js.map and b/netbox/project-static/dist/netbox.js.map differ diff --git a/netbox/project-static/src/colorMode.ts b/netbox/project-static/src/colorMode.ts index 453617740..1d05c955d 100644 --- a/netbox/project-static/src/colorMode.ts +++ b/netbox/project-static/src/colorMode.ts @@ -43,6 +43,11 @@ function updateElements(targetMode: ColorMode): void { export function setColorMode(mode: ColorMode): void { storeColorMode(mode); updateElements(mode); + window.dispatchEvent( + new CustomEvent('netbox.colorModeChanged', { + detail: { netboxColorMode: mode }, + }), + ); } /** diff --git a/netbox/project-static/src/global.d.ts b/netbox/project-static/src/global.d.ts index d7244339a..5b75be1ca 100644 --- a/netbox/project-static/src/global.d.ts +++ b/netbox/project-static/src/global.d.ts @@ -79,3 +79,6 @@ type FormControls = HTMLInputElement | HTMLSelectElement | HTMLTextAreaElement; type ColorMode = 'light' | 'dark'; type ColorModePreference = ColorMode | 'none'; +type ColorModeData = { + netboxColorMode: ColorMode; +};