Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@
"@babel/runtime": "^7.23.9",
"@nutui/icons-react": "^1.0.5",
"@nutui/icons-react-taro": "^1.0.5",
"@nutui/jdesign-icons-react-taro": "1.0.6-beta.2",
"@nutui/touch-emulator": "^1.0.0",
"@react-spring/web": "~9.6.1",
"@use-gesture/react": "10.2.20",
Expand All @@ -118,7 +119,6 @@
"@commitlint/cli": "^19.0.3",
"@commitlint/config-conventional": "^19.0.3",
"@loadable/component": "^5.16.3",
"prettier-markdown-table": "^1.0.2",
"@mdx-js/mdx": "^3.0.1",
"@mdx-js/react": "^3.0.1",
"@mdx-js/rollup": "^3.0.1",
Expand Down Expand Up @@ -184,6 +184,7 @@
"postcss-rtlcss": "^5.1.0",
"postcss-scss": "^4.0.9",
"prettier": "^3.2.5",
"prettier-markdown-table": "^1.0.2",
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

建议将 prettier-markdown-table 移回 devDependencies

prettier-markdown-table 是一个用于格式化 Markdown 表格的开发工具,不应该出现在 dependencies 中。这可能会:

  1. 增加生产环境的包体积
  2. 造成不必要的依赖安装

建议应用以下修改:

  "dependencies": {
-   "prettier-markdown-table": "^1.0.2",
    // ... other dependencies
  },
  "devDependencies": {
+   "prettier-markdown-table": "^1.0.2",
    // ... other devDependencies
  }

Committable suggestion was skipped due to low confidence.

"react": "^18.2.0",
"react-color": "^2.19.3",
"react-dom": "^18.2.0",
Expand Down
8 changes: 8 additions & 0 deletions packages/nutui-taro-demo/babel.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// babel-preset-taro 更多选项和默认值:
// https://github.com/NervJS/taro/blob/next/packages/babel-preset-taro/README.md
const replaceIcons = require('@dongdesign/replace-icons')

