From ea8983bdd60c9536d5a76a50af6da6c625e66c95 Mon Sep 17 00:00:00 2001 From: Michel Roegl-Brunner Date: Thu, 24 Apr 2025 10:02:11 +0200 Subject: [PATCH] Handel Responsive/Mobile --- .../_components/ScriptItems/ConfigFile.tsx | 4 +- .../src/components/ui/config-copy-button.tsx | 55 +++++++++++++++++++ 2 files changed, 57 insertions(+), 2 deletions(-) create mode 100644 frontend/src/components/ui/config-copy-button.tsx diff --git a/frontend/src/app/scripts/_components/ScriptItems/ConfigFile.tsx b/frontend/src/app/scripts/_components/ScriptItems/ConfigFile.tsx index c484aa5..0f4f43f 100644 --- a/frontend/src/app/scripts/_components/ScriptItems/ConfigFile.tsx +++ b/frontend/src/app/scripts/_components/ScriptItems/ConfigFile.tsx @@ -1,10 +1,10 @@ -import CodeCopyButton from "@/components/ui/code-copy-button"; +import ConfigCopyButton from "@/components/ui/config-copy-button"; import { Script } from "@/lib/types"; export default function ConfigFile({ item }: { item: Script }) { return (
- {item.config_path ? item.config_path : "No config path set"} + {item.config_path ? item.config_path : "No config path set"}
); } diff --git a/frontend/src/components/ui/config-copy-button.tsx b/frontend/src/components/ui/config-copy-button.tsx new file mode 100644 index 0000000..45fc2e9 --- /dev/null +++ b/frontend/src/components/ui/config-copy-button.tsx @@ -0,0 +1,55 @@ +"use client"; +import { cn } from "@/lib/utils"; +import { CheckIcon, ClipboardIcon } from "lucide-react"; +import { useEffect, useState } from "react"; +import { toast } from "sonner"; +import { Card } from "./card"; + +export default function CodeCopyButton({ + children, +}: { + children: React.ReactNode; +}) { + const [hasCopied, setHasCopied] = useState(false); + const isMobile = window.innerWidth <= 640; + + useEffect(() => { + if (hasCopied) { + setTimeout(() => { + setHasCopied(false); + }, 2000); + } + }, [hasCopied]); + + const handleCopy = (type: string, value: any) => { + navigator.clipboard.writeText(value); + + setHasCopied(true); + + + // toast.success(`copied ${type} to clipboard`, { + // icon: , + // }); + }; + + return ( +
+ +
+ {!isMobile && children ? children : "Copy Config File Path"} +
+
handleCopy("install command", children)} + > + {hasCopied ? ( + + ) : ( + + )} + Copy +
+
+
+ ); +}