Skip to content

Commit 2a21985

Browse files
committed
fix: json viewer styling
1 parent c890515 commit 2a21985

File tree

5 files changed

+38
-4
lines changed

5 files changed

+38
-4
lines changed

public/build/preview.wasm

-1.55 KB
Binary file not shown.

src/Preview.tsx

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import { AnimatePresence, motion } from "motion/react";
2929
import { type FC, useCallback, useEffect, useMemo, useState } from "react";
3030
import { useSearchParams } from "react-router";
3131
import ReactJsonView from "@microlink/react-json-view";
32+
import { useTheme } from "@/contexts/theme";
3233

3334
export const Preview: FC = () => {
3435
const $wasmState = useStore((state) => state.wasmState);
@@ -378,6 +379,7 @@ type DebuggerProps = {
378379
output: PreviewOutput | null;
379380
};
380381
const Debugger: FC<DebuggerProps> = ({ output }) => {
382+
const { appliedTheme } = useTheme();
381383
const parserLogs = output?.parser_logs ?? [];
382384

383385
return (
@@ -386,8 +388,15 @@ const Debugger: FC<DebuggerProps> = ({ output }) => {
386388
className="h-full w-full bg-surface-primary"
387389
>
388390
<ResizablePanel className="flex">
389-
<div className="h-full w-full overflow-scroll p-4">
390-
<ReactJsonView src={output ?? {}} collapsed={1} />
391+
<div className="h-full w-full overflow-scroll break-all p-4">
392+
<ReactJsonView
393+
src={output ?? {}}
394+
collapsed={1}
395+
theme={appliedTheme === "dark" ? "brewer" : "rjv-default"}
396+
style={{
397+
background: "inherit",
398+
}}
399+
/>
391400
</div>
392401
</ResizablePanel>
393402
<ResizableHandle className="bg-surface-quaternary" />

src/contexts/theme.tsx

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import {
22
createContext,
33
useContext,
44
useEffect,
5+
useMemo,
56
useState,
67
type FC,
78
type PropsWithChildren,
@@ -19,11 +20,13 @@ type Theme = v.InferInput<typeof ThemeSchema>;
1920

2021
type ThemeContext = {
2122
theme: Theme;
23+
appliedTheme: "light" | "dark";
2224
setTheme: (theme: Theme) => void;
2325
};
2426

2527
const ThemeContext = createContext<ThemeContext>({
2628
theme: "system",
29+
appliedTheme: "dark",
2730
setTheme: () => null,
2831
});
2932

@@ -41,6 +44,18 @@ export const ThemeProvider: FC<PropsWithChildren> = ({ children }) => {
4144
return parsedTheme.output;
4245
});
4346

47+
const appliedTheme = useMemo(() => {
48+
if (theme === "system") {
49+
if (window.matchMedia("(prefers-color-scheme: dark)").matches) {
50+
return "dark";
51+
}
52+
53+
return "light";
54+
}
55+
56+
return theme;
57+
}, [theme]);
58+
4459
useEffect(() => {
4560
const force =
4661
theme === "dark" ||
@@ -57,7 +72,7 @@ export const ThemeProvider: FC<PropsWithChildren> = ({ children }) => {
5772
}, [theme]);
5873

5974
return (
60-
<ThemeContext.Provider value={{ theme, setTheme }}>
75+
<ThemeContext.Provider value={{ theme, setTheme, appliedTheme }}>
6176
{children}
6277
</ThemeContext.Provider>
6378
);

src/index.css

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,4 +128,14 @@
128128
text-align: right;
129129
width: 40px;
130130
font-weight: 100;
131+
}
132+
133+
/* Styles for the JSON viewer */
134+
135+
.react-json-view {
136+
background: hsl(var(--surface-primary)) !important;
137+
}
138+
139+
.copy-to-clipboard-container span {
140+
display: flex !important;
131141
}

tailwind.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,5 +85,5 @@ module.exports = {
8585
},
8686
},
8787
},
88-
plugins: [require("tailwindcss-animate"), require("@tailwindcss/typography")],
88+
plugins: [require("tailwindcss-animate"), ],
8989
};

0 commit comments

Comments
 (0)