-
Notifications
You must be signed in to change notification settings - Fork 62
Expand file tree
/
Copy pathDynamicLobeIcon.tsx
More file actions
34 lines (30 loc) · 1.04 KB
/
DynamicLobeIcon.tsx
File metadata and controls
34 lines (30 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import { memo } from 'react';
// Static barrel import — all icon components are already mostly bundled
// via providerConfig/modelConfig; marginal addition is small.
import * as LobeIcons from '@lobehub/icons/es/icons.js';
const iconsMap = LobeIcons as unknown as Record<string, any>;
interface DynamicLobeIconProps {
iconId: string;
size?: number;
type?: 'color' | 'avatar' | 'mono';
}
/**
* Renders a @lobehub/icons icon by its toc `id` (e.g., "Ai302", "OpenAI")
* via direct component lookup, bypassing the incomplete keyword matching
* in ProviderIcon/ModelIcon.
*/
export const DynamicLobeIcon = memo(function DynamicLobeIcon({
iconId,
size = 24,
type = 'avatar',
}: DynamicLobeIconProps) {
const IconModule = iconsMap[iconId];
if (!IconModule) return <div style={{ width: size, height: size }} />;
if (type === 'color' && IconModule.Color) {
return <IconModule.Color size={size} />;
}
if (type === 'avatar' && IconModule.Avatar) {
return <IconModule.Avatar size={size} />;
}
return <IconModule size={size} />;
});