Skip to content

feat: indicator基础升级完成#3480

Open
xiyehutao wants to merge 2 commits into
jdf2e:feat_v4.xfrom
xiyehutao:feat_v16_indicator
Open

feat: indicator基础升级完成#3480
xiyehutao wants to merge 2 commits into
jdf2e:feat_v4.xfrom
xiyehutao:feat_v16_indicator

Conversation

@xiyehutao

@xiyehutao xiyehutao commented Jun 9, 2026

Copy link
Copy Markdown
Collaborator

🤔 这个变动的性质是?

  • [✅] 新特性提交

☑️ 请求合并前的自查清单

⚠️ 请自检并全部勾选全部选项⚠️

  • [☑️] 文档已补充或无须补充
  • [☑️] 代码演示已提供或无须提供
  • [☑️] TypeScript 定义已补充或无须补充
  • [☑️] fork仓库代码是否为最新避免文件冲突
  • [☑️] Files changed 没有 package.json lock 等无关文件

Summary by CodeRabbit

  • 新功能

    • 新增 placement 属性,支持多种放置位置(outside、inside-top-right、inside-bottom-center、inside-bottom-left)。
    • 补充类型支持(anchor/slide/dualScreen)与示例展示。
  • 示例

    • 新增第7组演示,展示多种 placement 布局(H5 与 Taro)。
  • 文档

    • 更新中/英/繁/小程序文档,新增定位布局说明与主题变量表。
  • 样式与主题

    • 调整点/滑块尺寸、圆角与若干样式变量,新增多项 CSS 变量。
  • 测试

    • 扩展测试覆盖,新增 placement、颜色、方向及 slide 场景。

@github-actions github-actions Bot added the action:review This PR needs more reviews (less than 2 approvals) label Jun 9, 2026
@coderabbitai

coderabbitai Bot commented Jun 9, 2026

Copy link
Copy Markdown

Review Change Stack

Walkthrough

新增 Indicator 的 placement 属性与定位样式支持;将 slide 模式位移计算暴露为 CSS 变量;补充样式变量与主题变量,新增 Demo7 演示并扩展中英/Taro 文档与单元测试覆盖。

Changes

Indicator 组件 placement 定位布局功能

Layer / File(s) Summary
placement 类型定义与接口
src/types/spec/indicator/base.ts
新增 IndicatorPlacement 联合类型(outside/inside-top-right/inside-bottom-center/inside-bottom-left),并在 BaseIndicator 中加入 placement 字段。
组件实现(H5 与 Taro)
src/packages/indicator/indicator.tsx, src/packages/indicator/indicator.taro.tsx
解构 placement 并基于其追加样式类名;将 type="slide" 的位移实现由 JS 内联 transform 改为通过 --nutui-indicator-current / --nutui-indicator-total 两个 CSS 变量暴露,移除 pxTransform 导入。
样式变量与 SCSS 实现
src/styles/variables.scss, src/styles/theme-default.scss, src/styles/theme-dark.scss, src/packages/indicator/indicator.scss
调整 dot 默认尺寸并新增一组 indicator 相关 SCSS 变量(dot border/inactive color/track/slider/dual-screen width/placement gap 等);新增主题变量 --nutui-indicator-border-radius;在 indicator.scss 中实现 placement 定位规则、fixed-width/dualScreen/vertical/white 主题样式与 RTL 反向支持,并把轨道位移与尺寸逻辑迁移到样式侧。
Demo7 演示与多语言集成
src/packages/indicator/demos/h5/demo7.tsx, src/packages/indicator/demos/taro/demo7.tsx, src/packages/indicator/demo.tsx, src/packages/indicator/demo.taro.tsx
新增 H5/Taro 的 Demo7 展示四种 placement;在 demo 页面中导入 Demo7 并添加 translated.placement 多语言文本与渲染区块。
文档更新(中英及 Taro 版)
src/packages/indicator/doc.md, src/packages/indicator/doc.en-US.md, src/packages/indicator/doc.taro.md, src/packages/indicator/doc.zh-TW.md
新增 Placement 小节与示例,更新 Props 表(添加 placement 条目并调整 total 默认值与 type/direction 描述),扩展 Theming 的 CSS 变量列表并更新默认值说明。
单元测试补充
src/packages/indicator/__test__/indicator.spec.tsx
新增对 type="slide" 输出 CSS 变量的断言,覆盖 dualScreen fixed-width、color="default" 白色变体、direction="vertical" 及四种 placement 类名断言。

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • jdf2e/nutui-react#3114: 早期 PR 引入了 dualScreen 类型与相关样式/测试,和本次 placement/样式调整有代码层面关联。
  • jdf2e/nutui-react#2746: 与本次对 slide 渲染逻辑与测试断言的修改存在直接重叠与延续关系。

