Open History to see the last commit
1import { T, useGT } from "gt-react";
2import { useId } from "react";
3
4import { Button } from "~/components/ui/button";
5import { Input } from "~/components/ui/input";
6
7export function FilePasswordPrompt(props: {
8 readonly incorrect: boolean;
9 readonly onSubmit: (password: string) => void;
10}) {
11 const gt = useGT();
12 const status = useId();
13 return (
14 <form
15 className="flex min-h-0 flex-1 flex-col items-center justify-center gap-3 p-4"
16 onSubmit={(event) => {
17 event.preventDefault();
18 event.stopPropagation();
19 const form = event.currentTarget;
20 const password = new FormData(form).get("password");
21 form.reset();
22 if (typeof password === "string" && password.length > 0) props.onSubmit(password);
23 }}
24 >
25 <p id={status} role={props.incorrect ? "alert" : "status"} className="text-sm">
26 {props.incorrect
27 ? gt("Incorrect password. Try again.")
28 : gt("This file requires a password.")}
29 </p>
30 <div className="flex w-full max-w-xs gap-2">
31 <div className="min-w-0 flex-1">
32 <Input
33 type="password"
34 name="password"
35 aria-label={gt("File password")}
36 aria-describedby={status}
37 autoComplete="off"
38 autoFocus={props.incorrect}
39 required
40 />
41 </div>
42 <Button type="submit">
43 <T>Unlock</T>
44 </Button>
45 </div>
46 </form>
47 );
48}