Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds a Copy HTML button #50

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions components/PreviewModal.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
"use client";

import { use, useEffect, useState } from "react";
import Prism from "prismjs";
import "prismjs/components/prism-cshtml";
Expand All @@ -26,6 +24,11 @@ export function PreviewModal({
return null;
}

const copyToClipboard = async () => {
await navigator.clipboard.writeText(html || '');
alert('HTML copied to clipboard');
};

return (
<div
onClick={(e) => {
Expand Down Expand Up @@ -55,6 +58,12 @@ export function PreviewModal({
>
Code
</TabButton>
<TabButton
active={false}
onClick={copyToClipboard}
>
Copy HTML
</TabButton>
</div>

<button
Expand Down Expand Up @@ -101,4 +110,4 @@ function TabButton({ active, ...buttonProps }: TabButtonProps) {
? "px-4 py-2 text-sm font-medium text-white bg-blue-500 rounded-t-md focus:outline-none focus:ring"
: "px-4 py-2 text-sm font-medium text-blue-500 bg-transparent hover:bg-blue-100 focus:bg-blue-100 rounded-t-md focus:outline-none focus:ring";
return <button className={className} {...buttonProps}></button>;
}
}