mirror of
https://github.com/nicotsx/zerobyte.git
synced 2026-04-17 21:37:06 -04:00
* refactor: scroll to first error when submitting a form * refactor: split file browsers into dedicated components with base * chore: pr feedbacks
40 lines
973 B
TypeScript
40 lines
973 B
TypeScript
import { useState } from "react";
|
|
import { DirectoryBrowser } from "./file-browsers/directory-browser";
|
|
import { Button } from "./ui/button";
|
|
|
|
type Props = {
|
|
value: string;
|
|
onChange: (path: string) => void;
|
|
label?: string;
|
|
};
|
|
|
|
export const PathSelector = ({ value, onChange }: Props) => {
|
|
const [showBrowser, setShowBrowser] = useState(false);
|
|
|
|
if (showBrowser) {
|
|
return (
|
|
<div className="space-y-2">
|
|
<DirectoryBrowser
|
|
selectedPath={value}
|
|
onSelectPath={(path) => {
|
|
onChange(path);
|
|
setShowBrowser(false);
|
|
}}
|
|
/>
|
|
<Button type="button" variant="ghost" size="sm" onClick={() => setShowBrowser(false)}>
|
|
Cancel
|
|
</Button>
|
|
</div>
|
|
);
|
|
}
|
|
|
|
return (
|
|
<div className="flex items-center gap-2">
|
|
<div className="flex-1 text-sm font-mono bg-muted px-3 py-2 rounded-md border">{value}</div>
|
|
<Button type="button" variant="outline" onClick={() => setShowBrowser(true)} size="sm">
|
|
Change
|
|
</Button>
|
|
</div>
|
|
);
|
|
};
|