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(Modal): fix confirm icon style when using third-party icons #48490

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

guoyunhe
Copy link
Contributor

@guoyunhe guoyunhe commented Apr 16, 2024

中文版模板 / Chinese template

🤔 This is a ...

  • New feature
  • Bug fix
  • Site / documentation update
  • Demo update
  • Component style update
  • TypeScript definition update
  • Bundle size optimization
  • Performance optimization
  • Enhancement feature
  • Internationalization
  • Refactoring
  • Code style optimization
  • Test Case
  • Branch merge
  • Workflow
  • Other (about what?)

🔗 Related issue link

💡 Background and solution

Modal.success/error/warning/info 调用的带图标的对话框,icon 样式的选择器为 token.iconCls,当使用第三方图标库时,样式不生效。

此变更增加了一层容器 ${confirmComponentCls}-icon 来赋予图标样式,兼容第三方图标库。

📝 Changelog

Language Changelog
🇺🇸 English fix(Modal): fix confirm icon style when using third-party icons
🇨🇳 Chinese fix(Modal): 修复快捷调用使用第三方图标时的样式

☑️ Self-Check before Merge

⚠️ Please check all items below before requesting a reviewing. ⚠️

  • Doc is updated/provided or not needed
  • Demo is updated/provided or not needed
  • TypeScript definition is updated/provided or not needed
  • Changelog is provided or not needed

Copy link

stackblitz bot commented Apr 16, 2024

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

Copy link
Contributor

github-actions bot commented Apr 16, 2024

Preview is ready

Copy link
Contributor

github-actions bot commented Apr 16, 2024

👁 Visual Regression Report for PR #48490 Passed ✅

🎯 Target branch: master (c150885)
📖 View Full Report ↗︎

🎊 Congrats! No visual-regression diff found.

@guoyunhe guoyunhe changed the title fix(Modal): confirm icon supports third-party icon fix(Modal): fix confirm icon style when using third-party icons Apr 16, 2024
Copy link

codesandbox-ci bot commented Apr 16, 2024

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

@afc163
Copy link
Member

afc163 commented Apr 16, 2024

给个重现先

@guoyunhe
Copy link
Contributor Author

@afc163 复现 demo https://stackblitz.com/edit/react-xkiawf?file=demo.tsx 第三方图标的尺寸和颜色都不对

图片

@@ -142,7 +142,7 @@ export function ConfirmContent(
[`${bodyCls}-has-title`]: hasTitle,
})}
>
{mergedIcon}
<div className={`${confirmPrefixCls}-icon`}>{mergedIcon}</div>
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
<div className={`${confirmPrefixCls}-icon`}>{mergedIcon}</div>
{cloneElement(mergedIcon, {
className: 'anticon',
})}

直接这样改如何?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@afc163 这样会覆盖掉原本的 icon 的 className 吧,而且也有可能组件不支持外部传入 className

Copy link
Member

Choose a reason for hiding this comment

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

  1. 我试了一下不会覆盖。
  2. 常用的图标组件都会支持 className 的,这个应该是标配。

Copy link
Contributor Author

Choose a reason for hiding this comment

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

效果相同的情况下,感觉使用 cloneElement 会更慢。

Copy link
Member

Choose a reason for hiding this comment

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

感觉?没有道理更慢吧

Copy link
Contributor Author

Choose a reason for hiding this comment

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

任何 clone 的过程都是耗时的。而且 React 官方文档里并不推荐用 cloneElement https://react.dev/reference/react/cloneElement

Using cloneElement is uncommon and can lead to fragile code.

@@ -44,7 +44,8 @@ const genModalConfirmStyle: GenerateStyle<ModalToken> = (token) => {
flexWrap: 'nowrap',
alignItems: 'start',

[`> ${token.iconCls}`]: {
[`> ${confirmComponentCls}-icon`]: {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
[`> ${confirmComponentCls}-icon`]: {
[`> ${token.iconCls}, > svg`]: {

这样吧。

Copy link
Member

Choose a reason for hiding this comment

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

我还是想尽量不动 dom 结构。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants