|
@@ -1,5 +1,5 @@ |
|
|
import * as React from 'react'; |
|
|
import * as React from 'react'; |
|
|
import {augmentImageFile, getMimeTypeDescription} from '@/utils/blob'; |
|
|
|
|
|
|
|
|
import {augmentImageFile, FallbackFile, getMimeTypeDescription} from '@/utils/blob'; |
|
|
import {formatFileSize, formatNumeral} from '@/utils/numeral'; |
|
|
import {formatFileSize, formatNumeral} from '@/utils/numeral'; |
|
|
import clsx from 'clsx'; |
|
|
import clsx from 'clsx'; |
|
|
import {useAugmentedFile, useImageControls} from '@/categories/blob/react'; |
|
|
import {useAugmentedFile, useImageControls} from '@/categories/blob/react'; |
|
@@ -7,7 +7,7 @@ import {useAugmentedFile, useImageControls} from '@/categories/blob/react'; |
|
|
type ImageFilePreviewDerivedComponent = HTMLImageElement; |
|
|
type ImageFilePreviewDerivedComponent = HTMLImageElement; |
|
|
|
|
|
|
|
|
export interface ImageFilePreviewProps extends Omit<React.HTMLProps<ImageFilePreviewDerivedComponent>, 'src' | 'alt'> { |
|
|
export interface ImageFilePreviewProps extends Omit<React.HTMLProps<ImageFilePreviewDerivedComponent>, 'src' | 'alt'> { |
|
|
file?: File; |
|
|
|
|
|
|
|
|
file?: File | FallbackFile; |
|
|
disabled?: boolean; |
|
|
disabled?: boolean; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@@ -19,14 +19,14 @@ export const ImageFilePreview = React.forwardRef<ImageFilePreviewDerivedComponen |
|
|
...etcProps |
|
|
...etcProps |
|
|
}, forwardedRef) => { |
|
|
}, forwardedRef) => { |
|
|
const { augmentedFile, error } = useAugmentedFile({ |
|
|
const { augmentedFile, error } = useAugmentedFile({ |
|
|
file, |
|
|
|
|
|
|
|
|
file: file as File, |
|
|
augmentFunction: augmentImageFile, |
|
|
augmentFunction: augmentImageFile, |
|
|
}); |
|
|
}); |
|
|
const { fullScreen, handleAction, imageRef, filenameRef } = useImageControls({ |
|
|
const { fullScreen, handleAction, imageRef, filenameRef } = useImageControls({ |
|
|
forwardedRef, |
|
|
forwardedRef, |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
if (!augmentedFile) { |
|
|
|
|
|
|
|
|
if (!(augmentedFile)) { |
|
|
return null; |
|
|
return null; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@@ -96,17 +96,22 @@ export const ImageFilePreview = React.forwardRef<ImageFilePreviewDerivedComponen |
|
|
{getMimeTypeDescription(augmentedFile.type, augmentedFile.name)} |
|
|
{getMimeTypeDescription(augmentedFile.type, augmentedFile.name)} |
|
|
</dd> |
|
|
</dd> |
|
|
</div> |
|
|
</div> |
|
|
<div className="w-full"> |
|
|
|
|
|
<dt className="sr-only"> |
|
|
|
|
|
Size |
|
|
|
|
|
</dt> |
|
|
|
|
|
<dd |
|
|
|
|
|
className="m-0 w-full text-ellipsis overflow-hidden" |
|
|
|
|
|
title={`${formatNumeral(augmentedFile.size ?? 0)} bytes`} |
|
|
|
|
|
> |
|
|
|
|
|
{formatFileSize(augmentedFile.size)} |
|
|
|
|
|
</dd> |
|
|
|
|
|
</div> |
|
|
|
|
|
|
|
|
{ |
|
|
|
|
|
typeof augmentedFile?.size === 'number' |
|
|
|
|
|
&& ( |
|
|
|
|
|
<div className="w-full"> |
|
|
|
|
|
<dt className="sr-only"> |
|
|
|
|
|
Size |
|
|
|
|
|
</dt> |
|
|
|
|
|
<dd |
|
|
|
|
|
className="m-0 w-full text-ellipsis overflow-hidden" |
|
|
|
|
|
title={`${formatNumeral(augmentedFile.size ?? 0)} bytes`} |
|
|
|
|
|
> |
|
|
|
|
|
{formatFileSize(augmentedFile.size)} |
|
|
|
|
|
</dd> |
|
|
|
|
|
</div> |
|
|
|
|
|
) |
|
|
|
|
|
} |
|
|
{ |
|
|
{ |
|
|
typeof augmentedFile.metadata?.width === 'number' |
|
|
typeof augmentedFile.metadata?.width === 'number' |
|
|
&& typeof augmentedFile.metadata?.height === 'number' |
|
|
&& typeof augmentedFile.metadata?.height === 'number' |
|
|