Skip to content

feat: new component Statistic.Timer#53401

Merged
thinkasany merged 25 commits intoant-design:featurefrom
lcgash:lcg-countdown-feat
Apr 11, 2025
Merged

feat: new component Statistic.Timer#53401
thinkasany merged 25 commits intoant-design:featurefrom
lcgash:lcg-countdown-feat

Conversation

@lcgash
Copy link
Copy Markdown
Contributor

@lcgash lcgash commented Apr 3, 2025

🤔 这个变动的性质是?

  • 🆕 新特性提交

🔗 相关 Issue

#53399

close #36223

  1. 描述相关需求的来源,如相关的 issue 讨论链接。
  2. 例如 close #xxxx、 fix #xxxx

💡 需求背景和解决方案

有些场景是需要正计时的,比如从某个时间点过去了多久这样的展示
image

📝 更新日志

语言 更新描述
🇺🇸 英文 🆕 Statistic adds Statistic.timer component
🇨🇳 中文 🆕 Statistic 新增 Statistic.timer 组件

@bolt-new-by-stackblitz
Copy link
Copy Markdown

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

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 3, 2025

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

📝 Walkthrough

Summary by CodeRabbit

  • 新功能

    • 现已用全新计时器组件替换旧版倒计时组件,新组件支持倒计时和正计时模式,并优化了时间更新和事件回调。旧组件已标记为弃用,请切换至新组件。
  • 文档更新

    • API 文档和示例均已更新,新增了对“type”属性的说明,提供了中英文的详细使用说明和演示示例。
## Summary by CodeRabbit

- **新功能**
  - 新增 Timer 定时器组件,支持倒计时与正计时两种模式,并提供更多配置选项。
- **文档**
  - 更新了中英文 API 文档及示例,详细介绍 Timer 组件的属性和用法。
- **重构**
  - 弃用旧版 Countdown 组件,建议用户切换至全新 Timer 组件以获得更好的体验。

## Walkthrough
本次变更对原有的 Countdown 组件进行了重构,移除了其内部定时器逻辑,改为调用新组件 StatisticTimer,并在 API 文档、测试用例及导出声明中将 Countdown 重命名为 Timer,同时新增了 type 属性(支持 countdown 与 countup)。工具函数 formatCountdown 重命名为 formatCounter 并增加了 down 参数,用以调整时间差的计算逻辑。此外,还新增了计时器组件的演示说明和示例代码,并添加了废弃提示,指导用户采用新的用法。

## Changes

| 文件                                                                                         | 变更摘要                                                                                                                    |
|----------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------|
| components/statistic/Countdown.tsx                                                           | 移除内部定时器逻辑,改为调用 StatisticTimer 组件;添加废弃注释,提示使用 Statistic.Timer 替代 Countdown。                           |
| components/statistic/index.en-US.md <br> components/statistic/index.zh-CN.md                   | 更新 API 文档:将 Countdown 重命名为 Timer,新增 type 属性说明(countdown/countup),并加入废弃警告。                               |
| components/statistic/utils.ts                                                                | 将 formatCountdown 重命名为 formatCounter,增加 down 参数,并调整计算倒计时或正计时的逻辑。                                      |
| components/statistic/Timer.tsx                                                               | 新增 StatisticTimer 组件,支持倒计时与正计时,集成定时、格式化及 onChange/onFinish 回调逻辑,利用自定义 Hook 实现定时更新。            |
| components/statistic/__tests__/index.test.tsx                                                | 测试用例中将 Countdown 组件替换为 Timer,更新导入类型及事件处理的相关调用。                                                    |
| components/statistic/demo/timer.md <br> components/statistic/demo/timer.tsx                    | 新增计时器组件的文档与示例代码,展示多种定时功能及响应式布局配置。                                                             |
| components/statistic/index.tsx <br> components/index.ts                                       | 更新导入与导出声明,将 Countdown 替换为 Timer,同时新增 StatisticTimerProps 类型导出。                                      |

## Sequence Diagram(s)

