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

feat: Modal support loading #48848

Merged
merged 22 commits into from
May 15, 2024
Merged

feat: Modal support loading #48848

merged 22 commits into from
May 15, 2024

Conversation

li-jia-nan
Copy link
Member

中文版模板 / 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

📝 Changelog

Language Changelog
🇺🇸 English feat: Modal support loading
🇨🇳 Chinese feat: Modal support loading

☑️ 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 May 9, 2024

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

Copy link
Contributor

github-actions bot commented May 9, 2024

Preview is ready

Copy link
Contributor

github-actions bot commented May 9, 2024

👁 Visual Regression Report for PR #48848 Failed ❌

🎯 Target branch: feature (05f587a)
📖 View Full Report ↗︎

Expected (Branch feature) Actual (Current PR) Diff
progress-info-position.compact.png progress-info-position.compact.png progress-info-position.compact.css-var.png progress-info-position.compact.css-var.png
progress-info-position.dark.png progress-info-position.dark.png progress-info-position.dark.css-var.png progress-info-position.dark.css-var.png
progress-info-position.default.png progress-info-position.default.png progress-info-position.default.css-var.png progress-info-position.default.css-var.png
modal-loading.compact.css-var.png modal-loading.compact.css-var.png 🆕🆕🆕 Added 🆕🆕🆕
modal-loading.compact.png modal-loading.compact.png 🆕🆕🆕 Added 🆕🆕🆕
modal-loading.dark.css-var.png modal-loading.dark.css-var.png 🆕🆕🆕 Added 🆕🆕🆕
modal-loading.dark.png modal-loading.dark.png 🆕🆕🆕 Added 🆕🆕🆕
modal-loading.default.css-var.png modal-loading.default.css-var.png 🆕🆕🆕 Added 🆕🆕🆕
modal-loading.default.png modal-loading.default.png 🆕🆕🆕 Added 🆕🆕🆕

Check Full Report for details

Copy link
Contributor

github-actions bot commented May 9, 2024

size-limit report 📦

Path Size
./dist/antd.min.js 338.01 KB (+70 B 🔺)
./dist/antd-with-locales.min.js 385.81 KB (+146 B 🔺)

Copy link

codesandbox-ci bot commented May 9, 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.

Copy link

codecov bot commented May 9, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (f912fa0) to head (1effa0b).
Report is 6 commits behind head on feature.

Additional details and impacted files
@@            Coverage Diff            @@
##           feature    #48848   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          746       746           
  Lines        13010     13020   +10     
  Branches      3425      3429    +4     
=========================================
+ Hits         13010     13020   +10     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@afc163
Copy link
Member

afc163 commented May 10, 2024

这个和直接写 Skeleton 有啥区别?如果是这个层面的封装,loading 属性意义不大,别加。

<Modal>
 <Skeleton active />
</Modal>

@li-jia-nan
Copy link
Member Author

这个和直接写 Skeleton 有啥区别?如果是这个层面的封装,loading 属性意义不大,别加。

<Modal>
 <Skeleton active />
</Modal>

这里还有一个 PR,是替换全部的内容,但是豆酱大佬讨论之后说,要保留 title 部分和 footer 部分:

@afc163
Copy link
Member

afc163 commented May 10, 2024

那就没意义了,这个程度的 loading 不必加。新属性还是要能解决原来不能做或者做起来很麻烦的事情。

@li-jia-nan
Copy link
Member Author

那就没意义了,这个程度的 loading 不必加。新属性还是要能解决原来不能做或者做起来很麻烦的事情。

更新了,把 footer 也隐藏了,只保留 title

@li-jia-nan
Copy link
Member Author

image

@li-jia-nan li-jia-nan requested a review from zombieJ May 10, 2024 04:03
@afc163
Copy link
Member

afc163 commented May 10, 2024

标题右边加个 LoadingIcon?

@li-jia-nan
Copy link
Member Author

标题右边加个 LoadingIcon?

done

@zombieJ
Copy link
Member

