nav-next/components/tools/hash-random/ResultDisplay.tsx
2024-12-27 19:27:49 +08:00

71 lines
2.5 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { useState } from "react";
interface ResultDisplayProps {
results: [string, string, number][];
saltHash: string;
}
export default function ResultDisplay({
results,
saltHash,
}: ResultDisplayProps) {
const [copied, setCopied] = useState(false);
const handleCopy = () => {
const resultText = results.map(([name]) => name).join("\n");
navigator.clipboard.writeText(resultText);
setCopied(true);
setTimeout(() => setCopied(false), 2000);
};
return (
<div className="bg-white dark:bg-gray-800 rounded-lg shadow-md p-6 transition-colors duration-200">
<h2 className="text-2xl font-bold mb-4 text-indigo-800 dark:text-indigo-200">
</h2>
<p className="mb-4 text-gray-600 dark:text-gray-300">
</p>
<div className="space-y-4">
<div>
<label
htmlFor="results"
className="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1"
>
</label>
<div className="flex">
<textarea
id="results"
value={results.map(([name]) => name).join("\n")}
readOnly
className="flex-grow h-32 border-gray-300 rounded-l-md shadow-sm bg-gray-50 dark:bg-gray-700 dark:border-gray-600 dark:text-white"
/>
<button
onClick={handleCopy}
className="bg-green-500 text-white px-4 py-2 rounded-r-md hover:bg-green-600 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-green-500 transition-colors"
>
{copied ? "已复制" : "复制"}
</button>
</div>
</div>
<div>
<label
htmlFor="saltHash"
className="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1"
>
</label>
<input
id="saltHash"
type="text"
value={saltHash}
readOnly
className="w-full border-gray-300 rounded-md shadow-sm bg-gray-50 dark:bg-gray-700 dark:border-gray-600 dark:text-white"
/>
</div>
</div>
</div>
);
}