Suggested reviewers

  • xiaoyatong
  • oasis-cloud
  • irisSong

🐰 指示器换新衣,四方位置任意移,
样式变量整齐列,slide 位移交样式里,
Demo 文档都铺开,测试断言把关齐,
小兔跳跃去庆贺,代码合入好喜气!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed 标题清晰指出了PR的核心内容——Indicator组件的基础升级,与changeset中广泛的功能增强、样式更新、文档完善高度一致。
Description check ✅ Passed PR描述按模板填写,选中了「新特性提交」,完成了预合并自查清单的全部5项检查(文档、演示、TypeScript定义、代码同步、文件清洁)。
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@codecov

codecov Bot commented Jun 9, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 88.42%. Comparing base (a938cf8) to head (ede7ddd).
⚠️ Report is 4 commits behind head on feat_v4.x.

Additional details and impacted files
@@              Coverage Diff              @@
##           feat_v4.x    #3480      +/-   ##
=============================================
+ Coverage      88.33%   88.42%   +0.09%     
=============================================
  Files            295      295              
  Lines          19747    19727      -20     
  Branches        3117     3116       -1     
=============================================
+ Hits           17443    17444       +1     
+ Misses          2298     2277      -21     
  Partials           6        6              

☔ View full report in Codecov by Harness.
📢 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.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (2)
src/packages/indicator/indicator.tsx (1)

58-59: ⚡ Quick win

建议提取滑块尺寸常量以提高可维护性。

硬编码的 trackWidth: 24sliderWidth: 8 与 SCSS 变量和文档一致,但如果将来这些值发生变化,需要在多个地方(包括 Taro 版本)同步更新。建议提取为命名常量或在文件顶部添加注释说明这些值与 CSS 变量的对应关系。

