Skip to content

Conversation

@Chralay
Copy link

@Chralay Chralay commented Jan 21, 2026

用[主题编辑器]修改行高之后,导出主题配置theme.json,将它放到<ConfigProvider>后会出现TS报错:"token.lineHeight" 的类型不兼容。类型“string”不可与类型“number”进行比较。
image

产生TS报错的原因是theme.json里lineHeight为string类型与ThemeConfig类型要求的number不一致。

当前PR将lineHeight* 字段改为InputNumber,确保导出配置时是number类型。

Summary by CodeRabbit

发布说明

  • 改进
    • 优化了行高令牌的输入体验,改用数字输入控件以提升准确性和操作效率
    • 保持了阴影效果令牌的原有文本输入方式

✏️ Tip: You can customize this high-level summary in your review settings.

@gemini-code-assist
Copy link

Summary of Changes

Hello @Chralay, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

此拉取请求旨在解决一个关键的 TypeScript 类型不兼容问题,该问题发生在从主题编辑器导出配置时,lineHeight 令牌被错误地处理为字符串类型。通过将所有 lineHeight 相关的输入字段替换为 InputNumber 组件,确保这些令牌在导出时始终是数字类型,从而消除了类型错误,并提升了主题配置的稳定性和可靠性。

Highlights

  • 解决类型不兼容问题: 修复了从主题编辑器导出主题配置后,lineHeight 令牌在 theme.json 中为字符串类型,导致与 ThemeConfig 要求的 number 类型不兼容的 TypeScript 报错。
  • 引入 InputNumber 组件: 在 src/token-panel-pro/TokenContent.tsx 文件中引入了 Ant Design 的 InputNumber 组件。
  • 修改行高输入方式: 将主题编辑器中所有 lineHeight 相关的字段的输入组件从通用文本输入改为 InputNumber,确保导出的配置中 lineHeight 始终为数字类型。
  • 调整渲染逻辑: 修改了 SeedTokenPreview 组件的渲染逻辑,将 boxShadowlineHeight 的处理逻辑分开,为 lineHeight 专门使用 InputNumber

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@coderabbitai
Copy link

coderabbitai bot commented Jan 21, 2026

📝 Walkthrough

Walkthrough

该变更在 TokenContent.tsx 中将非色彩种子输入的处理分为两个独立分支:保留 boxShadow 开头的 tokenName 使用 TextArea 渲染,新增 lineHeight 开头的 tokenName 使用 InputNumber 组件渲染。同时添加了 InputNumber 的显式导入。

Changes

Cohort / File(s) 变更摘要
InputNumber 导入与 lineHeight 输入优化
src/token-panel-pro/TokenContent.tsx
添加 InputNumber 组件的显式导入;拆分原有条件分支,为 lineHeight tokens 新增单独分支,使用 InputNumber 组件替代文本输入,通过 handleChange 绑定数值更新(无效值默认为0);保持 boxShadow tokens 原有 TextArea 渲染逻辑不变

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Poem

🐰 一只小兔跃过数值的田野,
线高从文本蜕变成数字精灵,
InputNumber 闪闪发光,整整齐齐,
boxShadow 稳如磐石,依然如昨,
分支明晰,逻辑如诗!✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed 标题清晰准确地总结了主要变更:将lineHeight令牌的输入方式从文本改为数值输入。
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

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

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

Copy link

@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

🤖 Fix all issues with AI agents
In `@src/token-panel-pro/TokenContent.tsx`:
- Around line 398-406: The InputNumber for lineHeight currently falls back to 0
when newValue is nullish which can hide text; in the token rendering branch
where tokenName.startsWith('lineHeight') use InputNumber props to enforce a
sensible minimum (e.g., min={1}) and change the onChange fallback from 0 to a
safer default (e.g., 1) by passing handleChange(newValue ?? 1); also add/update
the seedRange for the 'lineHeight' token in the same token definition area
(similar to fontSize/borderRadius) to provide a consistent allowed range for
generated values.

Comment on lines +398 to +406
{tokenName.startsWith('lineHeight') && (
<div>
<InputNumber<number>
style={{ minWidth: 200 }}
value={tokenValue}
onChange={(newValue) => handleChange(newValue ?? 0)}
/>
</div>
)}
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

清除输入时回退到 0 可能导致问题

当用户清空输入框时,newValuenull/undefined,代码会将其设为 0。但 lineHeight: 0 会导致文本不可见或排版异常。

建议添加 min 约束,并使用更合理的回退值:

🔧 建议的修复
      {tokenName.startsWith('lineHeight') && (
        <div>
          <InputNumber<number>
            style={{ minWidth: 200 }}
            value={tokenValue}
-           onChange={(newValue) => handleChange(newValue ?? 0)}
+           onChange={(newValue) => handleChange(newValue ?? 1)}
+           min={1}
+           step={0.1}
          />
        </div>
      )}

另外,可考虑像其他数值类型 token(如 fontSizeborderRadius)一样,在 seedRange 中为 lineHeight 定义合理的取值范围,以保持一致性。

📝 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
{tokenName.startsWith('lineHeight') && (
<div>
<InputNumber<number>
style={{ minWidth: 200 }}
value={tokenValue}
onChange={(newValue) => handleChange(newValue ?? 0)}
/>
</div>
)}
{tokenName.startsWith('lineHeight') && (
<div>
<InputNumber<number>
style={{ minWidth: 200 }}
value={tokenValue}
onChange={(newValue) => handleChange(newValue ?? 1)}
min={1}
step={0.1}
/>
</div>
)}
🤖 Prompt for AI Agents
In `@src/token-panel-pro/TokenContent.tsx` around lines 398 - 406, The InputNumber
for lineHeight currently falls back to 0 when newValue is nullish which can hide
text; in the token rendering branch where tokenName.startsWith('lineHeight') use
InputNumber props to enforce a sensible minimum (e.g., min={1}) and change the
onChange fallback from 0 to a safer default (e.g., 1) by passing
handleChange(newValue ?? 1); also add/update the seedRange for the 'lineHeight'
token in the same token definition area (similar to fontSize/borderRadius) to
provide a consistent allowed range for generated values.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

本次 PR 修复了 lineHeight token 在主题编辑器中导出为字符串,导致 TypeScript 类型不兼容的问题。通过将输入控件从 Input.TextArea 更换为 InputNumber,确保了 lineHeight 的值为数字类型。整体修改是正确的,并且解决了描述中的问题。我只提出了一点小建议,以增强 InputNumber 组件的健壮性和易用性。

Comment on lines +400 to +404
<InputNumber<number>
style={{ minWidth: 200 }}
value={tokenValue}
onChange={(newValue) => handleChange(newValue ?? 0)}
/>

Choose a reason for hiding this comment

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

medium

为了提高组件的健壮性,建议为 lineHeightInputNumber 组件添加 min={0} 属性,以防止用户输入无效的负值。另外,为了提升用户体验,可以考虑添加 step={0.1} 属性,让用户可以更精细地调整行高。

          <InputNumber<number>
            style={{ minWidth: 200 }}
            min={0}
            step={0.1}
            value={tokenValue}
            onChange={(newValue) => handleChange(newValue ?? 0)}
          />

Copy link
Author

Choose a reason for hiding this comment

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

用户输入负值时是用户的事情啊,为啥要防止呢?

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.

1 participant