Skip to content

Commit

Permalink
feat(ui): add share link on framework selection
Browse files Browse the repository at this point in the history
  • Loading branch information
matschik committed Mar 3, 2024
1 parent ba9422a commit 08c89c8
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 21 deletions.
2 changes: 1 addition & 1 deletion src/App.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@
<AppNotificationCenter />
<Header />
<Header {frameworksSelected} />
<div class="flex">
<Aside />
Expand Down
19 changes: 1 addition & 18 deletions src/components/CodeEditor.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import c from "classnames";
import { notifications } from "@veljs/svelte/NotificationCenter.svelte";
import { ClipboardDocumentIcon } from "heroiconsvelte/24/outline";
import copyToClipboard from "../lib/copyToClipboard.js";
export let files = [];
Expand All @@ -11,24 +12,6 @@
$: snippet =
filenameSelected && files.find((s) => s.fileName === filenameSelected);
function copyToClipboard(value) {
const $textarea = document.createElement("textarea");
$textarea.innerHTML = value;
document.body.appendChild($textarea);
$textarea.select();
let success = false;
try {
document.execCommand("copy");
success = true;
} catch (err) {
alert(
"Oops, unable to copy to clipboard. Please check website permissions."
);
}
$textarea.remove();
return success;
}
function copySnippet() {
if (codeSnippetEl) {
copyToClipboard(codeSnippetEl.innerText);
Expand Down
34 changes: 32 additions & 2 deletions src/components/Header.svelte
Original file line number Diff line number Diff line change
@@ -1,15 +1,45 @@
<script>
import { LinkIcon } from "heroiconsvelte/24/outline";
import { notifications } from "@veljs/svelte/NotificationCenter.svelte";
import GithubStarButton from "./GithubStarButton.svelte";
import copyToClipboard from "../lib/copyToClipboard.js";
export let frameworksSelected = [];
function copyShareLink() {
if (frameworksSelected.length === 0) {
return;
}
const shareURL = `${location.origin}?f=${[...frameworksSelected].map((f) => f.id).join(",")}`;
copyToClipboard(shareURL);
notifications.show({
title: `Framework selection link copied with ${[...frameworksSelected].map((f) => f.title).join(", ")}`,
});
}
</script>

<header class="backdrop-blur bg-gray-900/80 border-b border-gray-700">
<div class="px-4 sm:px-6 lg:px-8">
<div class="flex justify-between items-center py-3">
<a class="font-semibold text-lg flex items-center space-x-3" href="/">
<img src="/popper.svg" alt="logo" class="w-5 h-5" />
<img src="/popper.svg" alt="logo" class="size-5" />
<span>Component party</span>
</a>
<GithubStarButton />

<div class="flex items-center space-x-4">
{#if frameworksSelected.length > 0}
<button
type="button"
class="flex items-center space-x-2 rounded bg-gray-800 px-2 py-1 text-sm text-gray-200 shadow-sm hover:bg-white/15"
aria-label="Copy framework selection link"
on:click={copyShareLink}
>
<LinkIcon class="size-[1.3rem] sm:size-[1.1rem]" />
<span class="mt-[2px] hidden sm:inline">Share</span>
</button>
{/if}
<GithubStarButton />
</div>
</div>
</div>
</header>
17 changes: 17 additions & 0 deletions src/lib/copyToClipboard.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
export default function copyToClipboard(value) {
const $textarea = document.createElement("textarea");
$textarea.innerHTML = value;
document.body.appendChild($textarea);
$textarea.select();
let success = false;
try {
document.execCommand("copy");
success = true;
} catch (err) {
alert(
"Oops, unable to copy to clipboard. Please check website permissions."
);
}
$textarea.remove();
return success;
}

0 comments on commit 08c89c8

Please sign in to comment.