refactor(shell): move theme definition to its own file

This commit is contained in:
Jeremy Kahn 2024-06-10 08:29:00 -05:00
parent 56dbbf2665
commit dc78137702
2 changed files with 26 additions and 12 deletions

View File

@ -8,7 +8,7 @@ import {
useState,
} from 'react'
import CssBaseline from '@mui/material/CssBaseline'
import { ThemeProvider, createTheme } from '@mui/material/styles'
import { ThemeProvider } from '@mui/material/styles'
import Box from '@mui/material/Box'
import Typography from '@mui/material/Typography'
import { AlertColor } from '@mui/material/Alert'
@ -45,6 +45,7 @@ import {
EnvironmentUnsupportedDialog,
isEnvironmentSupported,
} from './EnvironmentUnsupportedDialog'
import { useShellTheme } from './useShellTheme'
export interface ShellProps extends PropsWithChildren {
userPeerId: string
@ -57,17 +58,7 @@ export const Shell = ({ appNeedsUpdate, children, userPeerId }: ShellProps) => {
const { getUserSettings, updateUserSettings } = useContext(SettingsContext)
const isEmbedded = queryParams.get(QueryParamKeys.IS_EMBEDDED) !== null
const { colorMode } = getUserSettings()
const theme = useMemo(
() =>
createTheme({
palette: {
mode: colorMode,
},
}),
[colorMode]
)
const theme = useShellTheme()
const [windowWidth] = useWindowSize()
const defaultSidebarsOpen = windowWidth >= theme.breakpoints.values.lg

View File

@ -0,0 +1,23 @@
import { SettingsContext } from 'contexts/SettingsContext'
import { useContext, useMemo } from 'react'
import { createTheme } from '@mui/material/styles'
export const useShellTheme = () => {
const { getUserSettings } = useContext(SettingsContext)
const { colorMode } = getUserSettings()
const theme = useMemo(
() =>
// NOTE: You can make theme customizations here. It is recommended to use
// the default theme viewer as a reference:
// https://mui.com/material-ui/customization/default-theme/
createTheme({
palette: {
mode: colorMode,
},
}),
[colorMode]
)
return theme
}