Skip to content

Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.

Add copy to clipboard for credential details (#541)

Leendert de Borst4c9376612e85
diff --git a/browser-extensions/chrome/src/components/FormInputCopyToClipboard.tsx b/browser-extensions/chrome/src/components/FormInputCopyToClipboard.tsx
new file mode 100644
index 000000000..69b01ad9d
--- /dev/null
+++ b/browser-extensions/chrome/src/components/FormInputCopyToClipboard.tsx
@@ -0,0 +1,79 @@
+import React, { useState, useEffect } from 'react';
+import { ClipboardCopyService } from '../utils/ClipboardCopyService';
+
+interface FormInputCopyToClipboardProps {
+ id: string;
+ label: string;
+ value: string;
+ type?: 'text' | 'password';
+}
+
+const clipboardService = new ClipboardCopyService();
+
+export const FormInputCopyToClipboard: React.FC<FormInputCopyToClipboardProps> = ({
+ id,
+ label,
+ value,
+ type = 'text'
+}) => {
+ const [showPassword, setShowPassword] = useState(false);
+ const [copied, setCopied] = useState(false);
+
+ useEffect(() => {
+ const unsubscribe = clipboardService.subscribe((copiedId) => {
+ setCopied(copiedId === id);
+ });
+ return () => unsubscribe();
+ }, [id]);
+
+ const copyToClipboard = async () => {
+ try {
+ await navigator.clipboard.writeText(value);
+ clipboardService.setCopied(id);
+
+ // Reset copied state after 2 seconds
+ setTimeout(() => {
+ if (clipboardService.getCopiedId() === id) {
+ clipboardService.setCopied('');
+ }
+ }, 2000);
+ } catch (err) {
+ console.error('Failed to copy text:', err);
+ }
+ };
+
+ return (
+ <div>
+ <label htmlFor={id} className="block mb-2 text-sm font-medium text-gray-700 dark:text-gray-300">
+ {label}
+ </label>
+ <div className="relative">
+ <input
+ type={type === 'password' && !showPassword ? 'password' : 'text'}
+ id={id}
+ readOnly
+ value={value}
+ onClick={copyToClipboard}
+ className={`w-full px-3 py-2.5 bg-gray-50 border ${
+ copied ? 'border-green-500 border-2' : 'border-gray-300'
+ } text-gray-900 sm:text-sm rounded-lg shadow-sm focus:ring-primary-500 focus:border-primary-500 dark:bg-gray-700 dark:border-gray-600 dark:text-white dark:placeholder-gray-400`}
+ />
+ <div className="absolute right-2 top-1/2 -translate-y-1/2 flex items-center gap-2">
+ {copied && (
+ <span className="text-green-500 dark:text-green-400">
+ Copied!
+ </span>
+ )}
+ {type === 'password' && (
+ <button
+ onClick={() => setShowPassword(!showPassword)}
+ className="px-3 py-1 text-sm text-gray-600 hover:text-gray-900 dark:text-gray-400 dark:hover:text-white transition-colors duration-200"
+ >
+ {showPassword ? 'Hide' : 'Show'}
+ </button>
+ )}
+ </div>
+ </div>
+ </div>
+ );
+};
\ No newline at end of file
diff --git a/browser-extensions/chrome/src/pages/CredentialDetails.tsx b/browser-extensions/chrome/src/pages/CredentialDetails.tsx
index 0180016d3..369c53fad 100644
--- a/browser-extensions/chrome/src/pages/CredentialDetails.tsx
+++ b/browser-extensions/chrome/src/pages/CredentialDetails.tsx
@@ -3,6 +3,7 @@ import { useNavigate, useParams } from 'react-router-dom';
import { useDb } from '../context/DbContext';
import { Credential } from '../types/Credential';
import { Buffer } from 'buffer';
+import { FormInputCopyToClipboard } from '../components/FormInputCopyToClipboard';
const CredentialDetails: React.FC = () => {
const { id } = useParams();
@@ -41,70 +42,41 @@ const CredentialDetails: React.FC = () => {
alt={credential.ServiceName}
className="w-12 h-12 rounded-lg mr-4"
/>
- <h1 className="text-2xl font-bold text-gray-900 dark:text-white">{credential.ServiceName}</h1>
+ <div>
+ <h1 className="text-2xl font-bold text-gray-900 dark:text-white">{credential.ServiceName}</h1>
+ {credential.ServiceUrl && (
+ <a
+ href={credential.ServiceUrl}
+ target="_blank"
+ rel="noopener noreferrer"
+ className="text-primary-600 hover:text-primary-700 dark:text-primary-400 dark:hover:text-primary-300"
+ >
+ {credential.ServiceUrl}
+ </a>
+ )}
+ </div>
</div>
<div className="grid gap-6 md:grid-cols-2">
<div className="space-y-4">
- <div>
- <label className="block mb-2 text-sm font-medium text-gray-700 dark:text-gray-300">Email Address</label>
- <input
- type="email"
- readOnly
- value={credential.Email || ''}
- className="w-full px-3 py-2.5 bg-gray-50 border border-gray-300 text-gray-900 sm:text-sm rounded-lg shadow-sm focus:ring-primary-500 focus:border-primary-500 dark:bg-gray-700 dark:border-gray-600 dark:text-white dark:placeholder-gray-400"
- />
- </div>
-
- <div>
- <label className="block mb-2 text-sm font-medium text-gray-700 dark:text-gray-300">Username</label>
- <input
- type="text"
- readOnly
- value={credential.Username}
- className="w-full px-3 py-2.5 bg-gray-50 border border-gray-300 text-gray-900 sm:text-sm rounded-lg shadow-sm focus:ring-primary-500 focus:border-primary-500 dark:bg-gray-700 dark:border-gray-600 dark:text-white dark:placeholder-gray-400"
- />
- </div>
+ <FormInputCopyToClipboard
+ id="email"
+ label="Email"
+ value={credential.Email || ''}
+ />
- <div>
- <label className="block mb-2 text-sm font-medium text-gray-700 dark:text-gray-300">Password</label>
- <div className="relative">
- <input
- type={showPassword ? 'text' : 'password'}
- readOnly
- value={credential.Password}
- className="w-full px-3 py-2.5 bg-gray-50 border border-gray-300 text-gray-900 sm:text-sm rounded-lg shadow-sm focus:ring-primary-500 focus:border-primary-500 dark:bg-gray-700 dark:border-gray-600 dark:text-white dark:placeholder-gray-400"
- />
- <button
- onClick={() => setShowPassword(!showPassword)}
- className="absolute right-2 top-1/2 -translate-y-1/2 px-3 py-1 text-sm text-gray-600 hover:text-gray-900 dark:text-gray-400 dark:hover:text-white transition-colors duration-200"
- >
- {showPassword ? 'Hide' : 'Show'}
- </button>
- </div>
- </div>
- </div>
-
- <div className="space-y-4">
- <div>
- <label className="block mb-2 text-sm font-medium text-gray-700 dark:text-gray-300">Service URL</label>
- <input
- type="text"
- readOnly
- value={credential.ServiceUrl || ''}
- className="w-full px-3 py-2.5 bg-gray-50 border border-gray-300 text-gray-900 sm:text-sm rounded-lg shadow-sm focus:ring-primary-500 focus:border-primary-500 dark:bg-gray-700 dark:border-gray-600 dark:text-white dark:placeholder-gray-400"
- />
- </div>
+ <FormInputCopyToClipboard
+ id="username"
+ label="Username"
+ value={credential.Username}
+ />
- <div>
- <label className="block mb-2 text-sm font-medium text-gray-700 dark:text-gray-300">Notes</label>
- <textarea
- readOnly
- value={credential.Notes || ''}
- rows={3}
- className="w-full px-3 py-2.5 bg-gray-50 border border-gray-300 text-gray-900 sm:text-sm rounded-lg shadow-sm focus:ring-primary-500 focus:border-primary-500 dark:bg-gray-700 dark:border-gray-600 dark:text-white dark:placeholder-gray-400"
- />
- </div>
+ <FormInputCopyToClipboard
+ id="password"
+ label="Password"
+ value={credential.Password}
+ type="password"
+ />
</div>
</div>
</div>
diff --git a/browser-extensions/chrome/src/utils/ClipboardCopyService.tsx b/browser-extensions/chrome/src/utils/ClipboardCopyService.tsx
new file mode 100644
index 000000000..f6c109cf1
--- /dev/null
+++ b/browser-extensions/chrome/src/utils/ClipboardCopyService.tsx
@@ -0,0 +1,24 @@
+export class ClipboardCopyService {
+ private currentCopiedId: string = '';
+ private onCopyCallbacks: ((id: string) => void)[] = [];
+
+ public setCopied(id: string) {
+ this.currentCopiedId = id;
+ this.notifySubscribers();
+ }
+
+ public getCopiedId(): string {
+ return this.currentCopiedId;
+ }
+
+ public subscribe(callback: (id: string) => void) {
+ this.onCopyCallbacks.push(callback);
+ return () => {
+ this.onCopyCallbacks = this.onCopyCallbacks.filter(cb => cb !== callback);
+ };
+ }
+
+ private notifySubscribers() {
+ this.onCopyCallbacks.forEach(callback => callback(this.currentCopiedId));
+ }
+ }
\ No newline at end of file