Files
spacedrive/interface/app/$libraryId/Explorer/FilePath/LayeredFileIcon.tsx
nikec afeeb32ea9 [ENG-1353] explorer dnd (#1737)
* locations dnd

* fix icon

* reduce navigate timeout

* fix types

* another

* fix drag overlay count

* Update pnpm-lock.yaml

* merge

* ephemeral support and other improvements

* merge

* Tag dnd

* merge

* type

* merge

* remove offset

* update dnd logic to not depend on drag source

* handle allowed types if parent isn't available

* saved searches dnd navigation

* well

* rendering

* Update pnpm-lock.yaml

* types

* remove width

* Temporary solution

* merge

* @dnd-kit/utilities

* Update pnpm-lock.yaml

* explorer path dnd

* remove unused drag hook

* fix dnd on LayeredFileIcon

---------

Co-authored-by: Brendan Allan <brendonovich@outlook.com>
2023-12-13 11:59:27 +00:00

48 lines
1.3 KiB
TypeScript

import { getLayeredIcon } from '@sd/assets/util';
import clsx from 'clsx';
import { forwardRef, type ImgHTMLAttributes } from 'react';
import { type ObjectKindKey } from '@sd/client';
interface LayeredFileIconProps extends ImgHTMLAttributes<HTMLImageElement> {
kind: ObjectKindKey;
extension: string | null;
}
const SUPPORTED_ICONS = ['Document', 'Code', 'Text', 'Config'];
const positionConfig: Record<string, string> = {
Text: 'flex h-full w-full items-center justify-center',
Code: 'flex h-full w-full items-center justify-center',
Config: 'flex h-full w-full items-center justify-center'
};
const LayeredFileIcon = forwardRef<HTMLImageElement, LayeredFileIconProps>(
({ kind, extension, ...props }, ref) => {
const iconImg = <img ref={ref} {...props} />;
if (SUPPORTED_ICONS.includes(kind) === false) {
return iconImg;
}
const IconComponent = extension ? getLayeredIcon(kind, extension) : null;
const positionClass =
positionConfig[kind] || 'flex h-full w-full items-end justify-end pb-4 pr-2';
return IconComponent == null ? (
iconImg
) : (
<div className="relative">
{iconImg}
<div
className={clsx('pointer-events-none absolute bottom-0 right-0', positionClass)}
>
<IconComponent viewBox="0 0 16 16" height="40%" width="40%" />
</div>
</div>
);
}
);
export default LayeredFileIcon;