mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-03-22 09:29:16 +01:00
Better import flow
This commit is contained in:
31
src-web/components/SelectFile.tsx
Normal file
31
src-web/components/SelectFile.tsx
Normal file
@@ -0,0 +1,31 @@
|
||||
import { open } from '@tauri-apps/plugin-dialog';
|
||||
import { Button } from './core/Button';
|
||||
import { HStack } from './core/Stacks';
|
||||
|
||||
interface Props {
|
||||
onChange: (filePath: string | null) => void;
|
||||
filePath: string | null;
|
||||
}
|
||||
|
||||
export function SelectFile({ onChange, filePath }: Props) {
|
||||
const handleClick = async () => {
|
||||
const selected = await open({
|
||||
title: 'Select File',
|
||||
multiple: false,
|
||||
});
|
||||
if (selected == null) onChange(null);
|
||||
else onChange(selected.path);
|
||||
};
|
||||
return (
|
||||
<HStack space={2}>
|
||||
<Button variant="border" color="secondary" size="sm" onClick={handleClick}>
|
||||
Choose File
|
||||
</Button>
|
||||
<div className="text-sm font-mono truncate rtl pr-3 text-fg">
|
||||
{/* Special character to insert ltr text in rtl element without making things wonky */}
|
||||
‎
|
||||
{filePath ?? 'No file selected'}
|
||||
</div>
|
||||
</HStack>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user