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/button icon loading not working #555

Merged
merged 4 commits into from
Jan 19, 2023
Merged
Show file tree
Hide file tree
Changes from 3 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
1 change: 1 addition & 0 deletions packages/icons-react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
"eslint": "^7.1.0",
"father": "^2.29.11",
"glob": "^7.1.6",
"history": "^4.9.0",
"lodash": "^4.17.15",
"mobx": "^5.1.0",
"mobx-react": "^6.1.3",
Expand Down
6 changes: 5 additions & 1 deletion packages/icons-react/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,11 @@ export const iconStyles = `
`;

export const useInsertStyles = (styleStr: string = iconStyles) => {
const { csp } = useContext(IconContext);
const { csp, prefixCls = 'anticon' } = useContext(IconContext);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这边不用设置默认值,否则下面 if 总是会走进去

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里之前写的时候删掉了,后来改着改着又加回去了.. 我修正一下


if (typeof prefixCls === "string") {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if (prefixCls) 就够了,不用做类型判断~

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

好的

styleStr = styleStr.replace(/anticon/g, prefixCls);
}

useEffect(() => {
updateCSS(styleStr, '@ant-design-icons', {
Expand Down
13 changes: 13 additions & 0 deletions packages/icons-react/tests/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -488,4 +488,17 @@ describe('Icon.createFromIconfontCN({scriptUrl:[]})', () => {
expect(node.className).toContain('hashCls');
})
});

it('icon loading should working when use prefixCls', () => {
testingLibRender(
<IconProvider value={{ prefixCls: 'myicon' }}>
<SyncOutlined spin />
</IconProvider>,
);

const spin = document.querySelector('.myicon-spin')
if(spin !== null){
expect(getComputedStyle(spin,null).getPropertyValue('animation')).toEqual('loadingCircle 1s infinite linear')
}
});
});