Skip to content

Commit 6e55348

Browse files
committed
Merge remote-tracking branch 'origin/main' into APL-1200
2 parents 76f231e + 49fd27b commit 6e55348

File tree

6 files changed

+59
-21
lines changed

6 files changed

+59
-21
lines changed

src/components/AccountPopover.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ export default function AccountPopover({ email }: Props) {
6161
p: 0,
6262
mt: 1.5,
6363
ml: 0.75,
64+
width: 300,
6465
'& .MuiMenuItem-root': {
6566
typography: 'body2',
6667
borderRadius: 0.75,

src/components/SettingMode.tsx

Lines changed: 33 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// @mui
22
import { styled } from '@mui/material/styles'
3-
import { CardActionArea, Grid, RadioGroup } from '@mui/material'
3+
import { CardActionArea, Grid, RadioGroup, Tooltip } from '@mui/material'
44
import useSettings from 'hooks/useSettings'
55
//
66
import Iconify from './Iconify'
@@ -9,7 +9,7 @@ import BoxMask from './BoxMask'
99
// ----------------------------------------------------------------------
1010

1111
const BoxStyle = styled(CardActionArea)(({ theme }) => ({
12-
height: 72,
12+
aspectRatio: '1',
1313
display: 'flex',
1414
alignItems: 'center',
1515
justifyContent: 'center',
@@ -23,26 +23,43 @@ const BoxStyle = styled(CardActionArea)(({ theme }) => ({
2323
export default function SettingMode() {
2424
const { themeMode, onChangeMode } = useSettings()
2525

26+
const modes = ['light', 'dark', 'system']
27+
const icons = ['ph:sun-duotone', 'ph:moon-duotone', 'ph:monitor-duotone']
28+
29+
const getBackgroundColor = (mode: string) => {
30+
if (mode === 'light') return 'common.white'
31+
if (mode === 'dark') return 'grey.800'
32+
return 'grey.600'
33+
}
34+
35+
const getModeLabel = (mode: string) => {
36+
return mode.charAt(0).toUpperCase() + mode.slice(1)
37+
}
38+
2639
return (
2740
<RadioGroup name='themeMode' value={themeMode} onChange={onChangeMode}>
2841
<Grid dir='ltr' container spacing={2.5}>
29-
{['light', 'dark'].map((mode, index) => {
42+
{modes.map((mode, index) => {
3043
const isSelected = themeMode === mode
3144

3245
return (
33-
<Grid key={mode} item xs={6}>
34-
<BoxStyle
35-
sx={{
36-
bgcolor: mode === 'light' ? 'common.white' : 'grey.800',
37-
...(isSelected && {
38-
color: 'primary.main',
39-
boxShadow: (theme) => theme.customShadows.z20,
40-
}),
41-
}}
42-
>
43-
<Iconify icon={index === 0 ? 'ph:sun-duotone' : 'ph:moon-duotone'} width={28} height={28} />
44-
<BoxMask value={mode} />
45-
</BoxStyle>
46+
<Grid key={mode} item xs={4}>
47+
<Tooltip title={getModeLabel(mode)} arrow placement='bottom'>
48+
<span>
49+
<BoxStyle
50+
sx={{
51+
bgcolor: getBackgroundColor(mode),
52+
...(isSelected && {
53+
color: 'primary.main',
54+
boxShadow: (theme) => theme.customShadows.z20,
55+
}),
56+
}}
57+
>
58+
<Iconify icon={icons[index]} width={28} height={28} />
59+
<BoxMask value={mode} />
60+
</BoxStyle>
61+
</span>
62+
</Tooltip>
4663
</Grid>
4764
)
4865
})}

src/components/SettingsType.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ type ColorVariants = {
1212
}
1313

1414
export type ThemeView = 'platform' | 'team'
15-
export type ThemeMode = 'light' | 'dark'
15+
export type ThemeMode = 'light' | 'dark' | 'system'
1616
export type ThemeContrast = 'default' | 'bold'
1717
export type ThemeLayout = 'vertical' | 'horizontal'
1818
export type ThemeColorPresets = 'default' | 'purple' | 'cyan' | 'blue' | 'orange' | 'red'

src/config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export const cookiesKey = {
4040

4141
export const defaultSettings: SettingsValueProps = {
4242
themeView: 'platform',
43-
themeMode: 'dark',
43+
themeMode: 'system',
4444
themeContrast: 'default',
4545
themeLayout: 'horizontal',
4646
themeColorPresets: 'cyan',

src/contexts/SettingsContext.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,12 @@ function SettingsProvider({ children, defaultSettings }: SettingsProviderProps)
7676
// Mode
7777

7878
const onToggleMode = () => {
79+
const modes: ThemeMode[] = ['light', 'dark', 'system']
80+
const currentIndex = modes.indexOf(settings.themeMode)
81+
const nextIndex = (currentIndex + 1) % modes.length
7982
setSettings({
8083
...settings,
81-
themeMode: settings.themeMode === 'light' ? 'dark' : 'light',
84+
themeMode: modes[nextIndex],
8285
})
8386
}
8487

src/theme/index.tsx

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ReactNode, useMemo } from 'react'
1+
import { ReactNode, useEffect, useMemo, useState } from 'react'
22
// @mui
33
import { CssBaseline } from '@mui/material'
44
import { ThemeProvider as MUIThemeProvider, ThemeOptions, createTheme } from '@mui/material/styles'
@@ -19,7 +19,24 @@ type Props = {
1919
export default function AppThemeProvider({ children }: Props) {
2020
const { themeMode } = useSettings()
2121

22-
const isLight = themeMode === 'light'
22+
const [systemPreference, setSystemPreference] = useState<'light' | 'dark'>(() => {
23+
return window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light'
24+
})
25+
26+
useEffect(() => {
27+
if (themeMode !== 'system') return undefined
28+
29+
const mediaQuery = window.matchMedia('(prefers-color-scheme: dark)')
30+
const handler = (e: MediaQueryListEvent) => {
31+
setSystemPreference(e.matches ? 'dark' : 'light')
32+
}
33+
34+
mediaQuery.addEventListener('change', handler)
35+
return () => mediaQuery.removeEventListener('change', handler)
36+
}, [themeMode])
37+
38+
const actualMode = themeMode === 'system' ? systemPreference : themeMode
39+
const isLight = actualMode === 'light'
2340

2441
const themeOptions: ThemeOptions = useMemo(
2542
() => ({

0 commit comments

Comments
 (0)