2025-05-02 21:27:21 +08:00
|
|
|
import { FileIconMap } from '@/constants/file';
|
2025-04-30 13:09:42 +08:00
|
|
|
import { cn } from '@/lib/utils';
|
2025-05-02 21:27:21 +08:00
|
|
|
import { getExtension } from '@/utils/document-util';
|
2025-11-19 16:16:57 +08:00
|
|
|
import { CSSProperties } from 'react';
|
2026-04-30 12:36:03 +08:00
|
|
|
import SvgIcon from './svg-icon';
|
2025-04-30 13:09:42 +08:00
|
|
|
|
|
|
|
|
type IconFontType = {
|
|
|
|
|
name: string;
|
|
|
|
|
className?: string;
|
2025-11-19 16:16:57 +08:00
|
|
|
style?: CSSProperties;
|
2025-04-30 13:09:42 +08:00
|
|
|
};
|
|
|
|
|
|
2025-11-19 16:16:57 +08:00
|
|
|
export const IconFont = ({ name, className, style }: IconFontType) => (
|
|
|
|
|
<svg className={cn('size-4', className)} style={style}>
|
2025-04-30 13:09:42 +08:00
|
|
|
<use xlinkHref={`#icon-${name}`} />
|
|
|
|
|
</svg>
|
|
|
|
|
);
|
2025-05-02 21:27:21 +08:00
|
|
|
|
2025-10-09 12:36:19 +08:00
|
|
|
export function IconFontFill({
|
|
|
|
|
name,
|
|
|
|
|
className,
|
|
|
|
|
isFill = true,
|
|
|
|
|
}: IconFontType & { isFill?: boolean }) {
|
|
|
|
|
return (
|
2026-03-12 13:33:36 +08:00
|
|
|
<svg
|
|
|
|
|
className={cn('size-4', className)}
|
|
|
|
|
style={{ fill: isFill ? 'currentColor' : '' }}
|
|
|
|
|
>
|
|
|
|
|
<use xlinkHref={`#icon-${name}`} />
|
|
|
|
|
</svg>
|
2025-10-09 12:36:19 +08:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2025-05-02 21:27:21 +08:00
|
|
|
export function FileIcon({
|
|
|
|
|
name,
|
|
|
|
|
className,
|
|
|
|
|
type,
|
|
|
|
|
}: IconFontType & { type?: string }) {
|
|
|
|
|
const isFolder = type === 'folder';
|
2026-04-30 12:36:03 +08:00
|
|
|
const isSkills = type === 'skills';
|
|
|
|
|
if (isSkills) {
|
|
|
|
|
return (
|
|
|
|
|
<span className={cn('size-4', className)}>
|
|
|
|
|
<SvgIcon name="home-icon/skills" width={16} height={16} />
|
|
|
|
|
</span>
|
|
|
|
|
);
|
|
|
|
|
}
|
2025-05-02 21:27:21 +08:00
|
|
|
return (
|
|
|
|
|
<span className={cn('size-4', className)}>
|
|
|
|
|
<IconFont
|
2025-05-08 15:25:26 +08:00
|
|
|
name={isFolder ? 'file-sub' : FileIconMap[getExtension(name)]}
|
2025-05-02 21:27:21 +08:00
|
|
|
></IconFont>
|
|
|
|
|
</span>
|
|
|
|
|
);
|
|
|
|
|
}
|