```mermaid
sequenceDiagram
    participant App as 应用程序
    participant Timer as StatisticTimer
    participant Hook as 定时器钩子
    participant Util as formatCounter

    App->>Timer: 挂载组件
    Timer->>Hook: 启动定时器 (setInterval)
    Hook->>Util: 计算时间差
    Util-->>Hook: 返回格式化后的时间
    Hook->>Timer: 调用 onChange 或 onFinish 回调
    Timer->>App: 更新 UI (useForceUpdate)
    Note over Timer,Hook: 条件满足时清理定时器 (clearInterval)

Possibly related issues

  • [NEW] Statistic.Timer #36223: 此次变更通过引入 Statistic.Timer 组件并废弃 Statistic.Countdown,实现了问题中讨论的组件转换目标。

Poem

我是一只跳跃的小兔,
在代码花园中探寻新路。
旧组件悄然谢幕,
Timer 闪耀登台独舞,
时间的节拍随我欢歌跳跃!
🐰✨


</details>

<!-- walkthrough_end -->
<!-- internal state start -->


<!-- DwQgtGAEAqAWCWBnSTIEMB26CuAXA9mAOYCmGJATmriQCaQDG+Ats2bgFyQAOFk+AIwBWJBrngA3EsgEBPRvlqU0AgfFwA6NPEgQAfACgjoCEYDEZyAAUASpADK2VmgqyjcEj2wAbb5AokAI7Y0riQ4rjedJAARABmJNRciNjc3PgUYeJsfEzM6eQYuDGQAO5oyCkCzOo09HKQ2IiUkN4MRBWw6Bj0qPBKRfBx8NENuLCeGE4CLQCsAMwALAAMAIwaMAjItihFFIrYDNLokOSlkAnU2AHhsNTovvilyHEZJ9kteQXsjGjcKlF+HEFNhBhgiJABPhxhcMuUKPRMPU0AwANbw2gAGnQtFoAUQiHg4MgiCOGBc8HwyFKExu6hQyHIRwJLnkBEgtCQ3G8aHkJB53Ga9A+F32zBOiG4oiG8AYPHwRLCRNunn+iE0m08SlJFHg3HE+CwDGoJCIGXgAC9juNUAw7uDPBUTmcLolcNdPFUagTKVgkf4SAkAhhmScAjy6gyUp4ABQASQJIUgZgW8wAnGmAJS3e6c0lNZrIcaTEjRV58G0vUFiX1obzqWQbACCkAkSGwdYDvGk7GovqBKtdVzpyCJDG82CUwvwHJIzEN6qoNBQuGQf25sr7ho07gmjW4tBNrXwEKJnONNCLdyye7tmFIHPwxww0PQcQSYkgJAAHkhxMS4mrA1yXrXBZGxJ1i1nOI0B8MIZjuNs3gCZhtAwZBq3tUhaA2Dwh3dEdZx1eAZl6LAoRhABRcF60QLp/QAYQQchmmxUp1C6KDqKIWiulSQ9l3VPtiRiAIpAoZpwngNgQSKSgSn9KCmKJHt9wEz1cGEiEYkAb/9ABt4wAkBUAQujADfTDQ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QLiEdm8NFgaYVYDrFmAMABAxoJ2dZEWCLAAA7GmEWC0B5gJAAABwCAhYMGQwNLLiDLA6AtAZYMsAYCHhU5McnWHEBjkxy0AockgGmFDnRzQ5ywIWIkFDloB0wqwUuWgFLmrBE5NsvWQIAzmzBVAywRYDrFDm0AY5ywduasFmCrBFgswSObMCFjWRZgocuIKHIEA6xaAiwR2UvPmDLAW50shgELFWAohQ5gsQWBmBIBCwC5Mc0ObMEXlCxlgOsAQE7LoTuy0whcmOSQGWBoAdYG8vWdfN1h6wSA485YHEAEBRzjQqwOIGmB/kkAdYaYeYKHNWAwKY5qwVOQHIWCzBDw78mlCQBrlRzFgLs32f7JAXOy+5QsNMJnJ3kzA0AYc3uUfKfkMAdY3c2eLrJpQOzQ5vs3EPApjlhz/ZDs2ue3Nrm0AYFXc5YGmDQC1yI5ywWgAwFnktzW5NKd1OoCNkiMVGps0oObM3SJygAA= -->

<!-- internal state end -->
<!-- tips_start -->

---



<details>
<summary>🪧 Tips</summary>

### Chat

There are 3 ways to chat with [CodeRabbit](https://coderabbit.ai?utm_source=oss&utm_medium=github&utm_campaign=ant-design/ant-design&utm_content=53401):

- Review comments: Directly reply to a review comment made by CodeRabbit. Example:
  - `I pushed a fix in commit <commit_id>, please review it.`
  - `Generate unit testing code for this file.`
  - `Open a follow-up GitHub issue for this discussion.`
- Files and specific lines of code (under the "Files changed" tab): Tag `@coderabbitai` in a new review comment at the desired location with your query. Examples:
  - `@coderabbitai generate unit testing code for this file.`
  -	`@coderabbitai modularize this function.`
- PR comments: Tag `@coderabbitai` in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
  - `@coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.`
  - `@coderabbitai read src/utils.ts and generate unit testing code.`
  - `@coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.`
  - `@coderabbitai help me debug CodeRabbit configuration file.`

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

### CodeRabbit Commands (Invoked using PR comments)

- `@coderabbitai pause` to pause the reviews on a PR.
- `@coderabbitai resume` to resume the paused reviews.
- `@coderabbitai review` to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
- `@coderabbitai full review` to do a full review from scratch and review all the files again.
- `@coderabbitai summary` to regenerate the summary of the PR.
- `@coderabbitai generate docstrings` to [generate docstrings](https://docs.coderabbit.ai/finishing-touches/docstrings) for this PR.
- `@coderabbitai resolve` resolve all the CodeRabbit review comments.
- `@coderabbitai plan` to trigger planning for file edits and PR creation.
- `@coderabbitai configuration` to show the current CodeRabbit configuration for the repository.
- `@coderabbitai help` to get help.

### Other keywords and placeholders

- Add `@coderabbitai ignore` anywhere in the PR description to prevent this PR from being reviewed.
- Add `@coderabbitai summary` to generate the high-level summary at a specific location in the PR description.
- Add `@coderabbitai` anywhere in the PR title to generate the title automatically.

### CodeRabbit Configuration File (`.coderabbit.yaml`)

- You can programmatically configure CodeRabbit by adding a `.coderabbit.yaml` file to the root of your repository.
- Please see the [configuration documentation](https://docs.coderabbit.ai/guides/configure-coderabbit) for more information.
- If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: `# yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json`

