'use client'; import { CheckIcon, CopyIcon, Loader2Icon, XIcon } from 'lucide-react'; import { Button } from '@/components/shared/ui/button'; import { motion } from 'framer-motion'; import { cn } from '@/lib/utils'; import { useState } from 'react'; import { useCopyBrickCode } from '@/components/bricks/useCopyBrickCode'; import { BrickCodeEditorToggle } from '@/components/bricks/brick-code-toggle'; export const BrickCopyCode = ({ brick, demo, }: { brick: string; demo: string; }) => { const [copied, setCopied] = useState(false); const [failed, setFailed] = useState(false); const [loading, setLoading] = useState(false); const { formattedCodeString, errorString, getCode } = useCopyBrickCode({ brick, demo, }); const copyCode = async () => { if (copied) { return false; } setFailed(false); setLoading(true); try { const code = await getCode(); if (!code) { setFailed(true); } else { setCopied(true); navigator.clipboard.writeText(code); } } catch (error) { console.error(error); setFailed(true); } finally { setLoading(false); } setTimeout(() => { setCopied(false); setFailed(false); }, 2000); }; const animation = { initial: { opacity: 0, translateY: 10 }, animate: { opacity: 1, translateY: 0 }, transition: { duration: 0.3, ease: 'easeInOut', }, exit: { opacity: 0, translateY: -10 }, }; return (
); }; export default BrickCopyCode;