MCPcopy Create free account
hub / github.com/PageAI-Pro/page-ui / BrickCopyCode

Function BrickCopyCode

components/bricks/brick-copy-code.tsx:11–103  ·  view source on GitHub ↗
({
  brick,
  demo,
}: {
  brick: string;
  demo: string;
})

Source from the content-addressed store, hash-verified

9import { BrickCodeEditorToggle } from '@/components/bricks/brick-code-toggle';
10
11export const BrickCopyCode = ({
12 brick,
13 demo,
14}: {
15 brick: string;
16 demo: string;
17}) => {
18 const [copied, setCopied] = useState(false);
19 const [failed, setFailed] = useState(false);
20 const [loading, setLoading] = useState(false);
21 const { formattedCodeString, errorString, getCode } = useCopyBrickCode({
22 brick,
23 demo,
24 });
25
26 const copyCode = async () => {
27 if (copied) {
28 return false;
29 }
30
31 setFailed(false);
32 setLoading(true);
33
34 try {
35 const code = await getCode();
36
37 if (!code) {
38 setFailed(true);
39 } else {
40 setCopied(true);
41 navigator.clipboard.writeText(code);
42 }
43 } catch (error) {
44 console.error(error);
45 setFailed(true);
46 } finally {
47 setLoading(false);
48 }
49
50 setTimeout(() => {
51 setCopied(false);
52 setFailed(false);
53 }, 2000);
54 };
55
56 const animation = {
57 initial: { opacity: 0, translateY: 10 },
58 animate: { opacity: 1, translateY: 0 },
59 transition: {
60 duration: 0.3,
61 ease: 'easeInOut',
62 },
63 exit: { opacity: 0, translateY: -10 },
64 };
65
66 return (
67 <div
68 className={cn(

Callers

nothing calls this directly

Calls 2

useCopyBrickCodeFunction · 0.90
cnFunction · 0.90

Tested by

no test coverage detected