feat: ConfigProvider support nextThemeEnd

This commit is contained in:
叶枫 2024-08-28 21:50:52 +08:00
parent 730a37f0bd
commit 9354a21780
8 changed files with 51 additions and 8 deletions

View File

@ -150,8 +150,8 @@ const GlobalLayout: React.FC = () => {
() => ({
algorithm: getAlgorithm(theme),
token: { motion: !theme.includes('motion-off') },
cssVar: true,
hashed: false,
cssVar: false,
hashed: true,
}),
[theme],
);

View File

@ -21,7 +21,7 @@ export default defineConfig({
: false,
hash: true,
mfsu: false,
mako: {},
// mako: {},
crossorigin: {},
runtimePublicPath: {},
outputPath: '_site',
@ -57,9 +57,12 @@ export default defineConfig({
analytics: {
ga_v2: 'UA-72788897-1',
},
analyze: process.env.NODE_ENV === 'production' ? false : {
analyzerPort: 'auto',
},
analyze:
process.env.NODE_ENV === 'production'
? false
: {
analyzerPort: 'auto',
},
links: [
{
rel: 'prefetch',

View File

@ -82,6 +82,12 @@ export interface ThemeConfig {
* @default true
*/
inherit?: boolean;
/**
* @descCN `ConfigProvider` `ConfigProvider`
* @descEN Whether to inherit the theme configured in the outer layer `ConfigProvider`.
* @default true
*/
nextThemeEnd?: boolean;
/**
* @descCN `hashed` antd `false`
* @descEN Whether to enable the `hashed` attribute. If there is only one version of antd in your application, you can set `false` to reduce the bundle size.
@ -243,6 +249,7 @@ export interface ConfigConsumerProps {
popupOverflow?: PopupOverflow;
form?: FormConfig;
theme?: ThemeConfig;
themeOrigin?: ThemeConfig;
select?: SelectConfig;
alert?: AlertConfig;
anchor?: ComponentStyleConfig;

View File

@ -0,0 +1,7 @@
## zh-CN
scope
## en-US
scope

View File

@ -0,0 +1,21 @@
import React from 'react';
import { Button, ConfigProvider } from 'antd';
const App: React.FC = () => (
// layout
<ConfigProvider theme={{ token: { colorPrimary: 'red' } }}>
{/* page */}
<ConfigProvider
componentSize="small"
theme={{ nextThemeEnd: true, token: { fontSize: 12, fontSizeSM: 12 } }}
>
<Button type="primary">font-size 12</Button>
{/* other */}
<ConfigProvider componentSize="middle" theme={{ token: { colorInfo: 'blue' } }}>
<Button type="primary">font-size 14</Button>
</ConfigProvider>
</ConfigProvider>
</ConfigProvider>
);
export default App;

View File

@ -47,6 +47,7 @@ Some components use dynamic style to support wave effect. You can config `csp` p
<code src="./demo/prefixCls.tsx" debug>prefixCls</code>
<code src="./demo/useConfig.tsx" debug>useConfig</code>
<code src="./demo/warning.tsx" debug>warning</code>
<code src="./demo/scope.tsx" >scope</code>
## API

View File

@ -177,6 +177,7 @@ export interface ConfigProviderProps {
popupMatchSelectWidth?: boolean;
popupOverflow?: PopupOverflow;
theme?: ThemeConfig;
themeOrigin?: ThemeConfig;
warning?: WarningContextProps;
alert?: AlertConfig;
anchor?: ComponentStyleConfig;
@ -414,7 +415,9 @@ const ProviderChildren: React.FC<ProviderChildrenProps> = (props) => {
useStyle(iconPrefixCls, csp);
const mergedTheme = useTheme(theme, parentContext.theme, { prefixCls: getPrefixCls('') });
const mergedTheme = useTheme(parentContext.themeOrigin || theme, parentContext.theme, {
prefixCls: getPrefixCls(''),
});
if (process.env.NODE_ENV !== 'production') {
existThemeConfig = existThemeConfig || !!mergedTheme;
@ -503,6 +506,7 @@ const ProviderChildren: React.FC<ProviderChildrenProps> = (props) => {
const config: ConfigConsumerProps = {
...parentContext,
themeOrigin: theme?.nextThemeEnd ? parentContext.theme : undefined,
};
(Object.keys(baseConfig) as (keyof typeof baseConfig)[]).forEach((key) => {
@ -629,7 +633,6 @@ const ProviderChildren: React.FC<ProviderChildrenProps> = (props) => {
return {
...rest,
theme: themeObj,
token: mergedToken,
components: parsedComponents,
override: {

View File

@ -48,6 +48,7 @@ export default Demo;
<code src="./demo/prefixCls.tsx" debug>前缀</code>
<code src="./demo/useConfig.tsx" debug>获取配置</code>
<code src="./demo/warning.tsx" debug>警告</code>
<code src="./demo/scope.tsx" >scope</code>
## API