Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,28 @@ const defaultOptions: BridgeWidgetPlaygroundOptions = {
},
};

export function BridgeWidgetPlayground() {
function updatePageUrl(tab: BridgeWidgetPlaygroundOptions["integrationType"]) {
const url = new URL(window.location.href);
if (tab === defaultOptions.integrationType) {
url.searchParams.delete("tab");
} else {
url.searchParams.set("tab", tab);
}

window.history.replaceState({}, "", url.toString());
}

export function BridgeWidgetPlayground(props: {
defaultTab: "iframe" | "script" | "react" | undefined;
}) {
const { theme } = useTheme();

const [options, setOptions] =
useState<BridgeWidgetPlaygroundOptions>(defaultOptions);
const [options, setOptions] = useState<BridgeWidgetPlaygroundOptions>(() => {
return {
...defaultOptions,
integrationType: props.defaultTab || defaultOptions.integrationType,
};
});

// change theme on global theme change
useEffect(() => {
Expand All @@ -36,6 +53,10 @@ export function BridgeWidgetPlayground() {
}));
}, [theme]);

useEffect(() => {
updatePageUrl(options.integrationType);
}, [options.integrationType]);

return (
<div>
<TabButtons
Expand All @@ -54,9 +75,8 @@ export function BridgeWidgetPlayground() {
},
{
name: "React",
onClick: () =>
setOptions({ ...options, integrationType: "component" }),
isActive: options.integrationType === "component",
onClick: () => setOptions({ ...options, integrationType: "react" }),
isActive: options.integrationType === "react",
},
]}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export function CodeGen(props: { options: BridgeWidgetPlaygroundOptions }) {
<CodeClient
className="grow"
code={getCode(props.options)}
lang={props.options.integrationType === "component" ? "tsx" : "html"}
lang={props.options.integrationType === "react" ? "tsx" : "html"}
/>
</Suspense>
</div>
Expand All @@ -36,7 +36,7 @@ function getCode(options: BridgeWidgetPlaygroundOptions) {
if (options.integrationType === "script") {
return getCode_Script(options);
}
if (options.integrationType === "component") {
if (options.integrationType === "react") {
return getCode_ReactComponent(options);
}
if (options.integrationType === "iframe") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type {
} from "thirdweb/react";

export type BridgeWidgetPlaygroundOptions = {
integrationType: "script" | "component" | "iframe";
integrationType: "iframe" | "script" | "react";
theme: {
type: "dark" | "light";
darkColorOverrides: ThemeOverrides["colors"];
Expand Down
19 changes: 17 additions & 2 deletions apps/playground-web/src/app/bridge/bridge-widget/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ const title = "Bridge Widget";
const description =
"Easily embed cross-chain token swap and fiat onramp UI into your app";

const validTabs = ["iframe", "script", "react"] as const;
type ValidTabs = (typeof validTabs)[number];

export const metadata = createMetadata({
description: description,
title,
Expand All @@ -17,7 +20,19 @@ export const metadata = createMetadata({
},
});

export default function Page() {
export default async function Page(props: {
searchParams: Promise<{
tab?: string | undefined | string[];
}>;
}) {
const searchParams = await props.searchParams;
const tab =
typeof searchParams.tab === "string" ? searchParams.tab : undefined;

const validTab = validTabs.includes(tab as ValidTabs)
? (tab as ValidTabs)
: undefined;

return (
<ThirdwebProvider>
<PageLayout
Expand All @@ -26,7 +41,7 @@ export default function Page() {
description={description}
docsLink="https://portal.thirdweb.com/bridge/bridge-widget?utm_source=playground"
>
<BridgeWidgetPlayground />
<BridgeWidgetPlayground defaultTab={validTab} />
</PageLayout>
</ThirdwebProvider>
);
Expand Down
20 changes: 17 additions & 3 deletions apps/portal/src/app/bridge/bridge-widget/iframe/page.mdx
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
import bridgeWidgetDark from "../bridge-widget-dark.png";
import bridgeWidgetLight from "../bridge-widget-light.png";
import {
Tabs,
TabsList,
TabsTrigger,
TabsContent,
ArticleIconCard,
Details,
createMetadata,
DocImage
} from "@doc";
import bridgeWidgetDark from "../bridge-widget-dark.png";
import bridgeWidgetLight from "../bridge-widget-light.png";
import { Tabs, TabsList, TabsTrigger, TabsContent } from "@doc";
import { IframeCodePreview } from "./iframe-code-preview";
import { PlayIcon } from "lucide-react";

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


## Try it out

<ArticleIconCard
title="Bridge Widget Playground"
description="Try out the Bridge Widget in our live playground"
icon={PlayIcon}
href="https://playground.thirdweb.com/bridge/bridge-widget"
/>

## Options

You can customize theme, currencies, token selections etc using query parameters as mentioned below
Expand Down
14 changes: 12 additions & 2 deletions apps/portal/src/app/bridge/bridge-widget/page.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
import bridgeWidgetDark from "./bridge-widget-dark.png";
import bridgeWidgetLight from "./bridge-widget-light.png";
import { ArticleIconCard, Grid } from "@doc";
import { CodeIcon, FrameIcon } from "lucide-react";
import { CodeIcon, FrameIcon, PlayIcon } from "lucide-react";
import { ReactIcon } from "@/icons";

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

</div>

</div>

## Try it out

<ArticleIconCard
title="Bridge Widget Playground"
description="Try out the Bridge Widget in our live playground"
icon={PlayIcon}
href="https://playground.thirdweb.com/bridge/bridge-widget"
/>
14 changes: 11 additions & 3 deletions apps/portal/src/app/bridge/bridge-widget/react/page.mdx
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import {
Details,
ArticleIconCard,
createMetadata,
DocImage
} from "@doc";
import bridgeWidgetDark from "../bridge-widget-dark.png";
import bridgeWidgetLight from "../bridge-widget-light.png";
import { Tabs, TabsList, TabsTrigger, TabsContent } from "@doc";
import { PlayIcon } from "lucide-react";
import { ReactIcon } from "@/icons";
import { ArticleIconCard } from "@doc";

export const metadata = createMetadata({
image: {
Expand Down Expand Up @@ -80,4 +79,13 @@ function Example() {
description="View the API reference for the BridgeWidget component"
icon={ReactIcon}
href="/references/typescript/v5/BridgeWidget"
/>

## Try it out

<ArticleIconCard
title="Bridge Widget Playground"
description="Try out the Bridge Widget in our live playground"
icon={PlayIcon}
href="https://playground.thirdweb.com/bridge/bridge-widget?tab=react"
/>
13 changes: 12 additions & 1 deletion apps/portal/src/app/bridge/bridge-widget/script/page.mdx
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import {
Details,
ArticleIconCard,
Details,
createMetadata,
DocImage
} from "@doc";
import bridgeWidgetDark from "../bridge-widget-dark.png";
import bridgeWidgetLight from "../bridge-widget-light.png";
import { PlayIcon } from "lucide-react";

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

## Try it out

<ArticleIconCard
title="Bridge Widget Playground"
description="Try out the Bridge Widget in our live playground"
icon={PlayIcon}
href="https://playground.thirdweb.com/bridge/bridge-widget?tab=script"
/>


## Options

Expand Down
2 changes: 1 addition & 1 deletion apps/portal/src/app/bridge/sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export const sidebar: SideBar = {
icon: <ZapIcon />,
},
{
href: "https://playground.thirdweb.com",
href: "https://playground.thirdweb.com/bridge",
name: "Playground",
icon: <ExternalLinkIcon />,
},
Expand Down
Loading