forked from CopilotKit/CopilotKit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathiframe-switcher.tsx
More file actions
132 lines (123 loc) · 3.08 KB
/
Copy pathiframe-switcher.tsx
File metadata and controls
132 lines (123 loc) · 3.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
import {
Tabs,
Tab,
TabsContent,
TabsList,
TabsTrigger,
} from "fumadocs-ui/components/tabs";
import { Monitor, Code } from "lucide-react";
interface IframeSwitcherProps {
id?: string;
exampleUrl: string;
codeUrl: string;
height?: string;
exampleLabel?: string;
codeLabel?: string;
}
export function IframeSwitcher({
id,
exampleUrl,
codeUrl,
height = "600px",
exampleLabel = "Example",
codeLabel = "Code",
}: IframeSwitcherProps) {
return (
<Tabs defaultValue={exampleLabel} id={id}>
<TabsList>
<TabsTrigger value={exampleLabel}>
<Monitor className="w-4 h-4" />
{exampleLabel}
</TabsTrigger>
<TabsTrigger value={codeLabel}>
<Code className="w-4 h-4" />
{codeLabel}
</TabsTrigger>
</TabsList>
<TabsContent className="p-0" value={exampleLabel}>
<iframe
src={exampleUrl}
className="w-full rounded-lg"
style={{ height }}
title="Interactive Example"
sandbox="allow-scripts allow-same-origin allow-forms allow-popups allow-modals"
/>
</TabsContent>
<TabsContent className="p-0" value={codeLabel}>
<iframe
src={codeUrl}
className="w-full rounded-lg"
style={{ height }}
title="Code View"
sandbox="allow-scripts allow-same-origin"
/>
</TabsContent>
</Tabs>
);
}
// Wrapper for multiple IframeSwitcher variants (e.g., different integrations)
interface IframeSwitcherVariant {
label: string;
exampleUrl: string;
codeUrl: string;
}
interface IframeSwitcherGroupProps {
id?: string;
variants: IframeSwitcherVariant[];
height?: string;
exampleLabel?: string;
codeLabel?: string;
}
export function IframeSwitcherGroup({
id,
variants,
height = "600px",
exampleLabel = "Example",
codeLabel = "Code",
}: IframeSwitcherGroupProps) {
const items = variants.map((v) => v.label);
const firstItem = items[0];
if (!firstItem || variants.length === 0) {
return null;
}
// Single variant - render without outer tabs
if (variants.length === 1) {
const variant = variants[0];
if (!variant) return null;
return (
<IframeSwitcher
id={id}
exampleUrl={variant.exampleUrl}
codeUrl={variant.codeUrl}
height={height}
exampleLabel={exampleLabel}
codeLabel={codeLabel}
/>
);
}
// Multiple variants - wrap with outer tabs
return (
<Tabs
groupId={`iframe-switcher-group-${id ?? "default"}`}
items={items}
defaultIndex={0}
>
{variants.map((variant) => (
<Tab key={variant.label} value={variant.label} className="p-0">
<IframeSwitcher
id={
id
? `${id}-${variant.label.toLowerCase().replace(/\s+/g, "-")}`
: undefined
}
exampleUrl={variant.exampleUrl}
codeUrl={variant.codeUrl}
height={height}
exampleLabel={exampleLabel}
codeLabel={codeLabel}
/>
</Tab>
))}
</Tabs>
);
}