Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

Add copy link button

ameer2468995c6d148d7a
diff --git a/apps/desktop/src/routes/editor/ShareButton.tsx b/apps/desktop/src/routes/editor/ShareButton.tsx
index c8d782d6e..82714f18c 100644
--- a/apps/desktop/src/routes/editor/ShareButton.tsx
+++ b/apps/desktop/src/routes/editor/ShareButton.tsx
@@ -1,8 +1,8 @@
import { Button } from "@cap/ui-solid";
-import { Tooltip } from "@kobalte/core";
import { createMutation } from "@tanstack/solid-query";
-import { createResource, Show } from "solid-js";
+import { createResource, createSignal, Show } from "solid-js";
import { createStore, produce } from "solid-js/store";
+import Tooltip from "~/components/Tooltip";
import { Channel } from "@tauri-apps/api/core";
import { createProgressBar } from "~/routes/editor/utils";
@@ -21,6 +21,7 @@ function ShareButton(props: {
const [recordingMeta, metaActions] = createResource(() =>
commands.getRecordingMeta(videoId, "recording")
);
+ const [copyPressed, setCopyPressed] = createSignal(false);
const uploadVideo = createMutation(() => ({
mutationFn: async () => {
@@ -201,44 +202,62 @@ function ShareButton(props: {
>
{(sharing) => {
const url = () => new URL(sharing().link);
-
+ const copyLink = () => {
+ navigator.clipboard.writeText(sharing().link);
+ setCopyPressed(true);
+ setTimeout(() => {
+ setCopyPressed(false);
+ }, 2000);
+ };
return (
<div class="flex gap-3 items-center">
- <Tooltip.Root openDelay={0} closeDelay={0}>
- <Tooltip.Trigger>
- <Button
- disabled={uploadVideo.isPending}
- onClick={(e) => uploadVideo.mutate()}
- variant="primary"
- class="flex justify-center items-center size-[41px] !px-0 !py-0 space-x-1 rounded-xl"
- >
- {uploadVideo.isPending ? (
- <IconLucideLoaderCircle class="animate-spin size-4" />
- ) : (
- <IconLucideRotateCcw class="size-4" />
- )}
- </Button>
- </Tooltip.Trigger>
- <Tooltip.Portal>
- <Tooltip.Content class="z-50 px-2 py-1 text-xs text-gray-50 bg-gray-500 rounded shadow-lg duration-100 animate-in fade-in">
- {uploadVideo.isPending
- ? "Reuploading video"
- : "Reupload video"}
- <Tooltip.Arrow class="fill-gray-500" />
- </Tooltip.Content>
- </Tooltip.Portal>
- </Tooltip.Root>
- <a
- class="rounded-xl px-4 py-2.5 flex flex-row items-center gap-[0.375rem] bg-gray-200 hover:bg-gray-300 transition-colors duration-100"
- href={sharing().link}
- target="_blank"
- rel="noreferrer"
+ <Tooltip
+ content={
+ uploadVideo.isPending ? "Reuploading video" : "Reupload video"
+ }
>
- <span class="text-[0.875rem] text-gray-500">
- {url().host}
- {url().pathname}
- </span>
- </a>
+ <Button
+ disabled={uploadVideo.isPending}
+ onClick={(e) => uploadVideo.mutate()}
+ variant="primary"
+ class="flex justify-center items-center size-[41px] !px-0 !py-0 space-x-1 rounded-xl"
+ >
+ {uploadVideo.isPending ? (
+ <IconLucideLoaderCircle class="animate-spin size-4" />
+ ) : (
+ <IconLucideRotateCcw class="size-4" />
+ )}
+ </Button>
+ </Tooltip>
+ <Tooltip content="Open link">
+ <div class="rounded-xl px-4 py-2.5 flex flex-row items-center gap-[0.375rem] bg-gray-200 hover:bg-gray-300 transition-colors duration-100">
+ <a
+ href={sharing().link}
+ target="_blank"
+ rel="noreferrer"
+ class="w-full truncate max-w-48"
+ >
+ <span class="text-[0.875rem] text-gray-500">
+ {url().host}
+ {url().pathname}
+ </span>
+ </a>
+ {/** Copy button */}
+ <Tooltip content="Copy link">
+ <Button
+ variant="secondary"
+ class="flex justify-center items-center size-[28px] text-gray-500 !px-0 !py-0 space-x-1 rounded-[5px] bg-gray-300 hover:bg-gray-400"
+ onClick={copyLink}
+ >
+ {!copyPressed() ? (
+ <IconCapCopy class="size-3" />
+ ) : (
+ <IconLucideCheck class="size-3 svgpathanimation" />
+ )}
+ </Button>
+ </Tooltip>
+ </div>
+ </Tooltip>
</div>
);
}}
diff --git a/apps/desktop/src/styles/theme.css b/apps/desktop/src/styles/theme.css
index 9f17d3380..832efae07 100644
--- a/apps/desktop/src/styles/theme.css
+++ b/apps/desktop/src/styles/theme.css
@@ -174,6 +174,29 @@
border-radius: 500px;
}
+/* Copy animation */
+
+@keyframes svgpathframes {
+ 0% {
+ stroke-dasharray: 100;
+ stroke-dashoffset: 100;
+ opacity: 0;
+ }
+ 50% {
+ opacity: 1;
+ }
+ 100% {
+ stroke-dashoffset: 0;
+ }
+}
+
+.svgpathanimation {
+ stroke-dasharray: 100;
+ stroke-dashoffset: 100;
+ animation: svgpathframes 1s ease-in-out forwards;
+}
+
+
/* Tabs container with mask-based fade-out effect */
.tabs-mask-content {