left-menu-mask.tsx 1.0 KB

12345678910111213141516171819202122232425262728293031
  1. import { memo, useEffect, useRef, useState } from 'react'
  2. import { useLayoutContext } from '../../../shared/context/layout-context'
  3. import useScopeValue from '../../../shared/hooks/use-scope-value'
  4. export default memo(function LeftMenuMask() {
  5. const { setLeftMenuShown } = useLayoutContext()
  6. const [editorTheme] = useScopeValue('settings.editorTheme')
  7. const [overallTheme] = useScopeValue('settings.overallTheme')
  8. const [original] = useState({ editorTheme, overallTheme })
  9. const maskRef = useRef<HTMLDivElement | null>(null)
  10. useEffect(() => {
  11. if (maskRef.current) {
  12. if (
  13. editorTheme !== original.editorTheme ||
  14. overallTheme !== original.overallTheme
  15. ) {
  16. maskRef.current.style.opacity = '0'
  17. }
  18. }
  19. }, [editorTheme, overallTheme, original])
  20. return (
  21. // eslint-disable-next-line jsx-a11y/click-events-have-key-events, jsx-a11y/no-static-element-interactions
  22. <div
  23. id="left-menu-mask"
  24. ref={maskRef}
  25. onClick={() => setLeftMenuShown(false)}
  26. />
  27. )
  28. })