Skip to content

Commit ed501ae

Browse files
committed
copy button and clear all steps button
1 parent 30eaa18 commit ed501ae

File tree

3 files changed

+37
-21
lines changed

3 files changed

+37
-21
lines changed

src/components/OutputBox.tsx

Lines changed: 31 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,35 @@
1-
import React from "react";
1+
import React, { useState } from "react";
22

3-
interface OutputBoxProps {
3+
type OutputBoxProps = {
44
output: string;
5-
}
5+
};
6+
7+
export default function OutputBox({ output }: OutputBoxProps) {
8+
const [copied, setCopied] = useState(false);
69

7-
const OutputBox: React.FC<OutputBoxProps> = ({ output }) => (
8-
<div style={{ marginTop: "16px" }}>
9-
<h2 style={{ fontSize: "18px", fontWeight: "bold" }}>Output</h2>
10-
<textarea
11-
style={{
12-
width: "100%",
13-
padding: "8px",
14-
borderRadius: "4px",
15-
border: "1px solid #ccc",
16-
backgroundColor: "#f7f7f7",
17-
}}
18-
rows={6}
19-
readOnly
20-
value={output}
21-
/>
22-
</div>
23-
);
10+
const handleCopy = async () => {
11+
try {
12+
await navigator.clipboard.writeText(output);
13+
setCopied(true);
14+
setTimeout(() => setCopied(false), 2000);
15+
} catch (err) {
16+
console.error("Failed to copy:", err);
17+
}
18+
};
2419

25-
export default OutputBox;
20+
return (
21+
<div style={{ marginTop: "16px" }}>
22+
<div style={{ display: "flex", justifyContent: "space-between", alignItems: "center" }}>
23+
<h3>Output</h3>
24+
<button onClick={handleCopy} style={{ padding: "4px 8px", fontSize: "0.9rem" }}>
25+
{copied ? "Copied!" : "Copy"}
26+
</button>
27+
</div>
28+
<textarea
29+
readOnly
30+
value={output}
31+
style={{ width: "100%", height: "200px", fontFamily: "monospace", marginTop: "8px" }}
32+
/>
33+
</div>
34+
);
35+
}

src/components/TransformationList.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,20 @@ interface TransformationListProps {
77
addStep: (transformation: keyof typeof transformations) => void;
88
getValidTransformations: (type: DataType) => { key: string; label: string }[];
99
currentType: DataType;
10+
clearSteps: () => void;
1011
}
1112

1213
const TransformationList: React.FC<TransformationListProps> = ({
1314
steps,
1415
removeStep,
1516
addStep,
17+
clearSteps,
1618
getValidTransformations,
1719
currentType,
1820
}) => (
1921
<div style={{ marginTop: "16px" }}>
2022
<h2 style={{ fontSize: "18px", fontWeight: "bold" }}>Transformation Steps</h2>
23+
{steps.length > 0 && <button onClick={clearSteps}>Clear All Steps</button>}
2124
<ul style={{ listStyle: "none", padding: 0 }}>
2225
{steps.map((step, i) => (
2326
<li key={step.id} style={{ display: "flex", alignItems: "center", marginBottom: "8px" }}>

src/pages/ToolBox.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ export function Toolbox() {
6363
.map(([key, t]) => ({ key, label: t.label }));
6464
};
6565

66+
const clearSteps = () => setSteps([]);
67+
6668
let lastType = inputType;
6769
try {
6870
let cur: any = input;
@@ -89,6 +91,7 @@ export function Toolbox() {
8991
steps={steps}
9092
removeStep={removeStep}
9193
addStep={addStep}
94+
clearSteps={clearSteps}
9295
getValidTransformations={getValidTransformations}
9396
currentType={lastType}
9497
/>

0 commit comments

Comments
 (0)