-
Notifications
You must be signed in to change notification settings - Fork 96
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add support for dark & light themes
- Loading branch information
Showing
7 changed files
with
87 additions
and
32 deletions.
There are no files selected for viewing
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,52 @@ | ||
// ThemeContext.js | ||
import React, { FC, PropsWithChildren, createContext, useContext, useState } from 'react' | ||
import { ThemeProvider as MuiThemeProvider, createTheme } from '@mui/material/styles' | ||
import { ConfigProvider, theme } from 'antd' | ||
import heIL from 'antd/es/locale/he_IL' | ||
export interface ThemeContextInterface { | ||
toggleTheme: () => void | ||
isDarkTheme: boolean | ||
} | ||
const ThemeContext = createContext({} as ThemeContextInterface) | ||
const darkTheme = createTheme({ | ||
palette: { | ||
mode: 'dark', | ||
}, | ||
}) | ||
|
||
const lightTheme = createTheme({ | ||
palette: { | ||
mode: 'light', | ||
}, | ||
}) | ||
|
||
const { defaultAlgorithm, darkAlgorithm } = theme | ||
export const ThemeProvider: FC<PropsWithChildren> = ({ children }) => { | ||
const [isDarkTheme, setIsDarkTheme] = useState(false) | ||
|
||
const toggleTheme = () => { | ||
setIsDarkTheme((prevTheme) => !prevTheme) | ||
} | ||
|
||
const contextValue = { | ||
isDarkTheme, | ||
toggleTheme, | ||
} | ||
|
||
return ( | ||
<ConfigProvider | ||
direction="rtl" | ||
locale={heIL} | ||
theme={{ | ||
algorithm: isDarkTheme ? darkAlgorithm : defaultAlgorithm, | ||
}}> | ||
<MuiThemeProvider theme={isDarkTheme ? darkTheme : lightTheme}> | ||
<ThemeContext.Provider value={contextValue}> {children} </ThemeContext.Provider> | ||
</MuiThemeProvider> | ||
</ConfigProvider> | ||
) | ||
} | ||
|
||
export const useTheme = () => { | ||
return useContext(ThemeContext) | ||
} |
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 |
---|---|---|
@@ -1,5 +1,7 @@ | ||
import { Card } from 'antd' | ||
|
||
const Widget = (props: { children: React.ReactNode }) => { | ||
return <section className="widget">{props.children}</section> | ||
return <Card>{props.children}</Card> | ||
} | ||
|
||
export default Widget |