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: createInstance 方法支持声明自定义 token 默认值
- Loading branch information
Showing
8 changed files
with
76 additions
and
26 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
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,24 +1,39 @@ | ||
import { Theme, UseTheme } from '@/types'; | ||
import { useMemo } from 'react'; | ||
import { Context, useContext, useMemo } from 'react'; | ||
|
||
import { DEFAULT_USE_THEME } from '@/functions/setupStyled'; | ||
import { useAntdTheme } from '@/hooks/useAntdTheme'; | ||
import { useThemeMode } from '@/hooks/useThemeMode'; | ||
|
||
export const createUseTheme = (useDefaultTheme?: UseTheme) => (): Theme => { | ||
interface CreateUseThemeOptions { | ||
prefixCls?: string; | ||
CustomThemeContext: Context<any>; | ||
styledUseTheme?: UseTheme; | ||
} | ||
|
||
export const createUseTheme = (options: CreateUseThemeOptions) => (): Theme => { | ||
const { prefixCls, styledUseTheme, CustomThemeContext } = options; | ||
const antdTheme = useAntdTheme(); | ||
const themeState = useThemeMode(); | ||
const defaultTheme = useDefaultTheme ? useDefaultTheme() : DEFAULT_USE_THEME() || {}; | ||
|
||
const defaultCustomTheme = useContext(CustomThemeContext); | ||
|
||
const styledTheme = styledUseTheme ? styledUseTheme() : DEFAULT_USE_THEME() || {}; | ||
|
||
const initTheme = useMemo<Theme>( | ||
() => ({ ...antdTheme, ...themeState, prefixCls: 'ant' }), | ||
[antdTheme, themeState], | ||
() => ({ | ||
...antdTheme, | ||
...themeState, | ||
...defaultCustomTheme, | ||
prefixCls: prefixCls || 'ant', | ||
}), | ||
[antdTheme, themeState, prefixCls, defaultCustomTheme], | ||
); | ||
|
||
// 如果是个空值,说明没有套 Provider,返回 antdTheme 的默认值 | ||
if (!defaultTheme || Object.keys(defaultTheme).length === 0) { | ||
if (!styledTheme || Object.keys(styledTheme).length === 0) { | ||
return initTheme; | ||
} | ||
|
||
return defaultTheme as Theme; | ||
return styledTheme as Theme; | ||
}; |
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,3 +1,5 @@ | ||
/* istanbul ignore file */ | ||
|
||
import { getRegisteredStyles, RegisteredCache } from '@emotion/utils'; | ||
|
||
/** | ||
|