|
| 1 | +/* eslint-disable @typescript-eslint/ban-ts-comment */ |
| 2 | + |
| 3 | +// TODO: remove eslint-disable and @ts-ignore rules |
| 4 | + |
| 5 | +import { Theme, useTheme } from '@material-ui/core' |
| 6 | + |
| 7 | +import { isFlagshipApp } from 'cozy-device-helper' |
| 8 | + |
| 9 | +import { isRsg } from '../hooks/useSetFlagshipUi/helpers' |
| 10 | +import { useSetFlagshipUI } from '../hooks/useSetFlagshipUi/useSetFlagshipUI' |
| 11 | +import { useCozyTheme } from '../providers/CozyTheme' |
| 12 | + |
| 13 | +const getBottomBackground = (theme: Theme): string => { |
| 14 | + const sidebar = document.getElementById('sidebar') |
| 15 | + |
| 16 | + return sidebar |
| 17 | + ? getComputedStyle(sidebar).getPropertyValue('background-color') |
| 18 | + : theme.palette.background.paper |
| 19 | +} |
| 20 | + |
| 21 | +const useHook = (): void => { |
| 22 | + const theme = useTheme() |
| 23 | + |
| 24 | + const { isLight } = useCozyTheme() |
| 25 | + |
| 26 | + useSetFlagshipUI( |
| 27 | + { |
| 28 | + bottomBackground: theme.palette.background.paper, |
| 29 | + // @ts-expect-error |
| 30 | + bottomTheme: isLight ? 'dark' : 'light', |
| 31 | + topOverlay: 'rgba(0, 0, 0, 0.5)', |
| 32 | + topBackground: theme.palette.background.paper, |
| 33 | + // @ts-expect-error |
| 34 | + topTheme: 'light' |
| 35 | + }, |
| 36 | + { |
| 37 | + bottomBackground: getBottomBackground(theme), |
| 38 | + bottomTheme: isLight ? 'dark' : 'light', |
| 39 | + topOverlay: 'transparent', |
| 40 | + topBackground: theme.palette.background.paper, |
| 41 | + topTheme: isLight ? 'dark' : 'light' |
| 42 | + }, |
| 43 | + 'cozy-ui/ActionMenu' |
| 44 | + ) |
| 45 | +} |
| 46 | + |
| 47 | +export const useActionMenuEffects = |
| 48 | + isFlagshipApp() || isRsg |
| 49 | + ? useHook |
| 50 | + : // eslint-disable-next-line @typescript-eslint/no-empty-function |
| 51 | + (): void => {} |
0 commit comments