Skip to content

Commit 1c11cd9

Browse files
483 - password-show-and-hide-functionality-in-variableEditor-for-secret (#486)
1 parent 3f1685f commit 1c11cd9

File tree

2 files changed

+42
-4
lines changed

2 files changed

+42
-4
lines changed

src/renderer/components/shared/settings/VariableTab/VariableEditor.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import { memo, useEffect } from 'react';
1414
import { produce } from 'immer';
1515
import { Checkbox } from '@/components/ui/checkbox';
1616
import { Trash2 } from 'lucide-react';
17+
import { SecretInput } from '@/components/ui/secret-input';
1718

1819
export interface VariableEditorProps {
1920
variables: VariableObjectWithKey[];
@@ -52,7 +53,7 @@ export const VariableEditor = memo<VariableEditorProps>(
5253
if (invalidVariableKeys.has('')) return;
5354
onVariablesChange(
5455
produce(variables, (variables) => {
55-
variables.push({ key: '', value: '' });
56+
variables.push({ key: '', value: '', description: '', secret: false });
5657
})
5758
);
5859
};
@@ -109,10 +110,9 @@ export const VariableEditor = memo<VariableEditorProps>(
109110
/>
110111
</TableCell>
111112
<TableCell className="break-all">
112-
<input
113-
type="text"
113+
<SecretInput
114+
secret={variable.secret}
114115
value={variable.value}
115-
className="w-full bg-transparent outline-none"
116116
placeholder="Enter variable value"
117117
onChange={(e) => update(index, { value: e.target.value })}
118118
/>
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import { useState } from 'react';
2+
import { cn } from '@/lib/utils';
3+
4+
interface SecretInputProps extends React.InputHTMLAttributes<HTMLInputElement> {
5+
secret?: boolean;
6+
}
7+
8+
export function SecretInput({ secret = false, className, ...props }: SecretInputProps) {
9+
const [show, setShow] = useState(false);
10+
11+
if (!secret) {
12+
return (
13+
<input
14+
type="text"
15+
className={cn('w-full bg-transparent outline-none', className)}
16+
{...props}
17+
/>
18+
);
19+
}
20+
21+
return (
22+
<div className="relative w-full">
23+
<input
24+
type={show ? 'text' : 'password'}
25+
className={cn('w-full bg-transparent pr-12 outline-none', className)}
26+
{...props}
27+
/>
28+
<button
29+
type="button"
30+
className="absolute inset-y-0 right-0 flex items-center text-sm text-text-secondary hover:text-text-primary"
31+
onClick={() => setShow((prev) => !prev)}
32+
tabIndex={-1}
33+
>
34+
{show ? 'Hide' : 'Show'}
35+
</button>
36+
</div>
37+
);
38+
}

0 commit comments

Comments
 (0)