|
@@ -227,7 +227,7 @@ export const FileSelectBox = React.forwardRef<FileSelectBoxDerivedElement, FileS |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
const handleReselectMouseDown: React.MouseEventHandler< |
|
|
const handleReselectMouseDown: React.MouseEventHandler< |
|
|
HTMLLabelElement |
|
|
|
|
|
|
|
|
HTMLButtonElement |
|
|
> = React.useCallback(() => { |
|
|
> = React.useCallback(() => { |
|
|
setAboutToSelect(true); |
|
|
setAboutToSelect(true); |
|
|
setTimeout(() => { |
|
|
setTimeout(() => { |
|
@@ -236,6 +236,13 @@ export const FileSelectBox = React.forwardRef<FileSelectBoxDerivedElement, FileS |
|
|
}); |
|
|
}); |
|
|
}, [defaultRef]); |
|
|
}, [defaultRef]); |
|
|
|
|
|
|
|
|
|
|
|
const handleReselectMouseUp: React.MouseEventHandler< |
|
|
|
|
|
HTMLButtonElement |
|
|
|
|
|
> = React.useCallback(() => { |
|
|
|
|
|
const fileInput = defaultRef.current as FileSelectBoxDerivedElement; |
|
|
|
|
|
fileInput.showPicker(); |
|
|
|
|
|
}, [defaultRef]); |
|
|
|
|
|
|
|
|
const handleDeleteMouseDown: React.MouseEventHandler< |
|
|
const handleDeleteMouseDown: React.MouseEventHandler< |
|
|
HTMLButtonElement |
|
|
HTMLButtonElement |
|
|
> = React.useCallback(() => { |
|
|
> = React.useCallback(() => { |
|
@@ -256,7 +263,7 @@ export const FileSelectBox = React.forwardRef<FileSelectBoxDerivedElement, FileS |
|
|
return () => { |
|
|
return () => { |
|
|
window.removeEventListener('mouseup', handleLabelMouseUp, { capture: true }); |
|
|
window.removeEventListener('mouseup', handleLabelMouseUp, { capture: true }); |
|
|
}; |
|
|
}; |
|
|
}, []); |
|
|
|
|
|
|
|
|
}, [defaultRef, aboutToSelect]); |
|
|
|
|
|
|
|
|
return ( |
|
|
return ( |
|
|
<div |
|
|
<div |
|
@@ -266,7 +273,6 @@ export const FileSelectBox = React.forwardRef<FileSelectBoxDerivedElement, FileS |
|
|
block && 'flex w-full', |
|
|
block && 'flex w-full', |
|
|
!block && 'inline-flex w-64 min-h-16 justify-center items-center', |
|
|
!block && 'inline-flex w-64 min-h-16 justify-center items-center', |
|
|
className, |
|
|
className, |
|
|
clientSide && 'resize-y', |
|
|
|
|
|
)} |
|
|
)} |
|
|
onDragEnter={clientSide ? cancelEvent : undefined} |
|
|
onDragEnter={clientSide ? cancelEvent : undefined} |
|
|
onDragOver={clientSide ? cancelEvent : undefined} |
|
|
onDragOver={clientSide ? cancelEvent : undefined} |
|
@@ -280,18 +286,37 @@ export const FileSelectBox = React.forwardRef<FileSelectBoxDerivedElement, FileS |
|
|
...(style ?? {}), |
|
|
...(style ?? {}), |
|
|
}} |
|
|
}} |
|
|
> |
|
|
> |
|
|
{clientSide && ( |
|
|
|
|
|
|
|
|
{label && ( |
|
|
<label |
|
|
<label |
|
|
|
|
|
data-testid="label" |
|
|
|
|
|
id={labelId} |
|
|
|
|
|
htmlFor={id} |
|
|
|
|
|
className={clsx( |
|
|
|
|
|
'absolute z-[1] w-full top-0.5 left-0 pointer-events-none select-none pl-1 text-xxs font-bold peer-disabled:opacity-50 group-focus-within:text-secondary text-primary leading-none bg-negative', |
|
|
|
|
|
{ |
|
|
|
|
|
'sr-only': hiddenLabel, |
|
|
|
|
|
}, |
|
|
|
|
|
)} |
|
|
|
|
|
> |
|
|
|
|
|
<div className="w-full whitespace-nowrap h-[1.1em] overflow-hidden text-ellipsis"> |
|
|
|
|
|
{label} |
|
|
|
|
|
</div> |
|
|
|
|
|
</label> |
|
|
|
|
|
)} |
|
|
|
|
|
{clientSide && ( |
|
|
|
|
|
<button |
|
|
|
|
|
type="button" |
|
|
|
|
|
disabled={disabled} |
|
|
className={clsx( |
|
|
className={clsx( |
|
|
'flex items-center justify-center absolute top-0 left-0 w-full h-full cursor-pointer', |
|
|
|
|
|
|
|
|
'flex items-center justify-center absolute top-0 left-0 w-full h-full cursor-pointer select-none', |
|
|
(fileList?.length ?? 0) > 0 && 'opacity-0', |
|
|
(fileList?.length ?? 0) > 0 && 'opacity-0', |
|
|
)} |
|
|
)} |
|
|
data-testid="clickArea" |
|
|
data-testid="clickArea" |
|
|
htmlFor={id} |
|
|
|
|
|
onMouseDown={handleReselectMouseDown} |
|
|
onMouseDown={handleReselectMouseDown} |
|
|
|
|
|
onMouseUp={handleReselectMouseUp} |
|
|
> |
|
|
> |
|
|
{placeholder} |
|
|
{placeholder} |
|
|
</label> |
|
|
|
|
|
|
|
|
</button> |
|
|
)} |
|
|
)} |
|
|
<input |
|
|
<input |
|
|
{...etcProps} |
|
|
{...etcProps} |
|
@@ -316,22 +341,6 @@ export const FileSelectBox = React.forwardRef<FileSelectBoxDerivedElement, FileS |
|
|
height: clientSide ? undefined : 256, |
|
|
height: clientSide ? undefined : 256, |
|
|
}} |
|
|
}} |
|
|
/> |
|
|
/> |
|
|
{label && ( |
|
|
|
|
|
<div |
|
|
|
|
|
data-testid="label" |
|
|
|
|
|
id={labelId} |
|
|
|
|
|
className={clsx( |
|
|
|
|
|
'absolute z-[1] w-full top-0.5 left-0 pointer-events-none pl-1 text-xxs font-bold peer-disabled:opacity-50 group-focus-within:text-secondary text-primary leading-none bg-negative', |
|
|
|
|
|
{ |
|
|
|
|
|
'sr-only': hiddenLabel, |
|
|
|
|
|
}, |
|
|
|
|
|
)} |
|
|
|
|
|
> |
|
|
|
|
|
<div className="w-full whitespace-nowrap h-[1.1em] overflow-hidden text-ellipsis"> |
|
|
|
|
|
{label} |
|
|
|
|
|
</div> |
|
|
|
|
|
</div> |
|
|
|
|
|
)} |
|
|
|
|
|
{filesCount < 1 |
|
|
{filesCount < 1 |
|
|
&& clientSide |
|
|
&& clientSide |
|
|
&& hint |
|
|
&& hint |
|
@@ -355,13 +364,13 @@ export const FileSelectBox = React.forwardRef<FileSelectBoxDerivedElement, FileS |
|
|
> |
|
|
> |
|
|
{multiple |
|
|
{multiple |
|
|
&& ( |
|
|
&& ( |
|
|
<div className="w-full h-full overflow-auto -mx-4 px-4"> |
|
|
|
|
|
<div className="w-full grid gap-4 grid-cols-3"> |
|
|
|
|
|
{Array.from(fileList ?? []).map((file, i) => ( |
|
|
|
|
|
|
|
|
<div className="w-full h-full overflow-auto"> |
|
|
|
|
|
<div className="w-full grid gap-2 grid-cols-3"> |
|
|
|
|
|
{Array.from(fileList ?? []).map((file) => ( |
|
|
<div |
|
|
<div |
|
|
key={`${file.name}:${i}`} |
|
|
|
|
|
|
|
|
key={file.name} |
|
|
data-testid="selectedFileItem" |
|
|
data-testid="selectedFileItem" |
|
|
className="w-full aspect-square rounded overflow-hidden relative before:absolute before:content-[''] before:bg-current before:top-0 before:left-0 before:w-full before:h-full before:opacity-10" |
|
|
|
|
|
|
|
|
className="w-full p-2 aspect-square rounded overflow-hidden relative before:absolute before:content-[''] before:bg-current before:top-0 before:left-0 before:w-full before:h-full before:opacity-10" |
|
|
> |
|
|
> |
|
|
<FilePreviewComponent |
|
|
<FilePreviewComponent |
|
|
file={file} |
|
|
file={file} |
|
@@ -375,9 +384,9 @@ export const FileSelectBox = React.forwardRef<FileSelectBoxDerivedElement, FileS |
|
|
</div> |
|
|
</div> |
|
|
)} |
|
|
)} |
|
|
{!multiple |
|
|
{!multiple |
|
|
&& Array.from(fileList ?? []).map((file, i) => ( |
|
|
|
|
|
|
|
|
&& Array.from(fileList ?? []).map((file) => ( |
|
|
<div |
|
|
<div |
|
|
key={`${file.name}:${i}`} |
|
|
|
|
|
|
|
|
key={file.name} |
|
|
className="w-full h-full" |
|
|
className="w-full h-full" |
|
|
> |
|
|
> |
|
|
<div |
|
|
<div |
|
@@ -400,10 +409,12 @@ export const FileSelectBox = React.forwardRef<FileSelectBoxDerivedElement, FileS |
|
|
</div> |
|
|
</div> |
|
|
<div className="absolute bottom-0 left-0 w-full text-center h-12 box-border flex"> |
|
|
<div className="absolute bottom-0 left-0 w-full text-center h-12 box-border flex"> |
|
|
<div className="w-0 flex-auto flex flex-col items-center justify-center h-full"> |
|
|
<div className="w-0 flex-auto flex flex-col items-center justify-center h-full"> |
|
|
<label |
|
|
|
|
|
|
|
|
<button |
|
|
|
|
|
type="button" |
|
|
data-testid="reselect" |
|
|
data-testid="reselect" |
|
|
htmlFor={id} |
|
|
|
|
|
|
|
|
disabled={disabled} |
|
|
onMouseDown={handleReselectMouseDown} |
|
|
onMouseDown={handleReselectMouseDown} |
|
|
|
|
|
onMouseUp={handleReselectMouseUp} |
|
|
className={clsx( |
|
|
className={clsx( |
|
|
'flex w-full h-full bg-negative text-primary cursor-pointer items-center justify-center leading-none gap-4 select-none', |
|
|
'flex w-full h-full bg-negative text-primary cursor-pointer items-center justify-center leading-none gap-4 select-none', |
|
|
{ |
|
|
{ |
|
@@ -417,7 +428,7 @@ export const FileSelectBox = React.forwardRef<FileSelectBoxDerivedElement, FileS |
|
|
> |
|
|
> |
|
|
Reselect |
|
|
Reselect |
|
|
</span> |
|
|
</span> |
|
|
</label> |
|
|
|
|
|
|
|
|
</button> |
|
|
</div> |
|
|
</div> |
|
|
<div className="w-0 flex-auto flex flex-col items-center justify-center h-full"> |
|
|
<div className="w-0 flex-auto flex flex-col items-center justify-center h-full"> |
|
|
<button |
|
|
<button |
|
@@ -471,7 +482,7 @@ FileSelectBox.defaultProps = { |
|
|
|
|
|
|
|
|
FileSelectBoxDefaultPreviewComponent.defaultProps = { |
|
|
FileSelectBoxDefaultPreviewComponent.defaultProps = { |
|
|
file: undefined, |
|
|
file: undefined, |
|
|
mini: false, |
|
|
|
|
|
|
|
|
mini: false as const, |
|
|
disabled: FileSelectBox.defaultProps.disabled, |
|
|
disabled: FileSelectBox.defaultProps.disabled, |
|
|
enhanced: FileSelectBox.defaultProps.enhanced, |
|
|
enhanced: FileSelectBox.defaultProps.enhanced, |
|
|
}; |
|
|
}; |