-
Notifications
You must be signed in to change notification settings - Fork 263
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(Icon): icon harmony adaptation #2788
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
import React, { useState } from 'react' | ||
import { IconFontConfig, IconFont } from '@nutui/icons-react-taro' | ||
import * as iconfonts from '@nutui/icons-react-taro' | ||
import { Cell, Toast } from '@nutui/nutui-react-taro' | ||
import { View } from '@tarojs/components' | ||
import { camelCase } from '@/utils/camel-case' | ||
|
||
const Demo7 = () => { | ||
|
@@ -27,11 +28,11 @@ const Demo7 = () => { | |
return ( | ||
<> | ||
<Toast visible={state.visible} content={state.content} type="text" /> | ||
{(IconFontConfig as any).style.map((item: any) => { | ||
{(iconfonts.IconFontConfig as any).style.map((item: any) => { | ||
return ( | ||
Comment on lines
+31
to
32
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 🛠️ Refactor suggestion Based on the analysis of the codebase, I can now provide the final response: 建议对 IconFontConfig 的使用添加类型定义和错误处理
建议添加以下改进: interface IconStyle {
name: string;
icons: Array<{
name: string;
'animation-name'?: string;
'animation-time'?: string;
}>;
}
interface IconFontConfigType {
style: IconStyle[];
data: IconStyle[];
}
// 使用时添加类型检查和错误处理
{
(() => {
try {
const config = iconfonts.IconFontConfig as IconFontConfigType;
if (!Array.isArray(config?.style)) {
return null;
}
return config.style.map((item) => (
// ... 原有渲染逻辑
));
} catch (err) {
console.error('图标配置解析错误:', err);
return null;
}
})()
} 🔗 Analysis chain建议添加错误处理和类型检查 当前代码缺少对无效图标名称的错误处理和类型检查机制。 建议添加以下改进:
interface IconConfig {
name: string;
icons: Array<{
name: string;
'animation-name': string;
'animation-time': string;
}>;
}
// 添加类型检查
const iconConfig = (iconfonts.IconFontConfig as any).style as IconConfig[];
if (!Array.isArray(iconConfig)) {
console.error('Invalid icon configuration');
return null;
} Let me gather more information about the IconFontConfig structure and its usage. Let me check the IconFontConfig usage and error handling patterns in the icon package. 🏁 Scripts executedThe following scripts were executed for the analysis: Script: #!/bin/bash
# 检查是否存在类型定义文件
fd -e d.ts -e tsx "icon.*types?" src/packages/icon
# 检查是否有其他文件使用了类似的错误处理模式
rg "IconFontConfig.*style.*map" -A 5
Length of output: 975 Script: #!/bin/bash
# Check the IconFontConfig definition and structure
rg -g "!*.d.ts" "IconFontConfig.*=|type.*IconFontConfig|interface.*IconFontConfig" -B 2 -A 5
# Check if there are any error handling patterns in icon related files
fd "icon" -e tsx -e ts | xargs rg "try.*catch|Error|throw|console\.(error|warn)"
# Look for any type definitions in icon package
ast-grep --pattern 'interface $_ {
$$$
}'
Length of output: 92277 Script: #!/bin/bash
# Check IconFontConfig definition and usage
rg "IconFontConfig" -B 3 -A 3 src/packages/icon/
# Check if there are any error handling patterns in icon demos
rg "try|catch|error|throw" src/packages/icon/demos/
Length of output: 2811 |
||
<Cell.Group key={item.name} title={item.name}> | ||
<Cell> | ||
<ul | ||
<View | ||
style={{ | ||
display: 'flex', | ||
flexWrap: 'wrap', | ||
|
@@ -41,7 +42,7 @@ const Demo7 = () => { | |
> | ||
{item.icons.map((icon: any) => { | ||
return ( | ||
<li | ||
<View | ||
key={icon.name} | ||
onClick={() => { | ||
copyTag(generateAMCopyText(icon)) | ||
|
@@ -61,14 +62,16 @@ const Demo7 = () => { | |
justifyContent: 'center', | ||
}} | ||
> | ||
<IconFont | ||
name={icon.name} | ||
className={`nut-icon-${icon['animation-name']} nut-icon-${icon['animation-time']}`} | ||
/> | ||
</li> | ||
{React.createElement( | ||
iconfonts[camelCase(icon.name, { pascalCase: true })], | ||
{ | ||
className: `nut-icon-${icon['animation-name']} nut-icon-${icon['animation-time']}`, | ||
} | ||
)} | ||
</View> | ||
) | ||
})} | ||
</ul> | ||
</View> | ||
</Cell> | ||
</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.
💡 Codebase verification
需要完成 H5 版本的图标组件迁移
在代码库中发现以下问题:
请将这些文件中的 IconFont 组件替换为新的 Dongdong 组件,以保持组件使用的一致性。
🔗 Analysis chain
验证图标组件迁移的完整性
需要确保所有使用 "dongdong" 图标的地方都已经迁移到新的 Dongdong 组件。
Let me check the content of those files to better understand the migration status.
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
Length of output: 730
Script:
Length of output: 2642