diff --git a/docs/extensions/capabilities/styling.md b/docs/extensions/capabilities/styling.md index e4d001b5a3..236e8be120 100644 --- a/docs/extensions/capabilities/styling.md +++ b/docs/extensions/capabilities/styling.md @@ -104,38 +104,38 @@ A complete list of themable colors can be found in the [Color Reference](../colo When the light theme is active, the `
` element gets a "theme-light" class, or: ``. If the class isn't there, the theme defaults to dark. The active theme can be changed in the **Preferences** page:  -Currently, there is no prescribed way of detecting changes to the theme in JavaScript. [This issue](https://github.com/lensapp/lens/issues/1336) has been raised to resolve this problem. In the meantime, you can use a [MutationObserver](https://developer.mozilla.org/en-US/docs/Web/API/MutationObserver) in order to observe the `` element's `class` attribute in order to see if the "theme-light" class gets added to it: +There is a way of detect active theme and its changes in JS. [MobX observer function/decorator](https://github.com/mobxjs/mobx-react#observercomponent) can be used for this purpose. -```javascript -... - useEffect(function () { - const observer = new MutationObserver(function (mutations: MutationRecord[]) { - mutations.forEach((mutation: MutationRecord) => { - if (mutation.type === 'attributes' && mutation.attributeName === 'class') { - if ((mutation.target as HTMLElement).classList.contains('theme-light')) { - // theme is LIGHT - } else { - // theme is DARK - } - } - }); - }); +```js +import React from "react" +import { observer } from "mobx-react" +import { App, Component, Theme } from "@k8slens/extensions"; - observer.observe(document.body, { - attributes: true, - attributeFilter: ['class'], - }); - - return function () { - observer.disconnect(); - }; - }, []); // run once on mount -... +@observer +export class SupportPage extends React.Component { + render() { + return ( +