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(Button): RN & 鸿蒙适配 #2382

Merged
merged 5 commits into from
Jun 26, 2024
Merged

Conversation

xiaoyatong
Copy link
Collaborator

@xiaoyatong xiaoyatong commented Jun 24, 2024

🤔 这个变动的性质是?

  • 新特性提交
  • 日常 bug 修复
  • 站点、文档改进
  • 演示代码改进
  • 组件样式/交互改进
  • TypeScript 定义更新
  • 包体积优化
  • 性能优化
  • 功能增强
  • 国际化改进
  • 重构
  • 代码风格优化
  • 测试用例
  • 分支合并
  • 其他改动(是关于什么的改动?)

🔗 相关 Issue

💡 需求背景和解决方案

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

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

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

Summary by CodeRabbit

  • 样式

    • 更新按钮样式以支持多种尺寸、颜色及状态,并增强互动状态(如悬停、点击)的视觉效果。
    • 调整禁用状态按钮的样式,使其具有更明显的视觉提示。
    • 优化按钮在不同平台上的样式一致性。
  • 功能

    • 基于平台动态设置按钮的边距和宽度,提升跨平台用户体验。
  • 组件

    • 更新了Button组件的样式逻辑,优化了背景色、边框色的处理。
  • 示例

    • 修改了多个示例文件,动态设置按钮的marginStyle以适应不同平台。

Copy link

coderabbitai bot commented Jun 24, 2024

Warning

Review failed

The pull request is closed.

Walkthrough

这些变化是关于按钮组件的样式和功能的改进,涵盖了从样式文件到示例演示代码的广泛调整。具体包括对按钮的颜色、边框、背景、字体等属性的修改,以及在不同平台和状态下的条件样式处理。这些改进旨在提高按钮组件的视觉效果和可用性。

Changes

文件路径 更改摘要
src/.../button.copy.scss 添加全面的按钮样式定义,包括多种按钮变体的配置及交互状态的视觉反馈。
src/.../button.harmony.css 调整按钮各类样式属性,简化类名,并优化禁用状态下的按钮样式。
src/.../button.scss 添加基于平台的条件样式,调整字体、颜色、背景等属性,并优化禁用和加载状态的按钮样式。
src/.../button.taro.tsx 调整样式逻辑,支持颜色属性处理,动态生成类名,并优化容器样式管理。
src/.../button/demos/taro/demo10.tsx 更新 marginStyle 基于平台的条件样式,优化按钮宽度和边距。
src/.../button/demos/taro/demo2.tsx 更新 marginStyle 添加基于平台的条件样式处理。
src/.../button/demos/taro/demo3.tsx 更新 marginStyle 包含宽度和其他边距属性。
src/.../button/demos/taro/demo4.tsx 添加 pxTransform 导入,修改 marginStyle 对象,添加多种按钮配置。
src/.../button/demos/taro/demo5.tsx 导入 pxTransform,扩展 marginStyle 对象,条件渲染多种禁用按钮样式。
src/.../button/demos/taro/demo6.tsx 更新 marginStyle 基于平台的条件样式,调整按钮宽度和边距。
src/.../button/demos/taro/demo7.tsx 更新 marginStyle 对象,包含各边距属性。
src/.../button/demos/taro/demo8.tsx 更新 marginStylemarginStyleXL 基于平台的条件样式,调整按钮宽度和边距。

Sequence Diagram(s)

无需生成。

Poem

在代码的森林里,
按钮换上新装,
边框色彩闪亮,
加载禁用齐欢,
版式清晰流畅,
格局搭配不慌,
代码铿锵,美如诗行。

🐰✨


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

‼️ IMPORTANT
Auto-reply has been disabled for this repository in the CodeRabbit settings. The CodeRabbit bot will not respond to your replies unless it is explicitly tagged.

  • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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 as 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 resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration 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 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 for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

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: 2

Comment on lines 1 to 447
}

&-warning {
color: $button-warning-border-color;
background-origin: border-box;
border-width: $button-border-width;
border-style: solid;
border-color: $button-warning-border-color;

&-solid {
color: $button-warning-color;
background: $button-warning-background-color;
border-color: transparent;
}

&-dashed {
border-style: dashed;
}

&-none {
border-color: transparent;
}

&-disabled {
background: transparent;
color: $button-warning-disabled;
border-color: $button-warning-disabled;
}

&-solid-disabled {
color: $button-warning-color;
background: $button-warning-disabled;
}

&-none-disabled {
border-color: transparent;
}
}

&-block {
display: block;
width: 100%;
}

&-solid {
color: $button-primary-color;
background: $button-primary-background-color;
background-origin: border-box;
border: $button-border-width solid transparent;

&.nut-button-disabled {
color: $button-default-disabled-color;
background: $button-default-disabled;
}
}

