generated from arvinxx/npm-template
-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ feat: useTheme 中增加 appearance 等主题状态属性
- Loading branch information
Showing
5 changed files
with
23 additions
and
18 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
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,10 +1,15 @@ | ||
import { createContext } from 'react'; | ||
|
||
import { DisplayTheme, ThemeMode } from '@/types'; | ||
import { ThemeAppearance, ThemeMode } from '@/types'; | ||
|
||
export interface ThemeModeContextState { | ||
appearance: DisplayTheme; | ||
export interface ThemeContextState { | ||
appearance: ThemeAppearance; | ||
themeMode: ThemeMode; | ||
isDarkMode: boolean; | ||
} | ||
|
||
export const ThemeModeContext = createContext<ThemeModeContextState | undefined>(undefined); | ||
export const ThemeModeContext = createContext<ThemeContextState>({ | ||
appearance: 'light', | ||
isDarkMode: false, | ||
themeMode: 'light', | ||
}); |
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,14 +1,5 @@ | ||
import { useContext } from 'react'; | ||
|
||
import { ThemeModeContext } from '@/context'; | ||
import { ThemeContextState, ThemeModeContext } from '@/context'; | ||
|
||
export const useThemeMode = () => { | ||
const value = useContext(ThemeModeContext); | ||
|
||
if (value === undefined) | ||
throw Error( | ||
'[WrapperError]你可能没有使用 <AppContainer /> 组件,请确保在组件顶层包裹 AppContainer 组件后再使用该 hooks。', | ||
); | ||
|
||
return value; | ||
}; | ||
export const useThemeMode = (): ThemeContextState => useContext(ThemeModeContext); |
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,4 +1,5 @@ | ||
export * from './containers'; | ||
export type { ThemeContextState } from './context'; | ||
export * from './functions'; | ||
export * from './hooks'; | ||
export * from './types'; |
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