pull/1964/head
bunsenstraat 3 years ago
parent 77014377e3
commit ad0d26ecea
  1. 129
      libs/remix-ui/vertical-icons-panel/src/lib/remix-ui-vertical-icons-panel.tsx

@ -1,5 +1,3 @@
/* eslint-disable no-use-before-define */
/* eslint-disable @typescript-eslint/no-unused-vars */
import React, { import React, {
Fragment, Fragment,
useEffect, useEffect,
@ -7,16 +5,16 @@ import React, {
useRef, useRef,
useState useState
} from 'react' } from 'react'
import { Plugin } from '@remixproject/engine'
import './remix-ui-vertical-icons-panel.css' import './remix-ui-vertical-icons-panel.css'
import OtherIcons from './components/OtherIcons' import IconList from './components/IconList'
import { VerticalIcons } from '../../types/vertical-icons-panel'
import Home from './components/Home' import Home from './components/Home'
import Settings from './components/Settings'
import { RequiredSection } from './components/RequiredSection'
import { verticalScrollReducer } from './reducers/verticalScrollReducer' import { verticalScrollReducer } from './reducers/verticalScrollReducer'
import { Chevron } from './components/Chevron'
import { IconRecord } from './types'
export interface RemixUiVerticalIconsPanelProps { export interface RemixUiVerticalIconsPanelProps {
verticalIconsPlugin: VerticalIcons verticalIconsPlugin: Plugin
icons: IconRecord[]
} }
const initialState = { const initialState = {
@ -25,13 +23,13 @@ const initialState = {
scrollState: false scrollState: false
} }
export function RemixUiVerticalIconsPanel ({ const RemixUiVerticalIconsPanel = ({
verticalIconsPlugin verticalIconsPlugin, icons
}: RemixUiVerticalIconsPanelProps) { }: RemixUiVerticalIconsPanelProps) => {
const scrollableRef = useRef<any>() const scrollableRef = useRef<any>()
const iconPanelRef = useRef<any>() const iconPanelRef = useRef<any>()
const [activateScroll, dispatchScrollAction] = useReducer(verticalScrollReducer, initialState) const [activateScroll, dispatchScrollAction] = useReducer(verticalScrollReducer, initialState)
const [theme, setTheme] = useState<string>('dark')
useEffect(() => { useEffect(() => {
const evaluateScrollability = (evt: any) => { const evaluateScrollability = (evt: any) => {
dispatchScrollAction({ dispatchScrollAction({
@ -44,73 +42,22 @@ export function RemixUiVerticalIconsPanel ({
}) })
} }
addEventListener('resize', evaluateScrollability) addEventListener('resize', evaluateScrollability)
return () => { return () => {
removeEventListener('resize', evaluateScrollability) removeEventListener('resize', evaluateScrollability)
} }
}) })
function onThemeChanged (themeType: any) {
const invert = themeType === 'dark' ? 1 : 0
// @ts-ignore
const active = iconPanelRef.current.querySelector('.active')
if (active) {
// @ts-ignore
const image = iconPanelRef.current.querySelector('.remixui_image')
image.style.setProperty('filter', `invert(${invert})`)
}
}
function removeActive () {
// @ts-ignore
const images = iconPanelRef.current.querySelectorAll('.remixui_image')
images.forEach(function (im: any) {
im.style.setProperty('filter', 'invert(0.5)')
})
// remove active
// @ts-ignore
const currentActive = iconPanelRef.current.querySelector('.active')
if (currentActive) {
currentActive.classList.remove('active')
}
}
function addActive (name: string) {
if (name === 'home') return
const themeType = verticalIconsPlugin.registry.get('themeModule').api.currentTheme().quality
const invert = themeType === 'dark' ? 1 : 0
const brightness = themeType === 'dark' ? '150' : '0' // should be >100 for icons with color
// @ts-ignore
const nextActive = iconPanelRef.current.querySelector(`[plugin="${name}"]`)
if (nextActive) {
const image = nextActive.querySelector('.remixui_image')
nextActive.classList.add('active')
image.style.setProperty('filter', `invert(${invert}) grayscale(1) brightness(${brightness}%)`)
}
}
async function itemContextAction (e: any, name: string, documentation: string) {
verticalIconsPlugin.appManager.deactivatePlugin(name)
verticalIconsPlugin.renderComponent()
}
useEffect(() => { useEffect(() => {
const themeModule = verticalIconsPlugin.registry.get('themeModule').api verticalIconsPlugin.on('theme', 'themeChanged', (th: any) => {
themeModule.events.on('themeChanged', (theme: any) => { setTheme(th.quality)
onThemeChanged(theme.quality)
}) })
return () => { return () => {
themeModule.events.off('themeChanged') verticalIconsPlugin.off('theme', 'themeChanged')
} }
}, []) }, [])
useEffect(() => { async function itemContextAction (e: any, name: string, documentation: string) {
if (verticalIconsPlugin.targetProfileForChange && verticalIconsPlugin.targetProfileForChange.udapp) { verticalIconsPlugin.call('manager', 'deactivatePlugin', name)
const doWalkThroughEvent = new Event('doWalkThrough') }
document.dispatchEvent(doWalkThroughEvent)
}
}, [Object.keys(verticalIconsPlugin.targetProfileForChange).length])
return ( return (
<div id="iconsP" className="h-100"> <div id="iconsP" className="h-100">
@ -118,13 +65,22 @@ export function RemixUiVerticalIconsPanel ({
<Home verticalIconPlugin={verticalIconsPlugin} /> <Home verticalIconPlugin={verticalIconsPlugin} />
<div className={scrollableRef.current && scrollableRef.current.scrollHeight > scrollableRef.current.clientHeight <div className={scrollableRef.current && scrollableRef.current.scrollHeight > scrollableRef.current.clientHeight
? 'remixui_default-icons-container remixui_requiredSection' : activateScroll && activateScroll.scrollState ? 'remixui_default-icons-container remixui_requiredSection' : 'remixui_requiredSection'}> ? 'remixui_default-icons-container remixui_requiredSection' : activateScroll && activateScroll.scrollState ? 'remixui_default-icons-container remixui_requiredSection' : 'remixui_requiredSection'}>
<RequiredSection <IconList
theme={theme}
icons={icons.filter((p) => p.isRequired)}
verticalIconsPlugin={verticalIconsPlugin} verticalIconsPlugin={verticalIconsPlugin}
addActive={addActive}
removeActive={removeActive}
itemContextAction={itemContextAction} itemContextAction={itemContextAction}
scrollableRef={scrollableRef}
/> />
{
scrollableRef.current && scrollableRef.current.scrollHeight > scrollableRef.current.clientHeight
? (
<Chevron
direction='up'
divElementRef={scrollableRef}
cssRule={'fa fa-chevron-up remixui_icon-chevron mt-0 mb-0 ml-1 pl-3'}
/>
) : null
}
</div> </div>
<div <div
id="remixuiScrollable" id="remixuiScrollable"
@ -133,26 +89,29 @@ export function RemixUiVerticalIconsPanel ({
: activateScroll && activateScroll.scrollState ? 'remixui_default-icons-container remixui_scrollable-container remixui_scrollbar remixui_hide-scroll' : 'remixui_scrollable-container remixui_scrollbar remixui_hide-scroll'} : activateScroll && activateScroll.scrollState ? 'remixui_default-icons-container remixui_scrollable-container remixui_scrollbar remixui_hide-scroll' : 'remixui_scrollable-container remixui_scrollbar remixui_hide-scroll'}
ref={scrollableRef} ref={scrollableRef}
> >
<OtherIcons <IconList
theme={theme}
icons={icons.filter((p) => {return !p.isRequired && p.profile.name !== 'settings'})}
verticalIconsPlugin={verticalIconsPlugin} verticalIconsPlugin={verticalIconsPlugin}
addActive={addActive}
removeActive={removeActive}
itemContextAction={itemContextAction} itemContextAction={itemContextAction}
/> />
</div> </div>
{verticalIconsPlugin.targetProfileForChange && <div>
Object.keys(verticalIconsPlugin.targetProfileForChange).length ? ( { scrollableRef.current && scrollableRef.current.scrollHeight > scrollableRef.current.clientHeight ? (<Chevron
<Fragment> divElementRef={scrollableRef}
<Settings direction='down'
cssRule={'fa fa-chevron-down remixui_icon-chevron mt-0 mb-0 ml-1 pl-3'}
/>) : null }
<IconList
theme={theme}
icons={icons.filter((p) => p.profile.name === 'settings')}
verticalIconsPlugin={verticalIconsPlugin} verticalIconsPlugin={verticalIconsPlugin}
addActive={addActive}
removeActive={removeActive}
itemContextAction={itemContextAction} itemContextAction={itemContextAction}
scrollableRef={scrollableRef}
/> />
</Fragment> </div>
) : null}
</div> </div>
</div> </div>
) )
} }
export default RemixUiVerticalIconsPanel

Loading…
Cancel
Save