-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMultiHashOutput.jsx
More file actions
99 lines (91 loc) · 2.83 KB
/
Copy pathMultiHashOutput.jsx
File metadata and controls
99 lines (91 loc) · 2.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
import React from 'react';
const COPY_FEEDBACK_DURATION = 1500;
export default function MultiHashOutput({ value, error }) {
const [copiedIndex, setCopiedIndex] = React.useState(null);
const handleCopy = (text, index) => {
navigator.clipboard.writeText(text);
setCopiedIndex(index);
setTimeout(() => setCopiedIndex(null), COPY_FEEDBACK_DURATION);
};
if (error) {
return <div style={{ color: '#ef4444', padding: '12px', fontSize: '13px' }}>{error}</div>;
}
let data;
try {
data = typeof value === 'string' ? JSON.parse(value) : value;
} catch {
return (
<div style={{ color: 'var(--muted-foreground)', padding: '12px', fontSize: '13px' }}>
{value}
</div>
);
}
if (!data || typeof data !== 'object') {
return (
<div style={{ color: 'var(--muted-foreground)', padding: '12px', fontSize: '13px' }}>
No hash results
</div>
);
}
const entries = Object.entries(data);
return (
<div style={{ display: 'flex', flexDirection: 'column', gap: '8px' }}>
{entries.map(([key, val], idx) => (
<div
key={key}
style={{
display: 'flex',
flexDirection: 'column',
gap: '4px',
padding: '8px 12px',
borderRadius: '6px',
backgroundColor: 'var(--card)',
border: '1px solid var(--border)',
}}
>
<div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center' }}>
<span
style={{
fontSize: '11px',
fontWeight: 600,
color: 'var(--muted-foreground)',
textTransform: 'uppercase',
letterSpacing: '0.05em',
}}
>
{key}
</span>
<button
onClick={() => handleCopy(val, idx)}
style={{
padding: '4px 8px',
fontSize: '11px',
fontWeight: 600,
textTransform: 'uppercase',
letterSpacing: '0.05em',
backgroundColor: copiedIndex === idx ? 'rgba(34, 197, 94, 0.15)' : 'var(--muted)',
color: copiedIndex === idx ? '#22c55e' : 'var(--muted-foreground)',
border: 'none',
borderRadius: '4px',
cursor: 'pointer',
transition: 'all 0.15s ease',
}}
>
{copiedIndex === idx ? 'Copied!' : 'Copy'}
</button>
</div>
<div
style={{
fontSize: '12px',
fontFamily: "'Menlo', 'Monaco', 'Courier New', monospace",
color: 'var(--foreground)',
wordBreak: 'break-all',
}}
>
{val}
</div>
</div>
))}
</div>
);
}