♻️ 建议的重构
+// 与 SCSS $indicator-track-width 和 $indicator-slider-width 保持一致
+const SLIDE_TRACK_WIDTH = 24
+const SLIDE_SLIDER_WIDTH = 8
+
 const renderLineElement = () => {
-  const trackWidth: number = 24
-  const sliderWidth: number = 8
+  const trackWidth: number = SLIDE_TRACK_WIDTH
+  const sliderWidth: number = SLIDE_SLIDER_WIDTH
   const stride = (trackWidth - sliderWidth) / (total - 1)
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/packages/indicator/indicator.tsx` around lines 58 - 59, Extract the
hardcoded numeric values into named constants at the top of indicator.tsx (e.g.,
SLIDER_TRACK_WIDTH and SLIDER_HANDLE_WIDTH) and replace usages of trackWidth and
sliderWidth with these constants; add a short comment above the constants noting
the corresponding SCSS variable names and documentation reference so future
changes stay in sync; ensure any other references (including Taro-specific
copies) use these constants or are documented where they diverge.
src/packages/indicator/indicator.taro.tsx (1)

63-64: ⚡ Quick win

建议提取滑块尺寸常量以提高可维护性。

与 H5 版本相同,硬编码的 trackWidth: 24sliderWidth: 8 应提取为命名常量,以便与 H5 版本保持同步并提高可维护性。

♻️ 建议的重构
+// 与 SCSS $indicator-track-width 和 $indicator-slider-width 保持一致
+const SLIDE_TRACK_WIDTH = 24
+const SLIDE_SLIDER_WIDTH = 8
+
 const renderLineElement = () => {
-  const trackWidth: number = 24
-  const sliderWidth: number = 8
+  const trackWidth: number = SLIDE_TRACK_WIDTH
+  const sliderWidth: number = SLIDE_SLIDER_WIDTH
   const stride = (trackWidth - sliderWidth) / (total - 1)
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/packages/indicator/indicator.taro.tsx` around lines 63 - 64, Extract the
hard-coded numeric values used for the slider into named constants (e.g.,
TRACK_WIDTH and SLIDER_WIDTH) instead of inline numbers; update the declarations
that currently set trackWidth and sliderWidth in indicator.taro.tsx to reference
these constants (and export them or import from a shared constants module if the
H5 version uses the same names) so both versions share the same definitions and
improve maintainability.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/types/spec/indicator/base.ts`:
- Line 18: The placement field is currently required but should be optional;
update the type declaration that defines placement (the property named placement
of type IndicatorPlacement) to be optional (add the ? modifier) so it reads as
an optional property, and ensure any related type/interface where placement
appears (the Indicator placement property in the indicator base type) reflects
this change to match the docs/default of "-".

---

Nitpick comments:
In `@src/packages/indicator/indicator.taro.tsx`:
- Around line 63-64: Extract the hard-coded numeric values used for the slider
into named constants (e.g., TRACK_WIDTH and SLIDER_WIDTH) instead of inline
numbers; update the declarations that currently set trackWidth and sliderWidth
in indicator.taro.tsx to reference these constants (and export them or import
from a shared constants module if the H5 version uses the same names) so both
versions share the same definitions and improve maintainability.

In `@src/packages/indicator/indicator.tsx`:
- Around line 58-59: Extract the hardcoded numeric values into named constants
at the top of indicator.tsx (e.g., SLIDER_TRACK_WIDTH and SLIDER_HANDLE_WIDTH)
and replace usages of trackWidth and sliderWidth with these constants; add a
short comment above the constants noting the corresponding SCSS variable names
and documentation reference so future changes stay in sync; ensure any other
references (including Taro-specific copies) use these constants or are
documented where they diverge.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 4bc353c0-9f11-427c-9f24-6433689c0277

📥 Commits

Reviewing files that changed from the base of the PR and between 11fcbd0 and 79e4288.

📒 Files selected for processing (16)
  • src/packages/indicator/__test__/indicator.spec.tsx
  • src/packages/indicator/demo.taro.tsx
  • src/packages/indicator/demo.tsx
  • src/packages/indicator/demos/h5/demo7.tsx
  • src/packages/indicator/demos/taro/demo7.tsx
  • src/packages/indicator/doc.en-US.md
  • src/packages/indicator/doc.md
  • src/packages/indicator/doc.taro.md
  • src/packages/indicator/doc.zh-TW.md
  • src/packages/indicator/indicator.scss
  • src/packages/indicator/indicator.taro.tsx
  • src/packages/indicator/indicator.tsx
  • src/styles/theme-dark.scss
  • src/styles/theme-default.scss
  • src/styles/variables.scss
  • src/types/spec/indicator/base.ts

direction: string
color: IndicatorColor
type: IndicatorType
placement: IndicatorPlacement

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical | ⚡ Quick win

placement 字段应该是可选的。

根据文档和组件实现,placement 属性应该是可选的(文档中默认值为 -),但当前类型定义中没有 ? 修饰符,这会导致类型错误并可能破坏现有代码。

🔧 建议修复
 export interface BaseIndicator extends BaseProps {
   total: number
   current: number
   direction: string
   color: IndicatorColor
   type: IndicatorType
-  placement: IndicatorPlacement
+  placement?: IndicatorPlacement
 }
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/types/spec/indicator/base.ts` at line 18, The placement field is
currently required but should be optional; update the type declaration that
defines placement (the property named placement of type IndicatorPlacement) to
be optional (add the ? modifier) so it reads as an optional property, and ensure
any related type/interface where placement appears (the Indicator placement
property in the indicator base type) reflects this change to match the
docs/default of "-".

@xiyehutao

Copy link
Copy Markdown
Collaborator Author

新版:image

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/packages/indicator/indicator.scss`:
- Around line 200-208: The calc expression inside the &-active selector breaks
Stylelint rules by placing binary operators at the end of lines; reformat the
calc so operators start the wrapped lines (e.g., put the "/" and "-" at the
beginning of their respective continued lines) to match the horizontal-mode
formatting and satisfy Stylelint; update the expression that uses
var(--nutui-indicator-current), var(--nutui-indicator-total),
#{$indicator-track-width} and #{$indicator-slider-width} within transform:
translateY(calc(...)) accordingly.
- Around line 85-91: The SCSS calc expression inside transform: translateX
currently breaks lines immediately after the / and * operators which violates
scss/operator-no-newline-after; update the calc so the operators are not
followed by a newline (e.g., place the / and * at the end of the preceding lines
or put the whole calc on one line) for the expression that uses
var(--nutui-indicator-current, 0), var(--nutui-indicator-total, 2),
$indicator-track-width and $indicator-slider-width inside transform:
translateX(calc(...)) to satisfy the lint rule.

In `@src/packages/indicator/indicator.tsx`:
- Around line 60-65: indicator passes the raw total into the CSS variable
--nutui-indicator-total, which makes the calc in indicator.scss divide by (total
- 1) and produce NaN when total === 1; update the component (indicator.tsx /
indicator.taro.tsx) to clamp/protect BaseIndicator.total before assigning the
CSS var (e.g. compute a safeTotal = Math.max(total, 2) and set
'--nutui-indicator-total' to safeTotal) so the CSS denominator never becomes
zero; alternatively also consider a defensive CSS change (use
max(var(--nutui-indicator-total) - 1, 1)) but the primary fix is to ensure the
component sets a minimum total >= 2.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 8a0eb9c6-cab6-4947-a7ef-1c31843e0060

📥 Commits

Reviewing files that changed from the base of the PR and between 79e4288 and ede7ddd.

📒 Files selected for processing (4)
  • src/packages/indicator/__test__/indicator.spec.tsx
  • src/packages/indicator/indicator.scss
  • src/packages/indicator/indicator.taro.tsx
  • src/packages/indicator/indicator.tsx

Comment on lines +85 to +91
transform: translateX(
calc(
var(--nutui-indicator-current, 0) /
(var(--nutui-indicator-total, 2) - 1) *
(#{$indicator-track-width} - #{$indicator-slider-width})
)
);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical | ⚡ Quick win

修复 SCSS 运算符换行格式问题。

Stylelint 检测到第 87 和 88 行在 /* 运算符后存在换行,违反 scss/operator-no-newline-after 规则,可能导致 CI 失败。

🔧 建议的格式修复
       transform: translateX(
         calc(
-          var(--nutui-indicator-current, 0) /
-            (var(--nutui-indicator-total, 2) - 1) *
-            (#{$indicator-track-width} - #{$indicator-slider-width})
+          var(--nutui-indicator-current, 0) / (var(--nutui-indicator-total, 2) - 1) * (#{$indicator-track-width} - #{$indicator-slider-width})
         )
       );
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
transform: translateX(
calc(
var(--nutui-indicator-current, 0) /
(var(--nutui-indicator-total, 2) - 1) *
(#{$indicator-track-width} - #{$indicator-slider-width})
)
);
transform: translateX(
calc(
var(--nutui-indicator-current, 0) / (var(--nutui-indicator-total, 2) - 1) * (#{$indicator-track-width} - #{$indicator-slider-width})
)
);
🧰 Tools
🪛 Stylelint (17.12.0)

[error] 87-87: Unexpected newline after "/" (scss/operator-no-newline-after)

(scss/operator-no-newline-after)


[error] 88-88: Unexpected newline after "*" (scss/operator-no-newline-after)

(scss/operator-no-newline-after)

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/packages/indicator/indicator.scss` around lines 85 - 91, The SCSS calc
expression inside transform: translateX currently breaks lines immediately after
the / and * operators which violates scss/operator-no-newline-after; update the
calc so the operators are not followed by a newline (e.g., place the / and * at
the end of the preceding lines or put the whole calc on one line) for the
expression that uses var(--nutui-indicator-current, 0),
var(--nutui-indicator-total, 2), $indicator-track-width and
$indicator-slider-width inside transform: translateX(calc(...)) to satisfy the
lint rule.

Source: Linters/SAST tools

Comment on lines +200 to +208
&-active {
transform: translateY(
calc(
var(--nutui-indicator-current, 0) /
(var(--nutui-indicator-total, 2) - 1) *
(#{$indicator-track-width} - #{$indicator-slider-width})
)
);
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical | ⚡ Quick win

修复竖向模式的运算符换行格式问题。

与横向模式相同,第 203 和 204 行在运算符后存在换行,违反 Stylelint 规则。

🔧 建议的格式修复
         &-active {
           transform: translateY(
             calc(
-              var(--nutui-indicator-current, 0) /
-                (var(--nutui-indicator-total, 2) - 1) *
-                (#{$indicator-track-width} - #{$indicator-slider-width})
+              var(--nutui-indicator-current, 0) / (var(--nutui-indicator-total, 2) - 1) * (#{$indicator-track-width} - #{$indicator-slider-width})
             )
           );
         }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
&-active {
transform: translateY(
calc(
var(--nutui-indicator-current, 0) /
(var(--nutui-indicator-total, 2) - 1) *
(#{$indicator-track-width} - #{$indicator-slider-width})
)
);
}
&-active {
transform: translateY(
calc(
var(--nutui-indicator-current, 0) / (var(--nutui-indicator-total, 2) - 1) * (#{$indicator-track-width} - #{$indicator-slider-width})
)
);
}
🧰 Tools
🪛 Stylelint (17.12.0)

[error] 203-203: Unexpected newline after "/" (scss/operator-no-newline-after)

(scss/operator-no-newline-after)


[error] 204-204: Unexpected newline after "*" (scss/operator-no-newline-after)

(scss/operator-no-newline-after)

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/packages/indicator/indicator.scss` around lines 200 - 208, The calc
expression inside the &-active selector breaks Stylelint rules by placing binary
operators at the end of lines; reformat the calc so operators start the wrapped
lines (e.g., put the "/" and "-" at the beginning of their respective continued
lines) to match the horizontal-mode formatting and satisfy Stylelint; update the
expression that uses var(--nutui-indicator-current),
var(--nutui-indicator-total), #{$indicator-track-width} and
#{$indicator-slider-width} within transform: translateY(calc(...)) accordingly.

Source: Linters/SAST tools

Comment on lines +60 to +65
style={
{
'--nutui-indicator-current': current,
'--nutui-indicator-total': total,
} as React.CSSProperties
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# 检查是否有 total 最小值校验或相关文档

# 搜索 total 的验证逻辑
rg -n -C3 'total.*[>=<].*1' --type ts --type tsx

# 搜索文档中是否说明 total 最小值
rg -n 'total.*minimum|minimum.*total|total.*至少|至少.*total' --glob '*.md'

Repository: jdf2e/nutui-react

Length of output: 89


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# 1) 确认 indicator 相关文件
echo "=== indicator.tsx ==="
sed -n '1,140p' src/packages/indicator/indicator.tsx

# 2) 搜索 total 的校验/默认值/prop 类型
echo
echo "=== Search total validation/usage in indicator package ==="
rg -n --hidden --no-ignore-vcs "total" src/packages/indicator -S

# 3) 搜索 CSS 变量在样式中如何用于 calc(total - 1)
echo
echo "=== Search for nutui-indicator-total usage ==="
rg -n "nutui-indicator-total|indicator-total" -S src/packages/indicator

# 4) 在整个 repo 搜索 calc( ... - 1 ) 与 indicator 相关的写法
echo
echo "=== Search calc with total-1 near indicator ==="
rg -n "calc\\([^\\)]*\\-\\s*1\\)|\\(\\s*total\\s*\\-\\s*1\\s*\\)|total\\s*\\-\\s*1" -S src/packages/indicator src/packages -g'*.{scss,css,less,ts,tsx,js,jsx}'

# 5) 搜索文档/示例是否注明 total 最小值
echo
echo "=== Search docs for total minimum mention ==="
rg -n "total.*(最小|至少|min|minimum)|至少.*total|minimum.*total" --glob '*.md' -S

Repository: jdf2e/nutui-react

Length of output: 8601


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# 1) 确认 indicator 相关文件
echo "=== indicator.tsx ==="
sed -n '1,220p' src/packages/indicator/indicator.tsx

# 2) 搜索 total 的校验/默认值/prop 类型
echo
echo "=== Search total validation/usage in indicator package ==="
rg -n --hidden --no-ignore-vcs "total" src/packages/indicator -S

# 3) 搜索 CSS 变量在样式中如何用于 calc(total - 1)
echo
echo "=== Search for nutui-indicator-total usage ==="
rg -n "nutui-indicator-total|indicator-total" -S src/packages/indicator

# 4) 在整个 repo 搜索 calc( ... - 1 ) 与 indicator 相关的写法
echo
echo "=== Search calc with total-1 near indicator ==="
rg -n "calc\\([^\\)]*\\-\\s*1\\)|\\(\\s*total\\s*\\-\\s*1\\s*\\)|total\\s*\\-\\s*1" -S src/packages/indicator src/packages -g'*.{scss,css,less,ts,tsx,js,jsx}'

# 5) 搜索文档/示例是否注明 total 最小值
echo
echo "=== Search docs for total minimum mention ==="
rg -n "total.*(最小|至少|min|minimum)|至少.*total|minimum.*total|total\\s*>=\\s*1|total\\s*\\.?\\s*>=\\s*1" --glob '*.md' -S

Repository: jdf2e/nutui-react

Length of output: 8601


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# 1) 确认 indicator 相关文件
echo "=== indicator.tsx ==="
sed -n '1,220p' src/packages/indicator/indicator.tsx

# 2) 搜索 total 的校验/默认值/prop 类型
echo
echo "=== Search total validation/usage in indicator package ==="
rg -n --hidden --no-ignore-vcs "total" src/packages/indicator -S

# 3) 搜索 CSS 变量在样式中如何用于 calc(total - 1)
echo
echo "=== Search for nutui-indicator-total usage ==="
rg -n "nutui-indicator-total|indicator-total" -S src/packages/indicator

# 4) 在整个 repo 搜索 calc( ... - 1 ) 与 indicator 相关的写法
echo
echo "=== Search calc with total-1 near indicator ==="
rg -n "calc\\([^\\)]*\\-\\s*1\\)|\\(\\s*total\\s*\\-\\s*1\\s*\\)|total\\s*\\-\\s*1" -S src/packages/indicator src/packages -g'*.{scss,css,less,ts,tsx,js,jsx}'

# 5) 搜索文档/示例是否注明 total 最小值
echo
echo "=== Search docs for total minimum mention ==="
rg -n "total.*(最小|至少|min|minimum)|至少.*total|minimum.*total|total\\s*>=\\s*1|total\\s*\\.?\\s*>=\\s*1" --glob '*.md' -S

Repository: jdf2e/nutui-react

Length of output: 8601


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "=== indicator.tsx ==="
sed -n '1,220p' src/packages/indicator/indicator.tsx

echo
echo "=== Search total validation/usage in indicator package ==="
rg -n "total" src/packages/indicator -S

echo
echo "=== Search for nutui-indicator-total usage ==="
rg -n "nutui-indicator-total|indicator-total" src/packages/indicator -S

echo
echo "=== Search calc with total-1 near indicator ==="
rg -n "calc\\([^\\)]*\\-\\s*1\\)|\\(\\s*total\\s*\\-\\s*1\\s*\\)|total\\s*\\-\\s*1" -S src/packages/indicator src/packages -g'*.{scss,css,less,ts,tsx,js,jsx}'

echo
echo "=== Search docs for total minimum mention ==="
rg -n "total.*(最小|至少|min|minimum)|至少.*total|minimum.*total|total\\s*>=\\s*1|total\\s*\\.?\\s*>=\\s*1" --glob '*.md' -S

Repository: jdf2e/nutui-react

Length of output: 8601


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "=== indicator.tsx ==="
sed -n '1,220p' src/packages/indicator/indicator.tsx

echo
echo "=== Search total validation/usage in indicator package ==="
rg -n "total" src/packages/indicator -S

echo
echo "=== Search for nutui-indicator-total usage ==="
rg -n "nutui-indicator-total|indicator-total" src/packages/indicator -S

echo
echo "=== Search calc with total-1 near indicator ==="
rg -n "calc\\([^\\)]*\\-\\s*1\\)|\\(\\s*total\\s*\\-\\s*1\\s*\\)|total\\s*\\-\\s*1" -S src/packages/indicator src/packages -g'*.{scss,css,less,ts,tsx,js,jsx}'

echo
echo "=== Search docs for total minimum mention ==="
rg -n "total.*(最小|至少|min|minimum)|至少.*total|minimum.*total|total\\s*>=\\s*1|total\\s*\\.?\\s*>=\\s*1" --glob '*.md' -S

Repository: jdf2e/nutui-react

Length of output: 8601


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "=== indicator.scss (around line 70-110) ==="
sed -n '60,110p' src/packages/indicator/indicator.scss

echo
echo "=== indicator.scss (around line 180-240) ==="
sed -n '170,240p' src/packages/indicator/indicator.scss

echo
echo "=== indicator.taro.tsx (for parity) ==="
sed -n '1,120p' src/packages/indicator/indicator.taro.tsx

echo
echo "=== doc.md total prop description (around line 60-100) ==="
sed -n '60,100p' src/packages/indicator/doc.md

Repository: jdf2e/nutui-react

Length of output: 6040


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Locate WebIndicatorProps / TaroIndicatorProps definition
echo "=== Search for WebIndicatorProps definition ==="
rg -n "export (interface|type) WebIndicatorProps" -S src | head

echo
echo "=== Search for total in WebIndicatorProps ==="
rg -n "WebIndicatorProps|TaroIndicatorProps" -S src/types src | head -n 50

echo
echo "=== Search for TaroIndicatorProps definition ==="
rg -n "export (interface|type) TaroIndicatorProps" -S src | head

echo
echo "=== Search for runtime guard/clamp for total in indicator code ==="
rg -n "total\\s*(<=|>=|<|>|Math\\.|max\\(|min\\()" -S src/packages/indicator

echo
echo "=== Search for clamping total in entire repo ==="
rg -n "total\\s*(<=|>=|<|>|Math\\.|max\\(|min\\()" -S src | head -n 50

Repository: jdf2e/nutui-react

Length of output: 1528


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "=== Search for BaseIndicator definition ==="
rg -n "BaseIndicator" src/types -S

echo
echo "=== Print files containing BaseIndicator (first matches) ==="
# Use rg to list likely file paths then show relevant sections
files=$(rg -l "BaseIndicator" src/types -S)
for f in $files; do
  echo "--- $f ---"
  sed -n '1,200p' "$f"
done

Repository: jdf2e/nutui-react

Length of output: 1437


total=1 时 slide 模式会导致 CSS calc 除零从而位移失效
indicator.tsx/indicator.taro.tsx--nutui-indicator-total 直接设为 total,而 indicator.scsstransform: translateX/translateY(calc(var(--nutui-indicator-current) / (var(--nutui-indicator-total) - 1) * ...)) 的分母是 (total - 1):当 total={1} 时分母为 0,calc() 结果无效,可能出现视觉错误。BaseIndicator.total 仅为 number,代码/文档未见最小值约束。
建议在组件侧对 total 进行最小值保护(如 clamp 到 >= 2),或在 CSS 中用 max(var(--nutui-indicator-total) - 1, 1) 避免除零。

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/packages/indicator/indicator.tsx` around lines 60 - 65, indicator passes
the raw total into the CSS variable --nutui-indicator-total, which makes the
calc in indicator.scss divide by (total - 1) and produce NaN when total === 1;
update the component (indicator.tsx / indicator.taro.tsx) to clamp/protect
BaseIndicator.total before assigning the CSS var (e.g. compute a safeTotal =
Math.max(total, 2) and set '--nutui-indicator-total' to safeTotal) so the CSS
denominator never becomes zero; alternatively also consider a defensive CSS
change (use max(var(--nutui-indicator-total) - 1, 1)) but the primary fix is to
ensure the component sets a minimum total >= 2.

@xiaoyatong

Copy link
Copy Markdown
Collaborator

辛苦关注下 ai 评审~

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

Labels

action:review This PR needs more reviews (less than 2 approvals) size/L

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants