mirror of
https://github.com/ant-design/ant-design.git
synced 2024-11-24 02:59:58 +08:00
fix: global token in components with css var should work (#45860)
This commit is contained in:
parent
625184a306
commit
b2300fa2d3
@ -245,5 +245,27 @@ describe('ConfigProvider.Theme', () => {
|
||||
'line-height': 'var(--bar-line-height)',
|
||||
});
|
||||
});
|
||||
|
||||
it('component token should work', () => {
|
||||
const { container } = render(
|
||||
<ConfigProvider
|
||||
theme={{
|
||||
cssVar: { key: 'foo' },
|
||||
hashed: true,
|
||||
components: { Button: { colorPrimary: '#1890ff', defaultBg: '#000' } },
|
||||
}}
|
||||
>
|
||||
<Button className="button-foo" type="primary">
|
||||
Button
|
||||
</Button>
|
||||
</ConfigProvider>,
|
||||
);
|
||||
|
||||
const btn = container.querySelector('.button-foo')!;
|
||||
expect(btn).toHaveStyle({
|
||||
'--antd-color-primary': '#1890ff',
|
||||
'--antd-button-default-bg': '#000',
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -303,7 +303,7 @@ export const genCSSVarRegister = <C extends OverrideComponent>(
|
||||
useCSSVarRegister(
|
||||
{
|
||||
path: [component],
|
||||
prefix: getCompVarPrefix(component, cssVar.prefix),
|
||||
prefix: cssVar.prefix,
|
||||
key: cssVar?.key!,
|
||||
unitless: {
|
||||
...unitless,
|
||||
@ -316,7 +316,13 @@ export const genCSSVarRegister = <C extends OverrideComponent>(
|
||||
},
|
||||
() => {
|
||||
const defaultToken = getDefaultComponentToken(component, realToken, getDefaultToken);
|
||||
return getComponentToken(component, realToken, defaultToken);
|
||||
const componentToken = getComponentToken(component, realToken, defaultToken);
|
||||
Object.keys(defaultToken).forEach((key) => {
|
||||
componentToken[`${component}${key.slice(0, 1).toUpperCase()}${key.slice(1)}`] =
|
||||
componentToken[key];
|
||||
delete componentToken[key];
|
||||
});
|
||||
return componentToken;
|
||||
},
|
||||
);
|
||||
return null;
|
||||
|
Loading…
Reference in New Issue
Block a user