-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Add theme.ts to create common theme structure for components. - Add light and dark and dark mode themes. - Add ThemeContext.tsx for theme management. - Edit Layout.tsx to add ThemeProvider and CssBaseline. - Add theme.test.tsx to test themes. - Install roboto font.
- Loading branch information
Showing
6 changed files
with
372 additions
and
7 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
'use client'; | ||
|
||
import { ThemeProvider as MuiThemeProvider, Theme } from '@mui/material/styles'; | ||
import React, { createContext, useEffect, useMemo, useState } from 'react'; | ||
import { darkTheme, lightTheme } from './theme'; | ||
|
||
interface ThemeContextType { | ||
toggleTheme: () => void; | ||
isDarkMode: boolean; | ||
} | ||
|
||
export const ThemeContext = createContext<ThemeContextType>({ | ||
toggleTheme: () => {}, | ||
isDarkMode: false, | ||
}); | ||
|
||
export const ThemeProvider: React.FC<{ children: React.ReactNode }> = ({ | ||
children, | ||
}) => { | ||
const [isDarkMode, setIsDarkMode] = useState<boolean>(false); | ||
|
||
useEffect(() => { | ||
const savedTheme = localStorage.getItem('theme'); | ||
if (savedTheme) { | ||
setIsDarkMode(savedTheme === 'dark'); | ||
} | ||
}, []); | ||
|
||
const toggleTheme = () => { | ||
setIsDarkMode((prev) => { | ||
const newMode = !prev; | ||
localStorage.setItem('theme', newMode ? 'dark' : 'light'); | ||
return newMode; | ||
}); | ||
}; | ||
|
||
const theme: Theme = useMemo( | ||
() => (isDarkMode ? darkTheme : lightTheme), | ||
[isDarkMode] | ||
); | ||
|
||
return ( | ||
<ThemeContext.Provider value={{ toggleTheme, isDarkMode }}> | ||
<MuiThemeProvider theme={theme}>{children}</MuiThemeProvider> | ||
</ThemeContext.Provider> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
import { createTheme } from '@mui/material/styles'; | ||
|
||
const commonSettings = { | ||
typography: { | ||
fontFamily: 'Roboto, Arial, sans-serif, ', | ||
body1: { | ||
color: 'var(--common-white_states-main, #FFF)', | ||
fontFamily: 'Roboto', | ||
fontSize: '16px', | ||
fontStyle: 'normal', | ||
fontWeight: 400, | ||
lineHeight: '24px', | ||
letterSpacing: '0.15px', | ||
}, | ||
body2: { | ||
color: '#FFFFFF', | ||
fontFamily: 'Roboto', | ||
fontSize: '14px', | ||
fontWeight: 400, | ||
lineHeight: '20px', | ||
letterSpacing: '0.15px', | ||
}, | ||
h1: { | ||
color: 'var(--common-white_states-main, #FFF)', | ||
fontFamily: 'Roboto', | ||
fontSize: '30px', | ||
fontStyle: 'normal', | ||
fontWeight: 500, | ||
lineHeight: '24px', | ||
letterSpacing: '0.15px', | ||
}, | ||
h2: { | ||
color: 'var(--common-white_states-main, #FFF)', | ||
fontFamily: 'Roboto', | ||
fontSize: '24px', | ||
fontWeight: 500, | ||
lineHeight: '32px', | ||
letterSpacing: '0.1px', | ||
}, | ||
h3: { | ||
color: 'var(--common-white_states-main, #FFF)', | ||
fontFamily: 'Roboto', | ||
fontSize: '20px', | ||
fontWeight: 500, | ||
lineHeight: '28px', | ||
letterSpacing: '0.1px', | ||
}, | ||
subtitle1: { | ||
color: '#D9D9D9', | ||
fontFamily: 'Roboto', | ||
fontSize: '16px', | ||
fontWeight: 400, | ||
lineHeight: '24px', | ||
letterSpacing: '0.15px', | ||
}, | ||
subtitle2: { | ||
color: '#8F8C8C', | ||
fontFamily: 'Roboto', | ||
fontSize: '14px', | ||
fontWeight: 400, | ||
lineHeight: '20px', | ||
letterSpacing: '0.1px', | ||
}, | ||
caption: { | ||
color: '#8F8C8C', | ||
fontFamily: 'Roboto', | ||
fontSize: '12px', | ||
fontWeight: 400, | ||
lineHeight: '16px', | ||
letterSpacing: '0.4px', | ||
}, | ||
overline: { | ||
color: '#8F8C8C', | ||
fontFamily: 'Roboto', | ||
fontSize: '10px', | ||
fontWeight: 400, | ||
lineHeight: '16px', | ||
letterSpacing: '1.5px', | ||
textTransform: 'uppercase' as const, | ||
}, | ||
}, | ||
}; | ||
|
||
export const lightTheme = createTheme({ | ||
...commonSettings, | ||
palette: { | ||
mode: 'light', | ||
primary: { main: '#282828' }, | ||
secondary: { main: '#8F8C8C' }, | ||
background: { default: '#D9D9D9', paper: '#fff' }, | ||
text: { | ||
primary: '#000000', | ||
secondary: '#282828', | ||
}, | ||
}, | ||
}); | ||
|
||
export const darkTheme = createTheme({ | ||
...commonSettings, | ||
palette: { | ||
mode: 'dark', | ||
primary: { main: '#FFFFFF' }, | ||
secondary: { main: '#8F8C8C' }, | ||
background: { | ||
default: '#000000', | ||
paper: '#161616', | ||
}, | ||
text: { | ||
primary: '#FFFFFF', | ||
secondary: '#D9D9D9', | ||
}, | ||
divider: '#282828', | ||
}, | ||
}); |
Oops, something went wrong.