zombieJ commented May 10, 2024

标题右边加个 LoadingIcon?

效果看起来不好,Skeleton active 看着够了

@li-jia-nan li-jia-nan requested a review from afc163 May 12, 2024 07:44
@li-jia-nan li-jia-nan mentioned this pull request May 12, 2024
20 tasks
components/modal/Modal.tsx Outdated Show resolved Hide resolved
@li-jia-nan li-jia-nan requested a review from zombieJ May 13, 2024 07:39
@li-jia-nan li-jia-nan requested a review from zombieJ May 13, 2024 18:07
@li-jia-nan li-jia-nan requested a review from zombieJ May 14, 2024 10:17
zombieJ and others added 2 commits May 14, 2024 19:13
Signed-off-by: 二货爱吃白萝卜 <smith3816@gmail.com>
@Wxh16144
Copy link
Member

Wxh16144 commented May 15, 2024

这个和直接写 Skeleton 有啥区别?如果是这个层面的封装,loading 属性意义不大,别加。

<Modal>
 <Skeleton active />
</Modal>

我也偏向这点, 如果真要做这个功能,可以考虑在 modalRender 上开口子,把自由度交给开发者去做。 可以参考 modal 的 footer 的 renderFunction 实现。比如

 modalRender={(originNode, { Title, Content, Footer }) => {
        // some code
        // 在这里可以对 Modal 的结构进行调整,包括 Skeleton 骨架,并且行为和 footer 的 render 一样
      }}
开发者使用时的示例代码(不一定准确
import { Button, Modal, Skeleton } from 'antd'
import * as React from 'react'

function useTimeout(callback: () => void, delay: number) {
  const savedCallback = React.useRef<() => void>()

  React.useEffect(() => {
    savedCallback.current = callback
  }, [callback])

  React.useEffect(() => {
    function tick() {
      savedCallback.current?.()
    }

    if (delay !== null) {
      const id = setTimeout(tick, delay)
      return () => clearTimeout(id)
    }
  }, [delay])
}

function Bar() {
  const [loading, setLoading] = React.useState(true)

  useTimeout(() => {
    setLoading(false)
  }, 3000)

  return (
    <Modal
      open
      // modalRender={modal => (
      //   <Skeleton loading={loading} active>
      //     {modal}
      //   </Skeleton>
      // )}
      modalRender={(originNode, { Title, Content, Footer }) => {
        // some code
        // 在这里可以对 Modal 的结构进行调整,包括 Skeleton 骨架,并且行为和 footer 的 render 一样
      }}
      footer={(originNode, { CancelBtn, OkBtn }) => {
        if (loading) {
          return <>{CancelBtn}</>
        }
        return <>{originNode}</>
      }}
    >
      <Button
        onClick={() => {
          setLoading(p => !p)
          setTimeout(() => {
            setLoading(p => !p)
          }, 3000)
        }}
        type="primary"
      >
        Toggle loading
      </Button>
    </Modal>
  )
}

export default Bar

@wanpan11
Copy link
Contributor

貌似有一些自定义 body 的需求

#48853

@zombieJ
Copy link
Member

zombieJ commented May 15, 2024

貌似有一些自定义 body 的需求

这个看起来和 Loading 没什么关系……

@zombieJ zombieJ merged commit 7cdeecf into feature May 15, 2024
102 of 103 checks passed
@zombieJ zombieJ deleted the loading-modal branch May 15, 2024 03:21
@li-jia-nan
Copy link
Member Author

我也偏向这点, 如果真要做这个功能,可以考虑在 modalRender 上开口子,把自由度交给开发者去做。 可以参考 modal 的 footer 的 renderFunction 实现

一开始是老外提的 PR,替换了全部的内容,后面发布了就没办法删了,只能在之前的基础上做优化,另外 Drawer 组件也是这样做的,两个保持一致,看起来没啥问题

@PeachScript PeachScript mentioned this pull request Jun 3, 2024
20 tasks
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

5 participants