项目文件夹

文件
wehub-resource-sync 2114b14ee0
Sync main into demo / sync (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 12:35:26 +08:00

53 行
1.5 KiB
TypeScript

此文件含有模棱两可的 Unicode 字符
此文件含有可能会与其他字符混淆的 Unicode 字符。 如果您是想特意这样的,可以安全地忽略该警告。 使用 Escape 按钮显示他们。
import React from 'react';
import type { AppIconSource, IconProps } from '../types/res';
/**
* 通用图标渲染组件 — 对应 Android ImageView 使用 Drawable 资源
*
* 统一渲染三种图标来源,切换实现只需改 res/drawable/icons.tsx,业务组件无需修改:
* 1. SVG 组件(lucide-react 图标 / 自定义 SVG
* 2. 图片 URLPNG / WebP,通过 Vite import 获得)
* 3. Tailwind React 组件(纯 CSS/HTML 实现的图标形状)
*
* 用法:
* import { TabHome, IcBack } from '../res/drawable/icons';
* import { DrawableIcon } from '@/os/components/DrawableIcon';
*
* <DrawableIcon icon={TabHome} size={24} color="currentColor" />
* <DrawableIcon icon={tabPhotoPng} size={32} className="opacity-70" />
*/
export const DrawableIcon: React.FC<{ icon: AppIconSource } & IconProps> = ({
icon,
size = 24,
color = 'currentColor',
strokeWidth,
className = '',
}) => {
if (typeof icon === 'string') {
// PNG / WebP / 图片 URL
return (
<img
src={icon}
width={typeof size === 'number' ? size : undefined}
height={typeof size === 'number' ? size : undefined}
className={className}
alt=""
aria-hidden="true"
draggable={false}
style={typeof size === 'string' ? { width: size, height: size } : undefined}
/>
);
}
// SVG 组件 / lucide-react / Tailwind React 组件
const Comp = icon;
return (
<Comp
size={size}
color={color}
strokeWidth={strokeWidth}
className={className}
/>
);
};