diff --git a/apps/remix-ide/src/app/tabs/theme-module.js b/apps/remix-ide/src/app/tabs/theme-module.js index 8558ad4da3..cc59695dbf 100644 --- a/apps/remix-ide/src/app/tabs/theme-module.js +++ b/apps/remix-ide/src/app/tabs/theme-module.js @@ -2,6 +2,10 @@ import { Plugin } from '@remixproject/engine' import { EventEmitter } from 'events' import QueryParams from '../../lib/query-params' import * as packageJson from '../../../../../package.json' +import { RemixUiThemeModule } from '@remix-ui/theme-module' +import ReactDOM from 'react-dom' +// eslint-disable-next-line no-use-before-define +import React from 'react' import yo from 'yo-yo' const _paq = window._paq = window._paq || [] @@ -33,6 +37,8 @@ export class ThemeModule extends Plugin { this._deps = { config: registry.get('config').api } + this.element = document.createElement('div') + this.element.setAttribute('id', 'themeModuleSection') this.themes = themes.reduce((acc, theme) => { theme.url = window.location.origin + window.location.pathname + theme.url return { ...acc, [theme.name]: theme } @@ -45,6 +51,23 @@ export class ThemeModule extends Plugin { this.forced = !!queryTheme } + onActivation () { + this.renderComponent() + } + + render () { + return this.element + } + + renderComponent () { + ReactDOM.render( + , + this.element + ) + } + /** Return the active theme */ currentTheme () { return this.themes[this.active] diff --git a/libs/remix-ui/settings/src/lib/remix-ui-settings.tsx b/libs/remix-ui/settings/src/lib/remix-ui-settings.tsx index aaf3cd2382..1baecef22a 100644 --- a/libs/remix-ui/settings/src/lib/remix-ui-settings.tsx +++ b/libs/remix-ui/settings/src/lib/remix-ui-settings.tsx @@ -7,6 +7,8 @@ import './remix-ui-settings.css' import { ethereumVM, generateContractMetadat, personal, textWrapEventAction, useMatomoAnalytics, saveTokenToast, removeTokenToast } from './settingsAction' import { initialState, toastInitialState, toastReducer, settingReducer } from './settingsReducer' import { Toaster } from '@remix-ui/toaster'// eslint-disable-line +import { RemixUiThemeModule } from '@remix-ui/theme-module' +import { ThemeModule } from 'libs/remix-ui/theme-module/types/theme-module' /* eslint-disable-next-line */ export interface RemixUiSettingsProps { @@ -14,6 +16,7 @@ export interface RemixUiSettingsProps { editor: any, _deps: any, useMatomoAnalytics: boolean + themeModule: ThemeModule } export const RemixUiSettings = (props: RemixUiSettingsProps) => { @@ -155,6 +158,7 @@ export const RemixUiSettings = (props: RemixUiSettingsProps) => { ) + // eslint-disable-next-line @typescript-eslint/no-unused-vars const themes = () => { const themes = props._deps.themeModule.getThemes() if (themes) { @@ -173,14 +177,15 @@ export const RemixUiSettings = (props: RemixUiSettingsProps) => { {state.message ? : null} {generalConfig()} {gistToken()} -
+ {/*
-
Themes
+
Themes Module
{themes()}
-
+
*/} + ) } diff --git a/libs/remix-ui/theme-module/src/lib/remix-ui-theme-module.tsx b/libs/remix-ui/theme-module/src/lib/remix-ui-theme-module.tsx index 035d8a0917..a168855dc3 100644 --- a/libs/remix-ui/theme-module/src/lib/remix-ui-theme-module.tsx +++ b/libs/remix-ui/theme-module/src/lib/remix-ui-theme-module.tsx @@ -1,14 +1,35 @@ +import { ThemeModule } from '../../types/theme-module'; import './remix-ui-theme-module.module.css'; /* eslint-disable-next-line */ -export interface RemixUiThemeModuleProps {} +export interface RemixUiThemeModuleProps { + themeModule: ThemeModule +} -export function RemixUiThemeModule(props: RemixUiThemeModuleProps) { +export function RemixUiThemeModule({ themeModule }: RemixUiThemeModuleProps) { + const themes = () => { + const themes = themeModule.getThemes() + if (themes) { + return themes.map((aTheme, index) => ( +
+ { themeModule.switchTheme(aTheme.name) }} className="align-middle custom-control-input" name='theme' id={aTheme.name} data-id={`settingsTabTheme${aTheme.name}`} checked = {themeModule.active === aTheme.name }/> + +
+ ) + ) + } + return + } return ( -
-

Welcome to remix-ui-theme-module!

-
- ); +
+
+
Themes Module
+
+

Welcome to remix-ui-theme-module!

+
+
+
+ ) } export default RemixUiThemeModule; diff --git a/libs/remix-ui/theme-module/types/theme-module.d.ts b/libs/remix-ui/theme-module/types/theme-module.d.ts new file mode 100644 index 0000000000..c293a80920 --- /dev/null +++ b/libs/remix-ui/theme-module/types/theme-module.d.ts @@ -0,0 +1,42 @@ +import { Plugin } from "@remixproject/engine/lib/abstract"; +import { EventEmitter } from "events"; +// eslint-disable-next-line @typescript-eslint/no-explicit-any +export class ThemeModule extends Plugin { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + constructor(registry: any); + events: EventEmitter; + _deps: { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + config: any; + }; + element: HTMLDivElement; + // eslint-disable-next-line @typescript-eslint/ban-types + themes: {}; + // eslint-disable-next-line @typescript-eslint/no-explicit-any + active: any; + forced: boolean; + render(): HTMLDivElement; + renderComponent(): void; + /** Return the active theme */ + // eslint-disable-next-line @typescript-eslint/no-explicit-any + currentTheme(): any; + /** Returns all themes as an array */ + // eslint-disable-next-line @typescript-eslint/no-explicit-any + getThemes(): any[]; + /** + * Init the theme + */ + // eslint-disable-next-line @typescript-eslint/no-explicit-any + initTheme(callback: any): void; + /** + * Change the current theme + * @param {string} [themeName] - The name of the theme + */ + switchTheme(themeName?: string): void; + /** + * fixes the invertion for images since this should be adjusted when we switch between dark/light qualified themes + * @param {element} [image] - the dom element which invert should be fixed to increase visibility + */ + // eslint-disable-next-line @typescript-eslint/no-explicit-any + fixInvert(image?: any): void; +}