forked from rajun/ar-test
feat: add model file picker
This commit is contained in:
parent
ab27087a79
commit
49ed4e2b2c
35
app/components/assets/form/file-picker.tsx
Normal file
35
app/components/assets/form/file-picker.tsx
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
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>
|
||||||
|
);
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user