11"use client" ;
22
3- import { useState } from "react" ;
3+ import { useTheme } from "next-themes" ;
4+ import { useEffect , useState } from "react" ;
45import { arbitrum } from "thirdweb/chains" ;
6+ import { TabButtons } from "@/components/ui/tab-buttons" ;
57import { LeftSection } from "../components/LeftSection" ;
68import { RightSection } from "../components/RightSection" ;
79import type { BridgeComponentsPlaygroundOptions } from "../components/types" ;
810
911const defaultOptions : BridgeComponentsPlaygroundOptions = {
12+ integrationType : "react" ,
1013 payOptions : {
1114 buyTokenAddress : undefined ,
1215 buyTokenAmount : "0.002" ,
@@ -29,16 +32,70 @@ const defaultOptions: BridgeComponentsPlaygroundOptions = {
2932 } ,
3033} ;
3134
32- export function BuyPlayground ( ) {
33- const [ options , setOptions ] =
34- useState < BridgeComponentsPlaygroundOptions > ( defaultOptions ) ;
35+ function updatePageUrl (
36+ tab : BridgeComponentsPlaygroundOptions [ "integrationType" ] ,
37+ ) {
38+ const url = new URL ( window . location . href ) ;
39+ if ( tab === defaultOptions . integrationType ) {
40+ url . searchParams . delete ( "tab" ) ;
41+ } else {
42+ url . searchParams . set ( "tab" , tab || "" ) ;
43+ }
44+
45+ window . history . replaceState ( { } , "" , url . toString ( ) ) ;
46+ }
47+
48+ export function BuyPlayground ( props : { defaultTab ?: "iframe" | "react" } ) {
49+ const { theme } = useTheme ( ) ;
50+
51+ const [ options , setOptions ] = useState < BridgeComponentsPlaygroundOptions > (
52+ ( ) => ( {
53+ ...defaultOptions ,
54+ integrationType : props . defaultTab || defaultOptions . integrationType ,
55+ } ) ,
56+ ) ;
57+
58+ // Change theme on global theme change
59+ useEffect ( ( ) => {
60+ setOptions ( ( prev ) => ( {
61+ ...prev ,
62+ theme : {
63+ ...prev . theme ,
64+ type : theme === "dark" ? "dark" : "light" ,
65+ } ,
66+ } ) ) ;
67+ } , [ theme ] ) ;
68+
69+ useEffect ( ( ) => {
70+ updatePageUrl ( options . integrationType ) ;
71+ } , [ options . integrationType ] ) ;
3572
3673 return (
37- < div className = "relative flex flex-col-reverse gap-6 xl:min-h-[900px] xl:flex-row xl:gap-6" >
38- < div className = "grow border-b pb-10 xl:mb-0 xl:border-r xl:border-b-0 xl:pr-6" >
39- < LeftSection widget = "buy" options = { options } setOptions = { setOptions } />
74+ < div >
75+ < TabButtons
76+ tabs = { [
77+ {
78+ name : "React" ,
79+ onClick : ( ) => setOptions ( { ...options , integrationType : "react" } ) ,
80+ isActive : options . integrationType === "react" ,
81+ } ,
82+ {
83+ name : "Iframe" ,
84+ onClick : ( ) =>
85+ setOptions ( { ...options , integrationType : "iframe" } ) ,
86+ isActive : options . integrationType === "iframe" ,
87+ } ,
88+ ] }
89+ />
90+
91+ < div className = "h-6" />
92+
93+ < div className = "relative flex flex-col-reverse gap-6 xl:min-h-[900px] xl:flex-row xl:gap-6" >
94+ < div className = "grow border-b pb-10 xl:mb-0 xl:border-r xl:border-b-0 xl:pr-6" >
95+ < LeftSection widget = "buy" options = { options } setOptions = { setOptions } />
96+ </ div >
97+ < RightSection widget = "buy" options = { options } />
4098 </ div >
41- < RightSection widget = "buy" options = { options } />
4299 </ div >
43100 ) ;
44101}
0 commit comments