module.exports = {
presets: [
[
Expand All @@ -12,5 +14,11 @@ module.exports = {
],
plugins: [
['@babel/plugin-transform-typescript', { allowDeclareFields: true }],
[
replaceIcons({
sourceLibrary: ['@nutui/icons-react-taro', '@nutui/icons-react'],
targetLibrary: '@nutui/jdesign-icons-react-taro',
}),
],
],
}
2 changes: 1 addition & 1 deletion packages/nutui-taro-demo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
"author": "",
"dependencies": {
"@babel/runtime": "^7.23.9",
"@dongdesign/replace-icons": "1.0.9-beta.0",
"@nutui/touch-emulator": "^1.0.0",
"@pmmmwh/react-refresh-webpack-plugin": "0.5.10",
"@tarojs/components": "3.6.22",
Expand All @@ -68,7 +69,6 @@
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-refresh": "^0.14.0"

},
"devDependencies": {
"@babel/core": "^7.23.9",
Expand Down
10 changes: 10 additions & 0 deletions src/packages/cell/cell.scss
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,14 @@
content: ' ';
}
}
&-disabled {
display: flex;
align-items: center;
color: #b5b5b5;
Copy link

Choose a reason for hiding this comment

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

💡 Codebase verification

建议更新禁用状态的颜色值以提高可访问性

根据代码分析,Cell 组件禁用状态使用的颜色值 #b5b5b5 与默认背景色(--nutui-gray-1: #ffffff)的对比度不足,可能无法满足 WCAG 2.0 的可访问性标准。建议:

  • 将禁用状态文本颜色更改为 var(--nutui-gray-5)(#8c8c8c),这个颜色值能提供更好的对比度
  • 或者使用主题系统中已定义的禁用态文本颜色变量 var(--nutui-color-text-disabled)
🔗 Analysis chain

检查颜色对比度以确保可访问性

建议验证禁用状态文本颜色 (#b5b5b5) 与背景色的对比度是否符合 WCAG 可访问性标准。

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# 搜索其他使用相同颜色值的地方,确保一致性
rg -i "#b5b5b5" --type scss

Length of output: 58


Script:

#!/bin/bash
# 使用更通用的搜索方式查找颜色值
rg -i "#b5b5b5"

# 查找所有样式文件以了解背景色设置
fd -e css -e scss -e less

Length of output: 6018


Script:

#!/bin/bash
# 查找 cell.scss 的完整内容以了解背景色
cat src/packages/cell/cell.scss

# 查找主题文件中的背景色定义
cat src/styles/theme-default.scss

Length of output: 5085

font-size: 14px;
font-family: PingFang SC;
font-weight: 400;
line-height: 20px;
letter-spacing: 0px;
}
Comment on lines +58 to +67
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

建议使用设计系统变量并优化样式属性

建议进行以下优化:

  1. 使用设计系统的变量替代硬编码的颜色值和字体属性
  2. 移除已被父级定义的重复属性
  3. 增加禁用状态的鼠标样式

建议按照以下方式修改:

  &-disabled {
-   display: flex;
-   align-items: center;
    color: #b5b5b5;
-   font-size: 14px;
-   font-family: PingFang SC;
-   font-weight: 400;
-   line-height: 20px;
-   letter-spacing: 0px;
+   color: $cell-disabled-color;
+   font-size: $cell-disabled-font-size;
+   cursor: not-allowed;
  }

Committable suggestion was skipped due to low confidence.

}
12 changes: 9 additions & 3 deletions src/packages/cell/cell.taro.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import React, { FunctionComponent, ReactNode, useContext } from 'react'
import classNames from 'classnames'
import { BasicComponent, ComponentDefaults } from '@/utils/typings'
import React, { FunctionComponent, ReactNode, useContext } from 'react'
import { CellGroup } from '@/packages/cellgroup/cellgroup.taro'
import CellGroupContext from '@/packages/cellgroup/context'
import { BasicComponent, ComponentDefaults } from '@/utils/typings'

export interface CellProps extends BasicComponent {
title: ReactNode
Expand All @@ -11,6 +11,7 @@ export interface CellProps extends BasicComponent {
radius: string | number
align: 'flex-start' | 'center' | 'flex-end'
clickable: boolean
disabled: boolean
onClick: (event: React.MouseEvent<HTMLDivElement, MouseEvent>) => void
}

Expand All @@ -22,6 +23,7 @@ const defaultProps = {
radius: '6px',
align: 'flex-start',
clickable: false,
disabled: false,
onClick: (event: React.MouseEvent<HTMLDivElement, MouseEvent>) => {},
} as CellProps

Expand All @@ -42,6 +44,7 @@ export const Cell: FunctionComponent<
className,
style,
clickable,
disabled,
...rest
} = {
...defaultProps,
Expand All @@ -66,7 +69,10 @@ export const Cell: FunctionComponent<
}
return (
<div
className={`${classNames(classPrefix, className, clickable ? `${classPrefix}-clickable` : '')}`}
className={classNames(classPrefix, className, {
[`${classPrefix}-clickable`]: clickable,
[`${classPrefix}-disabled`]: disabled,
})}
Comment on lines +72 to +75
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

类名条件判断逻辑优化建议

当前实现使用 classNames 处理条件类名是个好的做法。不过建议考虑以下几点:

  1. 建议将类名判断逻辑提取到组件外部,以提高代码复用性
  2. 考虑在禁用状态下阻止 click 事件

建议重构如下:

+const getCellClassNames = (classPrefix: string, { clickable, disabled }: Partial<CellProps>, className?: string) => {
+  return classNames(classPrefix, className, {
+    [`${classPrefix}-clickable`]: clickable,
+    [`${classPrefix}-disabled`]: disabled,
+  })
+}

// 在组件中使用
-      className={classNames(classPrefix, className, {
-        [`${classPrefix}-clickable`]: clickable,
-        [`${classPrefix}-disabled`]: disabled,
-      })}
+      className={getCellClassNames(classPrefix, { clickable, disabled }, className)}
-      onClick={(event) => handleClick(event)}
+      onClick={(event) => !disabled && handleClick(event)}

Committable suggestion was skipped due to low confidence.

onClick={(event) => handleClick(event)}
style={baseStyle}
{...rest}
Expand Down
12 changes: 11 additions & 1 deletion src/packages/cell/demos/taro/demo1.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from 'react'
import { ArrowRight } from '@nutui/icons-react-taro'
import { Cell } from '@nutui/nutui-react-taro'
import React from 'react'

const Demo1 = () => {
const testClick = (
Expand All @@ -17,7 +18,16 @@ const Demo1 = () => {
onClick={(
event: React.MouseEvent<HTMLDivElement, globalThis.MouseEvent>
) => testClick(event)}
extra={
<ArrowRight
size={14}
style={{
alignItems: 'center',
}}
/>
}
Comment on lines +21 to +28
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

建议优化图标样式实现

当前样式实现可以更简洁。建议使用更简化的方式来设置图标对齐。

建议如下修改:

  extra={
    <ArrowRight
      size={14}
-     style={{
-       alignItems: 'center',
-     }}
+     style={{ display: 'flex' }}
    />
  }

Committable suggestion was skipped due to low confidence.

/>
<Cell title="禁用状态" disabled extra={<ArrowRight size={14} />} />
<Cell title="圆角设置0" radius={0} />
</>
)
Expand Down
49 changes: 33 additions & 16 deletions src/packages/cell/demos/taro/demo3.tsx
Original file line number Diff line number Diff line change
@@ -1,23 +1,40 @@
import React from 'react'
import { ArrowRight, User } from '@nutui/icons-react-taro'
import { Cell } from '@nutui/nutui-react-taro'
import { User } from '@nutui/icons-react-taro'
import React from 'react'

const Demo3 = () => {
return (
<Cell
title={
<div style={{ display: 'inline-flex', alignItems: 'center' }}>
<User />
<span style={{ marginLeft: '5px' }}>我是标题</span>
</div>
}
description={
<span>
我是描述<b style={{ color: 'red' }}>1</b>
</span>
}
extra="描述文字"
/>
<Cell.Group>
<Cell
title={
<div style={{ display: 'inline-flex', alignItems: 'center' }}>
<User />
<span style={{ marginLeft: '5px' }}>我是标题</span>
</div>
}
description={
<span>
我是描述<b style={{ color: 'red' }}>1</b>
</span>
}
extra={<ArrowRight size={14} />}
/>

<Cell
title={
<div style={{ display: 'inline-flex', alignItems: 'center' }}>
<User />
<span style={{ marginLeft: '5px' }}>我是标题</span>
</div>
}
description={
<span>
我是描述<b style={{ color: 'red' }}>1</b>
</span>
}
extra={<ArrowRight size={14} />}
/>
Comment on lines +8 to +36
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

建议重构重复的 Cell 组件代码

当前代码中存在两个完全相同的 Cell 组件实现,建议将重复的部分抽取成可复用的配置或组件。这样可以提高代码的可维护性,并减少潜在的错误。

+const cellConfig = {
+  title: (
+    <div style={{ display: 'inline-flex', alignItems: 'center' }}>
+      <User />
+      <span style={{ marginLeft: '5px' }}>我是标题</span>
+    </div>
+  ),
+  description: (
+    <span>
+      我是描述<b style={{ color: 'red' }}>1</b>
+    </span>
+  ),
+  extra: <ArrowRight size={14} />
+}

 <Cell.Group>
-  <Cell
-    title={...}
-    description={...}
-    extra={<ArrowRight size={14} />}
-  />
-  <Cell
-    title={...}
-    description={...}
-    extra={<ArrowRight size={14} />}
-  />
+  {[1, 2].map((key) => (
+    <Cell key={key} {...cellConfig} />
+  ))}
 </Cell.Group>
📝 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
<Cell
title={
<div style={{ display: 'inline-flex', alignItems: 'center' }}>
<User />
<span style={{ marginLeft: '5px' }}>我是标题</span>
</div>
}
description={
<span>
我是描述<b style={{ color: 'red' }}>1</b>
</span>
}
extra={<ArrowRight size={14} />}
/>
<Cell
title={
<div style={{ display: 'inline-flex', alignItems: 'center' }}>
<User />
<span style={{ marginLeft: '5px' }}>我是标题</span>
</div>
}
description={
<span>
我是描述<b style={{ color: 'red' }}>1</b>
</span>
}
extra={<ArrowRight size={14} />}
/>
const cellConfig = {
title: (
<div style={{ display: 'inline-flex', alignItems: 'center' }}>
<User />
<span style={{ marginLeft: '5px' }}>我是标题</span>
</div>
),
description: (
<span>
我是描述<b style={{ color: 'red' }}>1</b>
</span>
),
extra: <ArrowRight size={14} />
}
{[1, 2].map((key) => (
<Cell key={key} {...cellConfig} />
))}

</Cell.Group>
)
}
export default Demo3
34 changes: 31 additions & 3 deletions src/packages/cell/demos/taro/demo4.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,38 @@
import React from 'react'
import { Cell, Switch } from '@nutui/nutui-react-taro'
import { BadgePercent } from '@nutui/icons-react'
import { Cell, Image, Radio, Switch } from '@nutui/nutui-react-taro'
import React, { useState } from 'react'

const App = () => {
const [radioChecked, setRadioChecked] = useState(false)
const handleRadioClick = () => {
setRadioChecked((v) => !v)
}
return (
<Cell.Group>
<Cell title="Switch" extra={<Switch defaultChecked />} />
<Cell align="center" title="Switch" extra={<Switch defaultChecked />} />
<Cell
align="center"
title="BadgePercent"
extra={<BadgePercent color="red" />}
/>
<Cell
align="center"
title="Image"
extra={
<Image
width={20}
height={20}
src="https://img12.360buyimg.com/imagetools/jfs/t1/201375/12/18248/5407/61b0715dE35f02aa9/55eff706b7755414.png"
/>
}
/>
<Cell
align="center"
title="Radio"
onClick={handleRadioClick}
extra={<Radio checked={radioChecked} />}
/>
Comment on lines +12 to +34
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

建议优化代码组织结构

  1. 考虑将重复的 align="center" 属性抽取为通用样式或默认属性
  2. 建议将图片URL移至常量配置中,便于统一管理和修改

建议添加以下常量定义:

const DEMO_IMAGE_URL = 'https://img12.360buyimg.com/imagetools/jfs/t1/201375/12/18248/5407/61b0715dE35f02aa9/55eff706b7755414.png'

<Cell align="center" title="Radio" extra={<Radio checked />} />
</Cell.Group>
)
}
Expand Down
5 changes: 3 additions & 2 deletions src/packages/menu/demos/taro/demo6.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React, { useState } from 'react'
import { Filter } from '@nutui/icons-react'
import { ArrowDown, Star } from '@nutui/icons-react-taro'
import { Menu } from '@nutui/nutui-react-taro'
import { ArrowDown, Star, Filter } from '@nutui/icons-react-taro'
import React, { useState } from 'react'

const Demo6 = () => {
const [options] = useState([
Expand Down
Loading
Loading