### Documentation and Community

- Visit our [Documentation](https://docs.coderabbit.ai) for detailed information on how to use CodeRabbit.
- Join our [Discord Community](http://discord.gg/coderabbit) to get help, request features, and share feedback.
- Follow us on [X/Twitter](https://twitter.com/coderabbitai) for updates and announcements.

</details>

<!-- tips_end -->

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 3, 2025

Preview is ready

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 3, 2025

👁 Visual Regression Report for PR #53401 Failed ❌

🎯 Target branch: feature (f5b9795)
📖 View Full Report ↗︎
📖 Alternative Report ↗︎
📊 Summary: 🆕 6 added

Expected (Branch feature) Actual (Current PR) Diff
statistic-timer.compact.css-var.png statistic-timer.compact.css-var.png 🆕🆕🆕 Added 🆕🆕🆕
statistic-timer.compact.png statistic-timer.compact.png 🆕🆕🆕 Added 🆕🆕🆕
statistic-timer.dark.css-var.png statistic-timer.dark.css-var.png 🆕🆕🆕 Added 🆕🆕🆕
statistic-timer.dark.png statistic-timer.dark.png 🆕🆕🆕 Added 🆕🆕🆕
statistic-timer.default.css-var.png statistic-timer.default.css-var.png 🆕🆕🆕 Added 🆕🆕🆕
statistic-timer.default.png statistic-timer.default.png 🆕🆕🆕 Added 🆕🆕🆕

Important

There are 6 diffs found in this PR: 🆕 6 added.
Please check all items:

  • Visual diff is acceptable

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented Apr 3, 2025

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 3, 2025

Bundle Report

Changes will increase total bundle size by 104 bytes (0.0%) ⬆️. This is within the configured threshold ✅

Detailed changes
Bundle name Size Change
antd.min-array-push 3.39MB 104 bytes (0.0%) ⬆️

Affected Assets, Files, and Routes:

view changes for bundle: antd.min-array-push

Assets Changed:

Asset Name Size Change Total Size Change (%)
antd-with-locales.min.js 52 bytes 1.85MB 0.0%
antd.min.js 52 bytes 1.54MB 0.0%

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🔭 Outside diff range comments (1)
components/statistic/Countdown.tsx (1)

13-63: 💡 Verification agent

🧩 Analysis chain

建议添加单元测试

新增的 reverse 功能应当有对应的单元测试,以确保功能在各种场景下都能正常工作,尤其是边界条件。


🏁 Script executed:

#!/bin/bash
# 查找是否有针对 reverse 功能的测试用例
echo "检查是否存在针对 reverse 功能的测试:"
rg -i "test.*reverse" --glob "*.test.ts*" components/statistic/
echo "----------------------------------------"
echo "检查现有的 Countdown 测试文件:"
fd "Countdown.test" components/

Length of output: 296


请补充 reverse 功能的单元测试

目前代码中新增的 reverse 功能尚未配套相应的单元测试,这可能导致在处理边界条件或特定场景时存在不可预见的问题。建议您在相关的测试文件中增加详细的测试用例,例如在 Countdown.test.tsx 中,针对不同场景(正向计时和反向计时)的边界条件进行测试,以保证功能的正确性和稳定性。

🧹 Nitpick comments (1)
components/statistic/Countdown.tsx (1)

40-40: 条件逻辑处理完善

定时器启动和停止条件的处理考虑了正向和反向两种模式,逻辑清晰。建议添加简短注释说明条件逻辑,以便其他开发者理解。

- if ((!reverse && timestamp >= Date.now()) || (reverse && timestamp <= Date.now())) {
+ // 正向模式:目标时间在将来才启动;反向模式:目标时间在过去才启动
+ if ((!reverse && timestamp >= Date.now()) || (reverse && timestamp <= Date.now())) {

- if ((!reverse && timestamp < Date.now()) || (reverse && timestamp > Date.now())) {
+ // 正向模式:目标时间已过期则停止;反向模式:理论上不会发生,保留以确保完整性
+ if ((!reverse && timestamp < Date.now()) || (reverse && timestamp > Date.now())) {

Also applies to: 45-45

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 17cfb7b and 9b13f5a.

⛔ Files ignored due to path filters (2)
  • components/statistic/__tests__/__snapshots__/demo-extend.test.ts.snap is excluded by !**/*.snap
  • components/statistic/__tests__/__snapshots__/demo.test.ts.snap is excluded by !**/*.snap
📒 Files selected for processing (5)
  • components/statistic/Countdown.tsx (4 hunks)
  • components/statistic/demo/countdown.tsx (2 hunks)
  • components/statistic/index.en-US.md (1 hunks)
  • components/statistic/index.zh-CN.md (1 hunks)
  • components/statistic/utils.ts (1 hunks)
🧰 Additional context used
🧬 Code Definitions (1)
components/statistic/Countdown.tsx (1)
components/statistic/utils.ts (1)
  • formatCountdown (62-69)
⏰ Context from checks skipped due to timeout of 90000ms (12)
  • GitHub Check: test-react-latest-dist (dist-min, 2/2)
  • GitHub Check: test-react-latest-dist (dist-min, 1/2)
  • GitHub Check: test-react-latest-dist (dist, 2/2)
  • GitHub Check: test-react-latest-dist (dist, 1/2)
  • GitHub Check: test-react-legacy (17, 2/2)
  • GitHub Check: test-react-legacy (17, 1/2)
  • GitHub Check: test-react-legacy (16, 2/2)
  • GitHub Check: test-react-latest (dom, 2/2)
  • GitHub Check: test-react-legacy (16, 1/2)
  • GitHub Check: test-react-latest (dom, 1/2)
  • GitHub Check: visual-diff snapshot (2/2)
  • GitHub Check: visual-diff snapshot (1/2)
🔇 Additional comments (10)
components/statistic/index.zh-CN.md (1)

59-59: API 文档更新正确

参数描述清晰准确,类型定义和默认值设置合理。

components/statistic/index.en-US.md (1)

58-58: API 文档更新正确

英文描述"reverse time counter"准确表达了该功能的作用,类型、默认值和版本号标注都很恰当。

components/statistic/utils.ts (1)

62-66: 逻辑实现正确

formatCountdown 函数改动合理,增加了 reverse 参数并正确实现了正反向计时的逻辑差异。

时间差值计算 diff = Math.max(reverse ? current - target : target - current, 0) 能够根据 reverse 参数灵活切换计时方向,同时保证差值不为负数。

components/statistic/demo/countdown.tsx (3)

8-8: 变量命名合理

before 变量命名直观地表示这是一个过去的时间点,用于演示反向计时功能。


28-33: 示例展示完整

这两个示例展示了正向和反向计时的对比效果,有助于用户理解新功能。其中 reverse 属性的使用方式清晰明了。


37-39: 格式化示例展示完整

此示例展示了带有格式化的反向计时,完善了功能演示。

components/statistic/Countdown.tsx (4)

13-13: 很好的接口扩展!

reverse 属性的添加使倒计时组件更加灵活,能够满足从过去时间点开始计时的需求。


24-24: 默认值设置合理

reverse 属性设置默认值为 false 保证了向后兼容性,现有代码无需修改即可继续使用。


43-44: 时间差计算处理正确

根据 reverse 属性计算时间差的逻辑正确,反向模式下计算当前时间与目标时间的差值,正向模式下计算目标时间与当前时间的差值。


63-63: 格式化函数参数传递完整

reverse 参数正确传递给 formatCountdown 函数,确保时间格式化能够根据计时方向正确处理。

Comment thread components/statistic/Countdown.tsx Outdated
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 3, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (f5b9795) to head (7673528).
Report is 1 commits behind head on feature.

Additional details and impacted files
@@            Coverage Diff            @@
##           feature    #53401   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          771       772    +1     
  Lines        13908     13914    +6     
  Branches      3664      3666    +2     
=========================================
+ Hits         13908     13914    +6     

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@afc163
Copy link
Copy Markdown
Member

afc163 commented Apr 3, 2025

参考这个 API:#36223

@lcgash
Copy link
Copy Markdown
Contributor Author

lcgash commented Apr 3, 2025

参考这个 API:#36223

要直接改成 Timer 么,这个改动会不会有点大,感觉完全是个新的组件了

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 9b13f5a and f0edd00.

📒 Files selected for processing (1)
  • components/statistic/Countdown.tsx (4 hunks)
🧰 Additional context used
🧬 Code Definitions (1)
components/statistic/Countdown.tsx (1)
components/statistic/utils.ts (1)
  • formatCountdown (62-69)
⏰ Context from checks skipped due to timeout of 90000ms (12)
  • GitHub Check: test-react-latest-dist (dist-min, 2/2)
  • GitHub Check: test-react-latest-dist (dist-min, 1/2)
  • GitHub Check: test-react-latest-dist (dist, 2/2)
  • GitHub Check: test-react-latest-dist (dist, 1/2)
  • GitHub Check: test-react-latest (dom, 2/2)
  • GitHub Check: test-react-latest (dom, 1/2)
  • GitHub Check: test-react-legacy (17, 2/2)
  • GitHub Check: test-react-legacy (17, 1/2)
  • GitHub Check: test-react-legacy (16, 2/2)
  • GitHub Check: test-react-legacy (16, 1/2)
  • GitHub Check: visual-diff snapshot (2/2)
  • GitHub Check: visual-diff snapshot (1/2)
🔇 Additional comments (4)
components/statistic/Countdown.tsx (4)

13-13: 增加了 reverse 属性,很好的功能扩展。

这个新增的可选属性让倒计时组件更加灵活,可以支持从过去时间点开始的正向计时。


24-24: 属性解构支持新增的 reverse 属性,并提供合理的默认值。

很好的实现了向后兼容性,默认值为 false 保证了原有功能不受影响。


40-41: 建议将重复的 Date.now() 调用提取为变量

根据之前的代码评审建议,interval 中有多处 Date.now() 调用,建议提取为一个变量,使代码更简洁易读。

  const syncTimer = () => {
    const timestamp = getTime(value);
    const now = Date.now();
    if ((!reverse && timestamp >= now) || (reverse && timestamp <= now)) {
      countdown.current = setInterval(() => {
-       const now = Date.now();
+       const currentTime = Date.now();
        forceUpdate();
-       const timeDiff = reverse ? now - timestamp : timestamp - now;
+       const timeDiff = reverse ? currentTime - timestamp : timestamp - currentTime;
        onChange?.(timeDiff);
-       if ((!reverse && timestamp < now) || (reverse && timestamp > now)) {
+       if ((!reverse && timestamp < currentTime) || (reverse && timestamp > currentTime)) {
          stopTimer();
        }
      }, REFRESH_INTERVAL);
    }
  };

65-65: 正确传递了 reverse 参数到 formatCountdown 函数

确保了格式化逻辑与计时方向一致,很好。

Comment thread components/statistic/Countdown.tsx Outdated
Comment thread components/statistic/index.en-US.md Outdated
@afc163
Copy link
Copy Markdown
Member

afc163 commented Apr 7, 2025

要直接改成 Timer 么,这个改动会不会有点大,感觉完全是个新的组件了

目标就是增加一个新组件,来同时支持正向/倒向的计时功能。

@lcgash lcgash changed the title feat: add reverse for countdown feat: support timer component Apr 8, 2025
@lcgash
Copy link
Copy Markdown
Contributor Author

lcgash commented Apr 8, 2025

要直接改成 Timer 么,这个改动会不会有点大,感觉完全是个新的组件了

目标就是增加一个新组件,来同时支持正向/倒向的计时功能。

大佬看看这样改对么

@lcgash lcgash changed the base branch from master to feature April 8, 2025 03:11
Comment thread components/statistic/Countdown.tsx
Comment thread components/statistic/utils.ts Outdated
lcgash and others added 3 commits April 8, 2025 13:57
Co-authored-by: graphite-app[bot] <96075541+graphite-app[bot]@users.noreply.github.com>
Signed-off-by: mr-chenguang <37072324+lcgash@users.noreply.github.com>
@thinkasany
Copy link
Copy Markdown
Member

https://github.com/ant-design/ant-design/actions/runs/14329441476/job/40161861632?pr=53401
› 2 snapshots failed from 1 test suite. Inspect your code changes or run npm run test:site -- -u to update them.
image

Comment thread components/statistic/index.zh-CN.md Outdated
Comment thread components/statistic/__tests__/index.test.tsx
Comment thread components/statistic/index.zh-CN.md Outdated
Comment thread components/statistic/__tests__/index.test.tsx Outdated
Comment thread components/statistic/Countdown.tsx
Comment thread components/statistic/__tests__/index.test.tsx Outdated
Comment thread components/statistic/Countdown.tsx Outdated
Comment thread components/statistic/__tests__/index.test.tsx Outdated
Comment thread components/statistic/index.zh-CN.md
@thinkasany thinkasany changed the title feat: support timer component feat: new component Statistic.Timer Apr 11, 2025
@thinkasany thinkasany merged commit bd13b34 into ant-design:feature Apr 11, 2025
51 checks passed
@github-actions
Copy link
Copy Markdown
Contributor

🎉 Thank you for your contribution! If you have not yet joined our DingTalk community group, please feel free to join us (when joining, please provide the link to this PR).

🎉 感谢您的贡献!如果您还没有加入钉钉社区群,请扫描下方二维码加入我们(加群时请提供此 PR 链接)。

@thinkasany
Copy link
Copy Markdown
Member

@lcgash Thanks for your contributions!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants