Skip to content

Commit 9383ccd

Browse files
committed
Portal: Add bridge widget playground links (#8575)
<!-- ## title your PR with this format: "[SDK/Dashboard/Portal] Feature/Fix: Concise title for the changes" If you did not copy the branch name from Linear, paste the issue tag here (format is TEAM-0000): ## Notes for the reviewer Anything important to call out? Be sure to also clarify these in your comments. ## How to test Unit tests, playground, etc. --> <!-- start pr-codex --> --- ## PR-Codex overview This PR focuses on updating the `Bridge Widget` to enhance its integration options and improve user experience by adding a live playground feature. It modifies the integration types, updates the code logic, and introduces new UI components for better functionality. ### Detailed summary - Changed `href` in `sidebar.tsx` for the Playground link. - Updated `integrationType` options in `types.ts` to include "react". - Adjusted code language conditions in `code.tsx` based on `integrationType`. - Added `PlayIcon` and `ArticleIconCard` components in multiple `.mdx` files. - Introduced a "Try it out" section in several `.mdx` files for the Playground. - Modified the `Page` component to accept `searchParams` and determine the valid tab. - Enhanced `BridgeWidgetPlayground` to manage URL updates based on the selected integration type. > ✨ Ask PR-Codex anything about this PR by commenting with `/codex {your question}` <!-- end pr-codex --> <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Playground now supports URL parameters to pre-select integration tabs and keeps the browser URL in sync when switching tabs * React integration tab standardized and labeled consistently with other tabs * **Documentation** * Added "Try it out" call-to-action cards throughout docs linking to the live playground * **Chores** * Sidebar playground link updated to point to the bridge-specific playground URL <sub>✏️ Tip: You can customize this high-level summary in your review settings.</sub> <!-- end of auto-generated comment: release notes by coderabbit.ai -->
1 parent ac326e2 commit 9383ccd

File tree

9 files changed

+99
-21
lines changed

9 files changed

+99
-21
lines changed

apps/playground-web/src/app/bridge/bridge-widget/components/bridge-playground.tsx

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,28 @@ const defaultOptions: BridgeWidgetPlaygroundOptions = {
1919
},
2020
};
2121

22-
export function BridgeWidgetPlayground() {
22+
function updatePageUrl(tab: BridgeWidgetPlaygroundOptions["integrationType"]) {
23+
const url = new URL(window.location.href);
24+
if (tab === defaultOptions.integrationType) {
25+
url.searchParams.delete("tab");
26+
} else {
27+
url.searchParams.set("tab", tab);
28+
}
29+
30+
window.history.replaceState({}, "", url.toString());
31+
}
32+
33+
export function BridgeWidgetPlayground(props: {
34+
defaultTab: "iframe" | "script" | "react" | undefined;
35+
}) {
2336
const { theme } = useTheme();
2437

25-
const [options, setOptions] =
26-
useState<BridgeWidgetPlaygroundOptions>(defaultOptions);
38+
const [options, setOptions] = useState<BridgeWidgetPlaygroundOptions>(() => {
39+
return {
40+
...defaultOptions,
41+
integrationType: props.defaultTab || defaultOptions.integrationType,
42+
};
43+
});
2744

2845
// change theme on global theme change
2946
useEffect(() => {
@@ -36,6 +53,10 @@ export function BridgeWidgetPlayground() {
3653
}));
3754
}, [theme]);
3855

56+
useEffect(() => {
57+
updatePageUrl(options.integrationType);
58+
}, [options.integrationType]);
59+
3960
return (
4061
<div>
4162
<TabButtons
@@ -54,9 +75,8 @@ export function BridgeWidgetPlayground() {
5475
},
5576
{
5677
name: "React",
57-
onClick: () =>
58-
setOptions({ ...options, integrationType: "component" }),
59-
isActive: options.integrationType === "component",
78+
onClick: () => setOptions({ ...options, integrationType: "react" }),
79+
isActive: options.integrationType === "react",
6080
},
6181
]}
6282
/>

