ar-test/app/components/assets/form/file-picker.tsx

36 lines
1.4 KiB
TypeScript

import { UploadCloud } from 'lucide-react';
import { DropZone } from '~/components/ui/drop-zone';
import { Text } from '~/components/ui/text';
import { SelectedFile } from '~/components/assets/form/selected-file';
import { formatFileSize } from '~/lib/format';
interface FilePickerProps {
id?: string;
accept: string;
file: File | null;
existing: string;
invalid?: boolean;
onFileChange: (file: File | null) => void;
onClearExisting: () => void;
}
export function FilePicker({ id, accept, file, existing, invalid, onFileChange, onClearExisting }: FilePickerProps) {
return (
<DropZone id={id} accept={accept} layout='row' filled={!!file || !!existing} invalid={invalid} onFile={onFileChange}>
{file ? (
<SelectedFile name={file.name} meta={formatFileSize(file.size)} onRemove={() => onFileChange(null)} />
) : existing ? (
<SelectedFile name={existing} meta='Current file' onRemove={onClearExisting} />
) : (
<div className='flex items-center gap-3 py-0.5'>
<UploadCloud size={17} className='text-text-secondary' />
<Text>
<Text as='span' variant='label' tone='primary'>Click to upload</Text> or drag a file here{' '}
<Text as='span' variant='meta'>({accept})</Text>
</Text>
</div>
)}
</DropZone>
);
}