跳到主要内容

Icon 图标

用于渲染以 prop 形式传入的 Lucide 图标组件的包装器。

VEF 特有组件,不属于 Ant Design。

基础用法

import { Icon } from '@vef-framework-react/components';
import { Settings } from 'lucide-react';

export default function Demo() {
return <Icon component={Settings} size={20} color="#666" />;
}

动态图标组件

import { Icon } from '@vef-framework-react/components';
import { User, Settings, Bell } from 'lucide-react';
import { LucideIcon } from 'lucide-react';

interface NavItem {
label: string;
IconComponent: LucideIcon;
}

const navItems: NavItem[] = [
{ label: '个人资料', IconComponent: User },
{ label: '系统设置', IconComponent: Settings },
{ label: '消息通知', IconComponent: Bell },
];

export default function Nav() {
return (
<ul>
{navItems.map((item) => (
<li key={item.label}>
<Icon component={item.IconComponent} size={16} />
<span>{item.label}</span>
</li>
))}
</ul>
);
}

API

Icon 继承所有 Lucide LucideProps(除 sizecolorchildren),另有:

属性类型默认值说明
componentComponentType<LucideProps>必填要渲染的 Lucide 图标组件
sizenumber | string24图标尺寸
colorstring图标颜色
strokeWidthnumber2描边宽度
classNamestringCSS 类名
styleCSSProperties内联样式

最佳实践

  • 图标组件以 prop 形式传入时使用 Icon;静态图标直接从 lucide-react 导入使用。
  • 图标名称以字符串存储时,使用 DynamicIcon