diff --git a/beszel/site/src/components/copy-to-clipboard.tsx b/beszel/site/src/components/copy-to-clipboard.tsx new file mode 100644 index 0000000..4e18688 --- /dev/null +++ b/beszel/site/src/components/copy-to-clipboard.tsx @@ -0,0 +1,49 @@ +import { useEffect, useMemo, useRef } from 'react' +import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle } from './ui/dialog' +import { Textarea } from './ui/textarea' +import { $copyContent } from '@/lib/stores' + +export default function CopyToClipboard({ content }: { content: string }) { + return ( + + + + Could not copy to clipboard + Please copy the text manually. + + +

+ Clipboard API requires a secure context (https, localhost, or *.localhost) +

+
+
+ ) +} + +function CopyTextarea({ content }: { content: string }) { + const textareaRef = useRef(null) + + const rows = useMemo(() => { + return content.split('\n').length + }, [content]) + + useEffect(() => { + if (textareaRef.current) { + textareaRef.current.select() + } + }, [textareaRef]) + + useEffect(() => { + return () => $copyContent.set('') + }, []) + + return ( +