Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

FilePasswordPrompt.tsx

46 lines1.4 KB

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 ? gt`Incorrect password. Try again.` : gt`This file requires a password.`}
27 </p>
28 <div className="flex w-full max-w-xs gap-2">
29 <div className="min-w-0 flex-1">
30 <Input
31 type="password"
32 name="password"
33 aria-label={gt`File password`}
34 aria-describedby={status}
35 autoComplete="off"
36 autoFocus={props.incorrect}
37 required
38 />
39 </div>
40 <Button type="submit">
41 <T>Unlock</T>
42 </Button>
43 </div>
44 </form>
45 );