|
1 | 1 | 'use client'; |
2 | 2 |
|
3 | | -import React, { useState, useEffect } from 'react'; |
| 3 | +import React, { useState } from 'react'; |
4 | 4 | import { SchemaRenderer } from '@object-ui/react'; |
5 | 5 | import type { SchemaNode } from '@object-ui/core'; |
6 | 6 | import dynamic from 'next/dynamic'; |
@@ -215,6 +215,20 @@ export default function PlaygroundPage() { |
215 | 215 | const [editorValue, setEditorValue] = useState(JSON.stringify(DEFAULT_SCHEMA, null, 2)); |
216 | 216 | const [error, setError] = useState<string | null>(null); |
217 | 217 | const [selectedExample, setSelectedExample] = useState<keyof typeof EXAMPLE_SCHEMAS>('basic'); |
| 218 | + const [editorTheme, setEditorTheme] = useState<'vs-dark' | 'light'>('vs-dark'); |
| 219 | + |
| 220 | + // Detect system theme |
| 221 | + React.useEffect(() => { |
| 222 | + const darkModeQuery = window.matchMedia('(prefers-color-scheme: dark)'); |
| 223 | + setEditorTheme(darkModeQuery.matches ? 'vs-dark' : 'light'); |
| 224 | + |
| 225 | + const handleChange = (e: MediaQueryListEvent) => { |
| 226 | + setEditorTheme(e.matches ? 'vs-dark' : 'light'); |
| 227 | + }; |
| 228 | + |
| 229 | + darkModeQuery.addEventListener('change', handleChange); |
| 230 | + return () => darkModeQuery.removeEventListener('change', handleChange); |
| 231 | + }, []); |
218 | 232 |
|
219 | 233 | const handleEditorChange = (value: string | undefined) => { |
220 | 234 | if (!value) return; |
@@ -289,7 +303,7 @@ export default function PlaygroundPage() { |
289 | 303 | defaultLanguage="json" |
290 | 304 | value={editorValue} |
291 | 305 | onChange={handleEditorChange} |
292 | | - theme="vs-dark" |
| 306 | + theme={editorTheme} |
293 | 307 | options={{ |
294 | 308 | minimap: { enabled: false }, |
295 | 309 | fontSize: 14, |
|
0 commit comments