-
Notifications
You must be signed in to change notification settings - Fork 62
Expand file tree
/
Copy pathKnowledgeBaseIcon.tsx
More file actions
33 lines (30 loc) · 1.23 KB
/
KnowledgeBaseIcon.tsx
File metadata and controls
33 lines (30 loc) · 1.23 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
import { Avatar, theme } from 'antd';
import { BookOpen } from 'lucide-react';
import { useResolvedAvatarSrc } from '@/hooks/useResolvedAvatarSrc';
import type { AvatarType } from '@/stores/userProfileStore';
import type { KnowledgeBase } from '@/types';
interface KnowledgeBaseIconProps {
kb: KnowledgeBase;
size?: number;
}
export function KnowledgeBaseIcon({ kb, size = 16 }: KnowledgeBaseIconProps) {
const resolvedSrc = useResolvedAvatarSrc((kb.iconType as AvatarType) ?? 'icon', kb.iconValue ?? '');
const { token } = theme.useToken();
if (kb.iconType === 'emoji' && kb.iconValue) {
return (
<span style={{
width: size, height: size, borderRadius: '50%',
backgroundColor: token.colorFillSecondary,
display: 'inline-flex', alignItems: 'center', justifyContent: 'center',
fontSize: size * 0.7, lineHeight: 1, flexShrink: 0,
}}>
{kb.iconValue}
</span>
);
}
if ((kb.iconType === 'url' || kb.iconType === 'file') && kb.iconValue) {
const src = kb.iconType === 'file' ? resolvedSrc : kb.iconValue;
return <Avatar size={size} src={src} style={{ flexShrink: 0 }} />;
}
return <BookOpen size={size} style={{ flexShrink: 0, color: token.colorTextSecondary }} />;
}