diff --git a/apps/remix-ide/src/app/tabs/theme-module.js b/apps/remix-ide/src/app/tabs/theme-module.js
index cc59695dbf..8b80ab6654 100644
--- a/apps/remix-ide/src/app/tabs/theme-module.js
+++ b/apps/remix-ide/src/app/tabs/theme-module.js
@@ -47,6 +47,7 @@ export class ThemeModule extends Plugin {
queryTheme = this.themes[queryTheme] ? queryTheme : null
let currentTheme = this._deps.config.get('settings/theme')
currentTheme = this.themes[currentTheme] ? currentTheme : null
+ this.currentThemeState = { queryTheme, currentTheme }
this.active = queryTheme || currentTheme || 'Dark'
this.forced = !!queryTheme
}
@@ -81,7 +82,7 @@ export class ThemeModule extends Plugin {
/**
* Init the theme
*/
- initTheme (callback) {
+ initTheme (callback) { // callback is setTimeOut in app.js which is always passed
if (this.active) {
const nextTheme = this.themes[this.active] // Theme
document.documentElement.style.setProperty('--theme', nextTheme.quality)
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 e75e246a05..af169f7b2b 100644
--- a/libs/remix-ui/settings/src/lib/remix-ui-settings.tsx
+++ b/libs/remix-ui/settings/src/lib/remix-ui-settings.tsx
@@ -23,10 +23,8 @@ export const RemixUiSettings = (props: RemixUiSettingsProps) => {
const [, dispatch] = useReducer(settingReducer, initialState)
const [state, dispatchToast] = useReducer(toastReducer, toastInitialState)
const [tokenValue, setTokenValue] = useState('')
- const [themeName, setThemeName] = useState('')
useEffect(() => {
- props._deps.themeModule.switchTheme()
const token = props.config.get('settings/gist-access-token')
if (token === undefined) {
props.config.set('settings/generate-contract-metadata', true)
@@ -35,7 +33,7 @@ export const RemixUiSettings = (props: RemixUiSettingsProps) => {
if (token) {
setTokenValue(token)
}
- }, [themeName, state.message])
+ }, [state.message])
useEffect(() => {
if (props.useMatomoAnalytics !== null) useMatomoAnalytics(props.config, props.useMatomoAnalytics, dispatch)
@@ -67,10 +65,10 @@ export const RemixUiSettings = (props: RemixUiSettingsProps) => {
useMatomoAnalytics(props.config, event.target.checked, dispatch)
}
- const onswitchTheme = (event, name) => {
- props._deps.themeModule.switchTheme(name)
- setThemeName(name)
- }
+ // const onswitchTheme = (event, name) => {
+ // props._deps.themeModule.switchTheme(name)
+ // setThemeName(name)
+ // }
const getTextClass = (key) => {
if (props.config.get(key)) {
@@ -159,18 +157,18 @@ export const RemixUiSettings = (props: RemixUiSettingsProps) => {
)
// eslint-disable-next-line @typescript-eslint/no-unused-vars
- const themes = () => {
- const themes = props._deps.themeModule.getThemes()
- if (themes) {
- return themes.map((aTheme, index) => (
-
- { onswitchTheme(event, aTheme.name) }} className="align-middle custom-control-input" name='theme' id={aTheme.name} data-id={`settingsTabTheme${aTheme.name}`} checked = {props._deps.themeModule.active === aTheme.name }/>
-
-
- )
- )
- }
- }
+ // const themes = () => {
+ // const themes = props._deps.themeModule.getThemes()
+ // if (themes) {
+ // return themes.map((aTheme, index) => (
+ //
+ // { onswitchTheme(event, aTheme.name) }} className="align-middle custom-control-input" name='theme' id={aTheme.name} data-id={`settingsTabTheme${aTheme.name}`} checked = {props._deps.themeModule.active === aTheme.name }/>
+ //
+ //
+ // )
+ // )
+ // }
+ // }
return (
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 ea239f9ee9..734a524d49 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,4 +1,5 @@
-import React from 'react'
+/* eslint-disable @typescript-eslint/no-explicit-any */
+import React, { useEffect, useRef, useState } from 'react'
import { ThemeModule } from '../../types/theme-module'
import './remix-ui-theme-module.module.css'
@@ -8,25 +9,50 @@ export interface 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 }/>
-
-
- )
- )
+ const [themeName, setThemeName] = useState('')
+
+ useEffect(() => {
+ themeModule.switchTheme()
+ }, [themeName, themeModule])
+
+ function ThemeHead () {
+ const [nextTheme, setNextTheme] = useState
()
+ const linkRef = useRef(null)
+ function initTheme (callback: () => void) {
+ // const theme = yo``
+ if (themeModule.active) {
+ setNextTheme(themeModule.themes[themeModule.active]) // Theme
+ document.documentElement.style.setProperty('--theme', nextTheme.quality)
}
- return
}
+ useEffect(() => {
+ const callback = () => {
+ setTimeout(() => {
+ document.body.removeChild(self._view.splashScreen)
+ self._view.el.style.visibility = 'visible'
+ }, 1500)
+ addEventListener('load', () => {
+ if (callback) callback()
+ })
+ document.head.insertBefore(linkRef.current, document.head.firstChild)
+ }, [])
+ return (
+
+ )
+ }
+
return (
Themes Module
-
Welcome to remix-ui-theme-module!
+ {themeModule.getThemes() ? themeModule.getThemes().map((theme, idx) => (
+
+ { themeModule.switchTheme(theme.name); setThemeName(theme.name) }} className="align-middle custom-control-input" name='theme' id={theme.name} data-id={`settingsTabTheme${theme.name}`} checked = {themeModule.active === theme.name }/>
+
+
+ )) : null
+ }
diff --git a/libs/remix-ui/theme-module/types/theme-module.d.ts b/libs/remix-ui/theme-module/types/theme-module.d.ts
index c293a80920..769faa7df9 100644
--- a/libs/remix-ui/theme-module/types/theme-module.d.ts
+++ b/libs/remix-ui/theme-module/types/theme-module.d.ts
@@ -2,6 +2,7 @@ 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 {
+ currentThemeState: Record;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
constructor(registry: any);
events: EventEmitter;
@@ -11,9 +12,9 @@ export class ThemeModule extends Plugin {
};
element: HTMLDivElement;
// eslint-disable-next-line @typescript-eslint/ban-types
- themes: {};
+ themes: {[key: string]: Theme};
// eslint-disable-next-line @typescript-eslint/no-explicit-any
- active: any;
+ active: string;
forced: boolean;
render(): HTMLDivElement;
renderComponent(): void;
@@ -22,7 +23,7 @@ export class ThemeModule extends Plugin {
currentTheme(): any;
/** Returns all themes as an array */
// eslint-disable-next-line @typescript-eslint/no-explicit-any
- getThemes(): any[];
+ getThemes(): Theme[];
/**
* Init the theme
*/
@@ -40,3 +41,5 @@ export class ThemeModule extends Plugin {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
fixInvert(image?: any): void;
}
+
+interface Theme { name: string, quality: string, url: string }