apps/playground-web/src/app/bridge/bridge-widget/components/code.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export function CodeGen(props: { options: BridgeWidgetPlaygroundOptions }) {
2525
<CodeClient
2626
className="grow"
2727
code={getCode(props.options)}
28-
lang={props.options.integrationType === "component" ? "tsx" : "html"}
28+
lang={props.options.integrationType === "react" ? "tsx" : "html"}
2929
/>
3030
</Suspense>
3131
</div>
@@ -36,7 +36,7 @@ function getCode(options: BridgeWidgetPlaygroundOptions) {
3636
if (options.integrationType === "script") {
3737
return getCode_Script(options);
3838
}
39-
if (options.integrationType === "component") {
39+
if (options.integrationType === "react") {
4040
return getCode_ReactComponent(options);
4141
}
4242
if (options.integrationType === "iframe") {

apps/playground-web/src/app/bridge/bridge-widget/components/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import type {
55
} from "thirdweb/react";
66

77
export type BridgeWidgetPlaygroundOptions = {
8-
integrationType: "script" | "component" | "iframe";
8+
integrationType: "iframe" | "script" | "react";
99
theme: {
1010
type: "dark" | "light";
1111
darkColorOverrides: ThemeOverrides["colors"];

apps/playground-web/src/app/bridge/bridge-widget/page.tsx

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ const title = "Bridge Widget";
88
const description =
99
"Easily embed cross-chain token swap and fiat onramp UI into your app";
1010

11+
const validTabs = ["iframe", "script", "react"] as const;
12+
type ValidTabs = (typeof validTabs)[number];
13+
1114
export const metadata = createMetadata({
1215
description: description,
1316
title,
@@ -17,7 +20,19 @@ export const metadata = createMetadata({
1720
},
1821
});
1922

20-
export default function Page() {
23+
export default async function Page(props: {
24+
searchParams: Promise<{
25+
tab?: string | undefined | string[];
26+
}>;
27+
}) {
28+
const searchParams = await props.searchParams;
29+
const tab =
30+
typeof searchParams.tab === "string" ? searchParams.tab : undefined;
31+
32+
const validTab = validTabs.includes(tab as ValidTabs)
33+
? (tab as ValidTabs)
34+
: undefined;
35+
2136
return (
2237
<ThirdwebProvider>
2338
<PageLayout
@@ -26,7 +41,7 @@ export default function Page() {
2641
description={description}
2742
docsLink="https://portal.thirdweb.com/bridge/bridge-widget?utm_source=playground"
2843
>
29-
<BridgeWidgetPlayground />
44+
<BridgeWidgetPlayground defaultTab={validTab} />
3045
</PageLayout>
3146
</ThirdwebProvider>
3247
);

apps/portal/src/app/bridge/bridge-widget/iframe/page.mdx

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
1+
import bridgeWidgetDark from "../bridge-widget-dark.png";
2+
import bridgeWidgetLight from "../bridge-widget-light.png";
13
import {
4+
Tabs,
5+
TabsList,
6+
TabsTrigger,
7+
TabsContent,
8+
ArticleIconCard,
29
Details,
310
createMetadata,
411
DocImage
512
} from "@doc";
6-
import bridgeWidgetDark from "../bridge-widget-dark.png";
7-
import bridgeWidgetLight from "../bridge-widget-light.png";
8-
import { Tabs, TabsList, TabsTrigger, TabsContent } from "@doc";
913
import { IframeCodePreview } from "./iframe-code-preview";
14+
import { PlayIcon } from "lucide-react";
1015

1116
export const metadata = createMetadata({
1217
image: {
@@ -42,6 +47,15 @@ The Bridge widget iframe makes it easy to embed cross-chain swaps and fiat onram
4247
<IframeCodePreview src="https://thirdweb.com/bridge/widget" />
4348

4449

50+
## Try it out
51+
52+
<ArticleIconCard
53+
title="Bridge Widget Playground"
54+
description="Try out the Bridge Widget in our live playground"
55+
icon={PlayIcon}
56+
href="https://playground.thirdweb.com/bridge/bridge-widget"
57+
/>
58+
4559
## Options
4660

4761
You can customize theme, currencies, token selections etc using query parameters as mentioned below

apps/portal/src/app/bridge/bridge-widget/page.mdx

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
import bridgeWidgetDark from "./bridge-widget-dark.png";
77
import bridgeWidgetLight from "./bridge-widget-light.png";
88
import { ArticleIconCard, Grid } from "@doc";
9-
import { CodeIcon, FrameIcon } from "lucide-react";
9+
import { CodeIcon, FrameIcon, PlayIcon } from "lucide-react";
1010
import { ReactIcon } from "@/icons";
1111

1212
export const metadata = createMetadata({
@@ -58,4 +58,14 @@ You can integrate the bridge widget into your website using an iframe, a script
5858
href="/bridge/bridge-widget/react"
5959
/>
6060

61-
</div>
61+
62+
</div>
63+
64+
## Try it out
65+
66+
<ArticleIconCard
67+
title="Bridge Widget Playground"
68+
description="Try out the Bridge Widget in our live playground"
69+
icon={PlayIcon}
70+
href="https://playground.thirdweb.com/bridge/bridge-widget"
71+
/>

apps/portal/src/app/bridge/bridge-widget/react/page.mdx

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
import {
2-
Details,
2+
ArticleIconCard,
33
createMetadata,
44
DocImage
55
} from "@doc";
66
import bridgeWidgetDark from "../bridge-widget-dark.png";
77
import bridgeWidgetLight from "../bridge-widget-light.png";
8-
import { Tabs, TabsList, TabsTrigger, TabsContent } from "@doc";
8+
import { PlayIcon } from "lucide-react";
99
import { ReactIcon } from "@/icons";
10-
import { ArticleIconCard } from "@doc";
1110

1211
export const metadata = createMetadata({
1312
image: {
@@ -80,4 +79,13 @@ function Example() {
8079
description="View the API reference for the BridgeWidget component"
8180
icon={ReactIcon}
8281
href="/references/typescript/v5/BridgeWidget"
82+
/>
83+
84+
## Try it out
85+
86+
<ArticleIconCard
87+
title="Bridge Widget Playground"
88+
description="Try out the Bridge Widget in our live playground"
89+
icon={PlayIcon}
90+
href="https://playground.thirdweb.com/bridge/bridge-widget?tab=react"
8391
/>

apps/portal/src/app/bridge/bridge-widget/script/page.mdx

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import {
2-
Details,
2+
ArticleIconCard,
3+
Details,
34
createMetadata,
45
DocImage
56
} from "@doc";
67
import bridgeWidgetDark from "../bridge-widget-dark.png";
78
import bridgeWidgetLight from "../bridge-widget-light.png";
9+
import { PlayIcon } from "lucide-react";
810

911
export const metadata = createMetadata({
1012
image: {
@@ -56,6 +58,15 @@ The Bridge widget script makes it easy to embed cross-chain swaps and fiat onram
5658
</script>
5759
```
5860

61+
## Try it out
62+
63+
<ArticleIconCard
64+
title="Bridge Widget Playground"
65+
description="Try out the Bridge Widget in our live playground"
66+
icon={PlayIcon}
67+
href="https://playground.thirdweb.com/bridge/bridge-widget?tab=script"
68+
/>
69+
5970

6071
## Options
6172

apps/portal/src/app/bridge/sidebar.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export const sidebar: SideBar = {
1313
icon: <ZapIcon />,
1414
},
1515
{
16-
href: "https://playground.thirdweb.com",
16+
href: "https://playground.thirdweb.com/bridge",
1717
name: "Playground",
1818
icon: <ExternalLinkIcon />,
1919
},

0 commit comments

Comments
 (0)