Skip to content

Commit c086813

Browse files
Copilothotlong
andcommitted
Address code review feedback: remove unused import and add theme detection
Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
1 parent 3183ea8 commit c086813

1 file changed

Lines changed: 16 additions & 2 deletions

File tree

apps/site/app/playground/page.tsx

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use client';
22

3-
import React, { useState, useEffect } from 'react';
3+
import React, { useState } from 'react';
44
import { SchemaRenderer } from '@object-ui/react';
55
import type { SchemaNode } from '@object-ui/core';
66
import dynamic from 'next/dynamic';
@@ -215,6 +215,20 @@ export default function PlaygroundPage() {
215215
const [editorValue, setEditorValue] = useState(JSON.stringify(DEFAULT_SCHEMA, null, 2));
216216
const [error, setError] = useState<string | null>(null);
217217
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+
}, []);
218232

219233
const handleEditorChange = (value: string | undefined) => {
220234
if (!value) return;
@@ -289,7 +303,7 @@ export default function PlaygroundPage() {
289303
defaultLanguage="json"
290304
value={editorValue}
291305
onChange={handleEditorChange}
292-
theme="vs-dark"
306+
theme={editorTheme}
293307
options={{
294308
minimap: { enabled: false },
295309
fontSize: 14,

0 commit comments

Comments
 (0)