'use client';
import React from 'react';
import { FC, useState } from 'react';
import { Inter } from 'next/font/google';
const inter = Inter({ subsets: ["latin"], weight: "500" });
interface Step {
title?: string;
description?: string;
code?: string;
highlightLines?: number[];
}
const steps: Step[] = [
{
title: "Title",
description: "Description",
code: "Your code",
},
{
title: "Highlight Code",
description: "Highlighting specific lines in your code",
code: `import React from 'react';
import Component from './components/ComponentName';
function App() {
return (
);
}
export default App;`,
highlightLines: [1,6],
},
];
const Steps: FC = () => {
const [copiedStep, setCopiedStep] = useState(null);
const copyToClipboard = (code: string | undefined, index: number) => {
if (!code) return;
if (navigator.clipboard && navigator.clipboard.writeText) {
navigator.clipboard.writeText(code).then(
() => setCopiedStep(index),
(err) => console.error("Failed to copy code: ", err)
);
} else {
const textarea = document.createElement("textarea");
textarea.value = code;
textarea.style.position = "fixed";
textarea.style.opacity = "0";
textarea.style.pointerEvents = "none";
document.body.appendChild(textarea);
textarea.select();
try {
const successful = document.execCommand("copy");
if (successful) {
setCopiedStep(index);
} else {
console.error("Oops, unable to copy.");
}
} catch (err) {
console.error("Oops, unable to copy.", err);
} finally {
document.body.removeChild(textarea);
}
}
setTimeout(() => setCopiedStep(null), 2000);
};
const renderCodeWithHighlight = (code: string | undefined, highlightLines?: number[]) => {
if (!code) return null;
return code.split('\n').map((line, index) => (
{line}
));
};
return (
{/* Vertical Line */}
{steps.map((step, index) => (
{index + 1}
{step.title &&
{step.title}
}
{step.description &&
{step.description}
}
{step.code && (
{renderCodeWithHighlight(step.code, step.highlightLines)}
{/* Copy Button */}
)}
))}
);
};
export default Steps;