feat(04-02): add OutputBlock reusable component
- Pre-formatted code block with label, copy button, and optional download button - Copy button calls navigator.clipboard.writeText with 2s "Copied!" feedback - Download button calls downloadFile(content, filename) when filename prop provided - disabled prop gates both copy and download actions (SECU-01 security gate)
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
// src/components/wizard/OutputBlock.tsx
|
||||
// Reusable output block: pre-formatted content + copy button + optional download button.
|
||||
// disabled prop gates both actions (SECU-01 security acknowledgement gate).
|
||||
import { useState } from 'react';
|
||||
import { downloadFile } from '../../utils/downloadFile';
|
||||
|
||||
export interface OutputBlockProps {
|
||||
label: string;
|
||||
content: string;
|
||||
filename?: string;
|
||||
disabled?: boolean;
|
||||
}
|
||||
|
||||
export function OutputBlock({ label, content, filename, disabled = false }: OutputBlockProps) {
|
||||
const [copied, setCopied] = useState(false);
|
||||
|
||||
async function handleCopy() {
|
||||
await navigator.clipboard.writeText(content);
|
||||
setCopied(true);
|
||||
setTimeout(() => setCopied(false), 2000);
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="mb-6">
|
||||
<div className="flex items-center justify-between mb-1">
|
||||
<span className="text-sm font-medium text-gray-700">{label}</span>
|
||||
<div className="flex gap-2">
|
||||
<button
|
||||
type="button"
|
||||
disabled={disabled}
|
||||
onClick={handleCopy}
|
||||
className="text-xs px-2 py-1 rounded border border-gray-300 disabled:opacity-40"
|
||||
>
|
||||
{copied ? 'Copied!' : 'Copy'}
|
||||
</button>
|
||||
{filename && (
|
||||
<button
|
||||
type="button"
|
||||
disabled={disabled}
|
||||
onClick={() => downloadFile(content, filename)}
|
||||
className="text-xs px-2 py-1 rounded border border-gray-300 disabled:opacity-40"
|
||||
>
|
||||
Download
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
<pre className="bg-gray-900 text-gray-100 rounded p-4 text-xs overflow-x-auto whitespace-pre-wrap">
|
||||
<code>{content}</code>
|
||||
</pre>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user