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.
BREAKING CHANGE: useTheme 的默认返回值发生变动,默认返回 antd token 值
- Loading branch information
Showing
4 changed files
with
36 additions
and
1 deletion.
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 |
---|---|---|
@@ -1,3 +1,6 @@ | ||
export * from './useAntdStylish'; | ||
export * from './useAntdTheme'; | ||
export * from './useAntdToken'; | ||
export * from './useAutoThemeMode'; | ||
export * from './useTheme'; | ||
export * from './useThemeMode'; |
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,11 @@ | ||
import { useAntdToken } from '@/hooks/useAntdToken'; | ||
import { AntdStylish } from '@/types'; | ||
import { useMemo } from 'react'; | ||
|
||
export const useAntdStylish = (): AntdStylish => { | ||
const token = useAntdToken(); | ||
|
||
return useMemo(() => { | ||
return {}; | ||
}, [token]); | ||
}; |
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,10 @@ | ||
import { AntdTheme } from '@/types'; | ||
import { useAntdStylish } from './useAntdStylish'; | ||
import { useAntdToken } from './useAntdToken'; | ||
|
||
export const useAntdTheme = (): AntdTheme => { | ||
const token = useAntdToken(); | ||
const antdStylish = useAntdStylish(); | ||
|
||
return { stylish: antdStylish, ...token }; | ||
}; |
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,15 @@ | ||
import { useAntdTheme } from '@/hooks/useAntdTheme'; | ||
import { Theme } from '@/types'; | ||
import { useTheme as _useTheme } from '@emotion/react'; | ||
|
||
export const useTheme = () => _useTheme() as Theme; | ||
export const useTheme = (): Theme => { | ||
const antdTheme = useAntdTheme(); | ||
const defaultTheme = _useTheme(); | ||
|
||
// 如果是个空值,说明没有套 Provider,返回 antdTheme 的默认值 | ||
if (Object.keys(defaultTheme).length === 0) { | ||
return antdTheme; | ||
} | ||
|
||
return defaultTheme as Theme; | ||
}; |