&-outline,
&-dashed {
background: transparent;
}

&-none {
background: transparent;
border-color: transparent;
background: transparent;
}

&-disabled {
cursor: not-allowed;
color: #ffffff;
background: $button-default-disabled;
border-color: $button-default-disabled;
}

&-loading {
cursor: default;
opacity: 0.9;
}

&-round {
border-radius: $button-border-radius;

&.nut-button-xlarge,
&.nut-button-large {
border-radius: $button-large-border-radius;
}

&.nut-button-small {
border-radius: $button-small-border-radius;
}

&.nut-button-mini {
border-radius: $button-mini-border-radius;
}
}

&-square {
border-radius: $button-square-border-radius;
}
}
Copy link

Choose a reason for hiding this comment

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

文件内容与button.scss相似,但存在重复。

这个文件似乎是button.scss的副本,包含了相同的样式指令。建议检查是否有必要保留此文件,或者考虑合并以避免代码冗余。

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

备份文件已删除。错误提交

Comment on lines +127 to +128
className={` ${props.fill || disabled || loading ? `nut-button-${type}${props.fill ? `-${fill}` : ''}${disabled || loading ? '-disabled' : ''}` : ''} ${icon || loading ? 'nut-button-text' : ''}${
rightIcon ? ' nut-button-text-right' : ''
Copy link

Choose a reason for hiding this comment

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

条件渲染复杂类名的优化

这里根据 props.fill, disabled, loading 状态动态生成类名。建议在这种复杂逻辑中添加注释,说明每个条件的用途,以提高代码的可读性。

- className={` ${props.fill || disabled || loading ? `nut-button-${type}${props.fill ? `-${fill}` : ''}${disabled || loading ? '-disabled' : ''}` : ''} ${icon || loading ? 'nut-button-text' : ''}${
- rightIcon ? ' nut-button-text-right' : ''
- }`}
+ // 添加注释说明各个条件
+ className={` ${props.fill || disabled || loading ? `nut-button-${type}${props.fill ? `-${fill}` : ''}${disabled || loading ? '-disabled' : ''}` : ''} ${icon || loading ? 'nut-button-text' : ''}${rightIcon ? ' nut-button-text-right' : ''}`}

Committable suggestion was skipped due to low confidence.

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: 4

Comment on lines +151 to +155
[`${prefixCls}-${shape}-${size}`]: shape && size,
[`${prefixCls}-block`]: block,
[`${prefixCls}-disabled`]: disabled || loading,
[`${prefixCls}-${type}${props.fill ? `-${fill}` : ''}-disabled`]:
disabled || loading,
Copy link

Choose a reason for hiding this comment

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

优化类名动态生成逻辑

此代码段负责根据不同的属性动态生成类名,但存在一些冗余和复杂的逻辑。可以通过简化条件判断来优化这部分代码,提高其可读性和可维护性。

-  [`${prefixCls}-${type}${props.fill ? `-${fill}` : ''}-disabled`]:
+  [`${prefixCls}-${type}${props.fill ? `-${fill}` : ''}${disabled || loading ? '-disabled' : ''}`]: true,
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
[`${prefixCls}-${shape}-${size}`]: shape && size,
[`${prefixCls}-block`]: block,
[`${prefixCls}-disabled`]: disabled || loading,
[`${prefixCls}-${type}${props.fill ? `-${fill}` : ''}-disabled`]:
disabled || loading,
[`${prefixCls}-${shape}-${size}`]: shape && size,
[`${prefixCls}-block`]: block,
[`${prefixCls}-disabled`]: disabled || loading,
[`${prefixCls}-${type}${props.fill ? `-${fill}` : ''}${disabled || loading ? '-disabled' : ''}`]: true,

Comment on lines +170 to +173
className={`nut-button-children nut-button-${size}-children nut-button-${type}-children ${!(props.fill || disabled || loading) ? '' : `nut-button-${type}${props.fill ? `-${fill}` : ''}${disabled || loading ? '-disabled' : ''}`} ${icon || loading ? `nut-button-text` : ''}${
rightIcon ? ` nut-button-text-right` : ''
}`}
style={harmonyAndRn() ? getContStyle() : ''}
Copy link

Choose a reason for hiding this comment

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

优化子组件类名和样式设置

此代码段负责为子组件设置类名和样式。建议优化这一逻辑,以减少复杂性并提高代码的清晰度。

+  // 根据条件动态设置类名,减少代码复杂性
-  className={`nut-button-children nut-button-${size}-children nut-button-${type}-children ${!(props.fill || disabled || loading) ? '' : `nut-button-${type}${props.fill ? `-${fill}` : ''}${disabled || loading ? '-disabled' : ''}`} ${icon || loading ? `nut-button-text` : ''}${
+  className={classNames('nut-button-children', `nut-button-${size}-children`, `nut-button-${type}-children`, {
+    [`nut-button-${type}${props.fill ? `-${fill}` : ''}${disabled || loading ? '-disabled' : ''}`]: props.fill || disabled || loading,
+    'nut-button-text': icon || loading,
+    'nut-button-text-right': rightIcon,
+  })}
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
className={`nut-button-children nut-button-${size}-children nut-button-${type}-children ${!(props.fill || disabled || loading) ? '' : `nut-button-${type}${props.fill ? `-${fill}` : ''}${disabled || loading ? '-disabled' : ''}`} ${icon || loading ? `nut-button-text` : ''}${
rightIcon ? ` nut-button-text-right` : ''
}`}
style={harmonyAndRn() ? getContStyle() : ''}
className={classNames('nut-button-children', `nut-button-${size}-children`, `nut-button-${type}-children`, {
[`nut-button-${type}${props.fill ? `-${fill}` : ''}${disabled || loading ? '-disabled' : ''}`]: props.fill || disabled || loading,
'nut-button-text': icon || loading,
'nut-button-text-right': rightIcon,
})}
style={harmonyAndRn() ? getContStyle() : ''}

Comment on lines +96 to +98
if (harmonyAndRn()) {
style.backgroundColor = color
}
Copy link

Choose a reason for hiding this comment

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

调整背景颜色设置以适应不同平台

此代码段针对鸿蒙和 React Native 平台进行了特别的背景颜色设置。建议在此基础上添加注释,说明为什么需要这样做,以提高代码的可读性和可维护性。

+  // 当运行平台为鸿蒙或React Native时,设置特定的背景颜色
  if (harmonyAndRn()) {
    style.backgroundColor = color
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
if (harmonyAndRn()) {
style.backgroundColor = color
}
// 当运行平台为鸿蒙或React Native时,设置特定的背景颜色
if (harmonyAndRn()) {
style.backgroundColor = color

Comment on lines 106 to 121
const getContStyle = useCallback(() => {
const style: CSSProperties = {}
if (props.color) {
if (props.fill === 'outline' || props.fill === 'dashed') {
style.color = color
if (!color?.includes('gradient')) {
style.borderColor = color
}
} else {
style.color = '#fff'
style.background = 'transparent'
style.borderColor = 'transparent'
}
}
return style
}, [color])
Copy link

Choose a reason for hiding this comment

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

优化 getContStyle 函数的实现

这个函数用于根据按钮的不同状态和属性动态生成样式。代码实现功能正确,但可以进一步优化以提高性能,例如通过减少重复代码和利用更简洁的条件表达式。

+  // 使用更简洁的条件判断来设置样式
  if (props.color) {
    if (props.fill === 'outline' || props.fill === 'dashed') {
      style.color = color
      if (!color?.includes('gradient')) {
        style.borderColor = color
      }
    } else {
      style.color = '#fff'
      style.background = 'transparent'
      style.borderColor = 'transparent'
    }
  }
  return style

Committable suggestion was skipped due to low confidence.

@oasis-cloud
Copy link
Collaborator

小程序下Icon未展示:
image

@oasis-cloud
Copy link
Collaborator

RN 下文本颜色不对:
image
Mini 尺寸不对
image

@oasis-cloud
Copy link
Collaborator

oasis-cloud commented Jun 25, 2024

image

@xiaoyatong
Copy link
Collaborator Author

xiaoyatong commented Jun 25, 2024

小程序下Icon未展示: image

小程序下Icon未展示: image

fixed
image

@xiaoyatong
Copy link
Collaborator Author

image

按系统走的,没有干预。

@xiaoyatong
Copy link
Collaborator Author

RN 下文本颜色不对: image

颜色目前只能写在 标签上,无法继承父元素。
暂不支持。

Mini 尺寸不对 image
RN 和 鸿蒙底层组件没有支持 自适应宽度。等底层支持后验证。


const Demo4 = () => {
const marginStyle = { margin: 8 }
const marginStyle = {
marginRight: 8,
Copy link
Collaborator

Choose a reason for hiding this comment

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

都用pxTransform转一下,现在鸿蒙间距有点小

marginLeft: 8,
marginBottom: 8,
}
: {
Copy link
Collaborator

Choose a reason for hiding this comment

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

{
marginRight: 8,
marginTop: 8,
marginLeft: 8,
marginBottom: 8,
}可以考虑提取一下

@@ -22,17 +27,18 @@
-webkit-tap-highlight-color: rgba(0, 0, 0, 0);
color: #1a1a1a;
background: transparent;
Copy link
Collaborator

Choose a reason for hiding this comment

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

harmony背景色透明覆盖不了button默认的灰色,$button-default-background-color是否需要改成白色

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

Successfully merging this pull request may close these issues.

3 participants