Skip to content

Commit

Permalink
fix(design): fontFamily in nested ConfigProvider should be correct wh…
Browse files Browse the repository at this point in the history
…en enable theme.customFont
  • Loading branch information
dengfuping committed Apr 25, 2024
1 parent 59be31e commit 4cb9141
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 4 deletions.
37 changes: 36 additions & 1 deletion packages/design/src/config-provider/__tests__/theme.test.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import React, { useContext } from 'react';
import { render } from '@testing-library/react';
import { ConfigProvider, useToken } from '@oceanbase/design';
import { ConfigProvider, useToken, theme } from '@oceanbase/design';
import defaultTheme from '../../theme/default';

const antToken = theme.getDesignToken();

describe('ConfigProvider theme', () => {
it('ConfigProvider theme token', () => {
const Child1 = () => {
Expand Down Expand Up @@ -38,4 +40,37 @@ describe('ConfigProvider theme', () => {
</ConfigProvider>
);
});

it('ConfigProvider theme.customFont', () => {
const Child1 = () => {
const { token } = useToken();
expect(token.fontFamily).toBe(antToken.fontFamily);
return <div />;
};
const Child2 = () => {
const { token } = useToken();
expect(token.fontFamily).toBe(`'Source Sans Pro', ${antToken.fontFamily}`);
return <div />;
};
const Child3 = () => {
const { token } = useToken();
expect(token.fontFamily).toBe(`'Source Sans Pro', ${antToken.fontFamily}`);
return <div />;
};
render(
<ConfigProvider>
<Child1 />
<ConfigProvider
theme={{
customFont: true,
}}
>
<Child2 />
<ConfigProvider>
<Child3 />
</ConfigProvider>
</ConfigProvider>
</ConfigProvider>
);
});
});
7 changes: 4 additions & 3 deletions packages/design/src/config-provider/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,10 @@ const ConfigProvider: ConfigProviderType = ({
)}
theme={merge(currentTheme, mergedTheme, {
token: {
fontFamily: mergedTheme.customFont
? `'Source Sans Pro', ${token.fontFamily}`
: token.fontFamily,
fontFamily:
mergedTheme.customFont && !token.fontFamily.startsWith(`'Source Sans Pro'`)
? `'Source Sans Pro', ${token.fontFamily}`
: token.fontFamily,
},
})}
renderEmpty={
Expand Down

0 comments on commit 4cb9141

Please sign in to comment.