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

SecretInput.tsx

38 lines976 Bytes

1import { DraftInput, type DraftInputProps } from "../ui/draft-input";
2import { Input, type InputProps } from "../ui/input";
3​
4type SecretInputProps = Omit<InputProps, "type" | "autoComplete" | "defaultValue" | "value"> & {
5 /** Pass only the replacement draft as `value`. */
6 readonly configured?: boolean;
7 readonly value: string;
8 readonly onCommit?: DraftInputProps["onCommit"];
9};
10​
11export function SecretInput({
12 configured = false,
13 placeholder,
14 onCommit,
15 ...props
16}: SecretInputProps) {
17 const shared = {
18 ...props,
19 type: "password" as const,
20 autoComplete: "off",
21 spellCheck: false,
22 placeholder: configured
23 ? "Stored secret, enter a new value to replace"
24 : (placeholder ?? "Not set"),
25 };
26 if (onCommit) {
27 return (
28 <DraftInput
29 {...shared}
30 onCommit={(next) => {
31 if (configured && next === "") return;
32 onCommit(next);
33 }}
34 />
35 );
36 }
37 return <Input {...shared} />;