Skip to content

Commit

Permalink
fix(design): ConfigProvider theme.isAliyun should work correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
dengfuping committed Jun 20, 2024
1 parent a5a4e14 commit eb5cf0b
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 8 deletions.
33 changes: 33 additions & 0 deletions packages/design/src/config-provider/__tests__/theme.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -109,4 +109,37 @@ describe('ConfigProvider theme', () => {
</ConfigProvider>
);
});

it('isAliyun', () => {
const Child1 = () => {
const { token } = useToken();
expect(token.colorPrimary).toBe(defaultTheme.token.colorPrimary);
return <div />;
};
const Child2 = () => {
const { token } = useToken();
expect(token.colorPrimary).toBe('#0064c8');
return <div />;
};
const Child3 = () => {
const { token } = useToken();
expect(token.colorPrimary).toBe('#0064c8');
return <div />;
};
render(
<ConfigProvider>
<Child1 />
<ConfigProvider
theme={{
isAliyun: true,
}}
>
<Child2 />
<ConfigProvider>
<Child3 />
</ConfigProvider>
</ConfigProvider>
</ConfigProvider>
);
});
});
16 changes: 8 additions & 8 deletions packages/design/src/config-provider/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -108,14 +108,14 @@ const ConfigProvider: ConfigProviderType = ({
const parentExtendedContext =
React.useContext<ExtendedConfigConsumerProps>(ExtendedConfigContext);
const { isDark, isAliyun } = merge({}, parentContext.theme, theme);
const currentTheme = isAliyun
? aliyunTheme
: isDark
? darkTheme
: parentContext.theme
? {}
: defaultTheme;
const mergedTheme = merge({}, parentContext.theme, currentTheme, theme);
const customTheme = isAliyun ? aliyunTheme : isDark ? darkTheme : undefined;
const mergedTheme = merge(
{},
customTheme ? {} : defaultTheme,
parentContext.theme,
customTheme,
theme
);

const { token } = themeConfig.useToken();
const fontFamily = mergedTheme.token?.fontFamily || token.fontFamily;
Expand Down

0 comments on commit eb5cf0b

Please sign in to comment.