@@ -13,6 +13,7 @@ interface URLParamsState {
1313 featurePickerHidden : boolean ;
1414 file ?: string ;
1515 codeLayout : "sidebar" | "tabs" ;
16+ theme : "light" | "dark" ;
1617}
1718
1819interface URLParamsContextType extends URLParamsState {
@@ -24,6 +25,7 @@ interface URLParamsContextType extends URLParamsState {
2425 setFeaturePickerHidden : ( disabled : boolean ) => void ;
2526 setCodeFile : ( fileName : string ) => void ;
2627 setCodeLayout : ( layout : "sidebar" | "tabs" ) => void ;
28+ setTheme : ( theme : "light" | "dark" ) => void ;
2729}
2830
2931const URLParamsContext = createContext < URLParamsContextType | undefined > ( undefined ) ;
@@ -46,6 +48,7 @@ export function URLParamsProvider({ children }: URLParamsProviderProps) {
4648 viewPickerHidden : searchParams . get ( "viewPicker" ) === "false" ,
4749 featurePickerHidden : searchParams . get ( "featurePicker" ) === "false" ,
4850 codeLayout : ( searchParams . get ( "codeLayout" ) as "sidebar" | "tabs" ) || "sidebar" ,
51+ theme : ( searchParams . get ( "theme" ) as "light" | "dark" ) || "light" ,
4952 } ) ) ;
5053
5154 // Update URL when state changes
@@ -114,6 +117,15 @@ export function URLParamsProvider({ children }: URLParamsProviderProps) {
114117 }
115118 }
116119
120+ // Update theme param
121+ if ( newState . theme !== undefined ) {
122+ if ( newState . theme === "light" ) {
123+ params . delete ( "theme" ) ;
124+ } else {
125+ params . set ( "theme" , newState . theme ) ;
126+ }
127+ }
128+
117129 // Update file param
118130 if ( newState . file !== undefined ) {
119131 params . set ( "file" , newState . file ) ;
@@ -134,6 +146,7 @@ export function URLParamsProvider({ children }: URLParamsProviderProps) {
134146 featurePickerHidden : searchParams . get ( "featurePicker" ) === "false" ,
135147 file : searchParams . get ( "file" ) || undefined ,
136148 codeLayout : ( searchParams . get ( "codeLayout" ) as "sidebar" | "tabs" ) || "sidebar" ,
149+ theme : ( searchParams . get ( "theme" ) as "light" | "dark" ) || "light" ,
137150 } ;
138151
139152 setState ( newState ) ;
@@ -188,6 +201,12 @@ export function URLParamsProvider({ children }: URLParamsProviderProps) {
188201 updateURL ( { codeLayout } ) ;
189202 } ;
190203
204+ const setTheme = ( theme : "light" | "dark" ) => {
205+ const newState = { ...state , theme } ;
206+ setState ( newState ) ;
207+ updateURL ( { theme } ) ;
208+ } ;
209+
191210 const contextValue : URLParamsContextType = {
192211 ...state ,
193212 setView,
@@ -198,6 +217,7 @@ export function URLParamsProvider({ children }: URLParamsProviderProps) {
198217 setFeaturePickerHidden,
199218 setCodeFile,
200219 setCodeLayout,
220+ setTheme,
201221 } ;
202222
203223 return < URLParamsContext . Provider value = { contextValue } > { children } </ URLParamsContext . Provider > ;
0 commit comments