-
Notifications
You must be signed in to change notification settings - Fork 284
feat(taro): demo update #2662
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
feat(taro): demo update #2662
Changes from all commits
e488ef3
bab59d4
783598d
4cae5eb
f134285
978ef72
12d1ef9
ff328a4
5b38d72
9ce77c4
d55d011
d234438
19e3d77
7da214f
3b0458f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -55,4 +55,14 @@ | |
content: ' '; | ||
} | ||
} | ||
&-disabled { | ||
display: flex; | ||
align-items: center; | ||
color: #b5b5b5; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 Codebase verification 建议更新禁用状态的颜色值以提高可访问性 根据代码分析,Cell 组件禁用状态使用的颜色值 #b5b5b5 与默认背景色(--nutui-gray-1: #ffffff)的对比度不足,可能无法满足 WCAG 2.0 的可访问性标准。建议:
🔗 Analysis chain检查颜色对比度以确保可访问性 建议验证禁用状态文本颜色 (#b5b5b5) 与背景色的对比度是否符合 WCAG 可访问性标准。 🏁 Scripts executedThe 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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion 建议使用设计系统变量并优化样式属性 建议进行以下优化:
建议按照以下方式修改: &-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;
}
|
||
} |
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 | ||
|
@@ -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 | ||
} | ||
|
||
|
@@ -22,6 +23,7 @@ const defaultProps = { | |
radius: '6px', | ||
align: 'flex-start', | ||
clickable: false, | ||
disabled: false, | ||
onClick: (event: React.MouseEvent<HTMLDivElement, MouseEvent>) => {}, | ||
} as CellProps | ||
|
||
|
@@ -42,6 +44,7 @@ export const Cell: FunctionComponent< | |
className, | ||
style, | ||
clickable, | ||
disabled, | ||
...rest | ||
} = { | ||
...defaultProps, | ||
|
@@ -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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion 类名条件判断逻辑优化建议 当前实现使用 classNames 处理条件类名是个好的做法。不过建议考虑以下几点:
建议重构如下: +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)}
|
||
onClick={(event) => handleClick(event)} | ||
style={baseStyle} | ||
{...rest} | ||
|
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 = ( | ||
|
@@ -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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion 建议优化图标样式实现 当前样式实现可以更简洁。建议使用更简化的方式来设置图标对齐。 建议如下修改: extra={
<ArrowRight
size={14}
- style={{
- alignItems: 'center',
- }}
+ style={{ display: 'flex' }}
/>
}
|
||
/> | ||
<Cell title="禁用状态" disabled extra={<ArrowRight size={14} />} /> | ||
<Cell title="圆角设置0" radius={0} /> | ||
</> | ||
) | ||
|
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
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
</Cell.Group> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
export default Demo3 |
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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion 建议优化代码组织结构
建议添加以下常量定义: 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> | ||
) | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
建议将 prettier-markdown-table 移回 devDependencies
prettier-markdown-table
是一个用于格式化 Markdown 表格的开发工具,不应该出现在dependencies
中。这可能会:建议应用以下修改: