Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(design): ConfigProvider theme.isAliyun should work correctly #605

Merged
merged 1 commit into from
Jun 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading