fixed settings icon theme change bug

pull/5370/head
Joseph Izang 3 years ago
parent 55ddc6da0d
commit edcb1e18d7
  1. 9
      apps/remix-ide/src/app/components/vertical-icons.js
  2. 37
      libs/remix-ui/vertical-icons-panel/src/lib/components/Settings.tsx
  3. 3
      libs/remix-ui/vertical-icons-panel/src/lib/remix-ui-vertical-icons-panel.tsx

@ -163,6 +163,15 @@ export class VerticalIcons extends Plugin {
this.events.emit('showContent', name) this.events.emit('showContent', name)
} }
onThemeChanged (themeType) {
const invert = themeType === 'dark' ? 1 : 0
const active = this.view.querySelector('.active')
if (active) {
const image = active.querySelector('.image')
image.style.setProperty('filter', `invert(${invert})`)
}
}
/** /**
* Toggles the side panel for plugin * Toggles the side panel for plugin
* @param {string} name Name of profile of the module to activate * @param {string} name Name of profile of the module to activate

@ -1,7 +1,7 @@
/* eslint-disable no-use-before-define */ /* eslint-disable no-use-before-define */
// eslint-disable-next-line @typescript-eslint/no-unused-vars // eslint-disable-next-line @typescript-eslint/no-unused-vars
import { VerticalIcons } from 'libs/remix-ui/vertical-icons-panel/types/vertical-icons-panel' import { VerticalIcons } from 'libs/remix-ui/vertical-icons-panel/types/vertical-icons-panel'
import React, { useEffect } from 'react' import React, { useEffect, useRef } from 'react'
import { Chevron } from './Chevron' import { Chevron } from './Chevron'
import Icon from './Icon' import Icon from './Icon'
@ -11,25 +11,30 @@ interface SettingsProps {
addActive: (name: string) => void addActive: (name: string) => void
removeActive: () => void removeActive: () => void
scrollableRef: React.MutableRefObject<any> scrollableRef: React.MutableRefObject<any>
onThemeChanged: (themeType: any) => void
} }
// eslint-disable-next-line @typescript-eslint/no-unused-vars function Settings ({ scrollableRef, verticalIconsPlugin, itemContextAction, addActive, removeActive }: SettingsProps) {
function Settings ({ scrollableRef, verticalIconsPlugin, itemContextAction, addActive, removeActive, onThemeChanged }: SettingsProps) { const settingsRef = useRef(null)
useEffect(() => { function onThemeChanged (themeType: any) {
// const themeModule = verticalIconsPlugin.registry.get('themeModule').api const invert = themeType === 'dark' ? 1 : 0
// themeModule.events.on('themeChanged', (theme: any) => { // @ts-ignore
// onThemeChanged(theme.quality) const active = settingsRef.current.querySelector('.active')
// }) if (active) {
return () => { // @ts-ignore
document.addEventListener('themeChanged', (theme: any) => { const image = settingsRef.current.querySelector('.remixui_image')
// onThemeChanged(theme.quality) image.style.setProperty('filter', `invert(${invert})`)
console.log('this is what theme contains', theme)
})
} }
}) }
useEffect(() => {
const themeModule = verticalIconsPlugin.registry.get('themeModule').api
themeModule.events.on('themeChanged', (theme: any) => {
onThemeChanged(theme.quality)
console.log('There was a theme change and is caught in settings. This is the theme payload ', theme)
})
}, [])
return ( return (
<div id="settingsIcons" data-id="vertialIconsSettingsIcons"> <div id="settingsIcons" data-id="vertialIconsSettingsIcons" ref={settingsRef}>
<Chevron <Chevron
divElementRef={scrollableRef} divElementRef={scrollableRef}
cssRule={'fa fa-chevron-down remixui_icon-chevron mt-0 mb-0 ml-1 pl-3'} cssRule={'fa fa-chevron-down remixui_icon-chevron mt-0 mb-0 ml-1 pl-3'}

@ -76,6 +76,7 @@ export function RemixUiVerticalIconsPanel ({
const themeModule = verticalIconsPlugin.registry.get('themeModule').api const themeModule = verticalIconsPlugin.registry.get('themeModule').api
themeModule.events.on('themeChanged', (theme: any) => { themeModule.events.on('themeChanged', (theme: any) => {
onThemeChanged(theme.quality) onThemeChanged(theme.quality)
console.log('There was a theme change. This is the theme payload ', theme)
}) })
}, []) }, [])
@ -83,6 +84,7 @@ export function RemixUiVerticalIconsPanel ({
const themeModule = verticalIconsPlugin.registry.get('themeModule').api const themeModule = verticalIconsPlugin.registry.get('themeModule').api
themeModule.events.on('themeChanged', (theme: any) => { themeModule.events.on('themeChanged', (theme: any) => {
onThemeChanged(theme.quality) onThemeChanged(theme.quality)
console.log('There was a theme change. This is the theme payload ', theme)
}) })
}, []) }, [])
@ -130,7 +132,6 @@ export function RemixUiVerticalIconsPanel ({
removeActive={removeActive} removeActive={removeActive}
itemContextAction={itemContextAction} itemContextAction={itemContextAction}
scrollableRef={scrollableRef} scrollableRef={scrollableRef}
onThemeChanged={onThemeChanged}
/> />
</Fragment> </Fragment>
) : null} ) : null}

Loading…
Cancel
Save