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-04-30 13:09:42 +08:00
|
|
|
|
|
|
|
|
type IconFontType = {
|
|
|
|
|
name: string;
|
|
|
|
|
className?: string;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const IconFont = ({ name, className }: IconFontType) => (
|
|
|
|
|
<svg className={cn('fill-current size-4', className)}>
|
|
|
|
|
<use xlinkHref={`#icon-${name}`} />
|
|
|
|
|
</svg>
|
|
|
|
|
);
|
2025-05-02 21:27:21 +08:00
|
|
|
|
|
|
|
|
export function FileIcon({
|
|
|
|
|
name,
|
|
|
|
|
className,
|
|
|
|
|
type,
|
|
|
|
|
}: IconFontType & { type?: string }) {
|
|
|
|
|
const isFolder = type === 'folder';
|
|
|
|
|
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>
|
|
|
|
|
);
|
|
|
|
|
}
|