fix(custom-widgets): sync option editor theme
This commit is contained in:
1 file changed
+19
-4
@@ -17,6 +17,7 @@ import {
|
|||||||
Text,
|
Text,
|
||||||
Textarea,
|
Textarea,
|
||||||
TextInput,
|
TextInput,
|
||||||
|
useComputedColorScheme,
|
||||||
} from "@mantine/core";
|
} from "@mantine/core";
|
||||||
import { DateInput, TimeInput } from "@mantine/dates";
|
import { DateInput, TimeInput } from "@mantine/dates";
|
||||||
import { IconAlertTriangle, IconBraces } from "@tabler/icons-react";
|
import { IconAlertTriangle, IconBraces } from "@tabler/icons-react";
|
||||||
@@ -31,6 +32,7 @@ import type { CommonWidgetInputProps } from "./common";
|
|||||||
import { useFormContext } from "./form";
|
import { useFormContext } from "./form";
|
||||||
|
|
||||||
const CodeMirror = dynamic(() => import("@uiw/react-codemirror").then((module) => module.default), { ssr: false });
|
const CodeMirror = dynamic(() => import("@uiw/react-codemirror").then((module) => module.default), { ssr: false });
|
||||||
|
const jsonExtensions = [json()];
|
||||||
|
|
||||||
type Schema = Record<string, unknown>;
|
type Schema = Record<string, unknown>;
|
||||||
|
|
||||||
@@ -405,9 +407,8 @@ function AdvancedJson({
|
|||||||
<Accordion.Item value="json">
|
<Accordion.Item value="json">
|
||||||
<Accordion.Control icon={<IconBraces size={16} />}>{labels("advancedJson")}</Accordion.Control>
|
<Accordion.Control icon={<IconBraces size={16} />}>{labels("advancedJson")}</Accordion.Control>
|
||||||
<Accordion.Panel>
|
<Accordion.Panel>
|
||||||
<CodeMirror
|
<ConfigurationJsonEditor
|
||||||
value={draft}
|
value={draft}
|
||||||
extensions={[json()]}
|
|
||||||
height="220px"
|
height="220px"
|
||||||
onChange={(next) => {
|
onChange={(next) => {
|
||||||
setDraft(next);
|
setDraft(next);
|
||||||
@@ -460,9 +461,8 @@ function JsonValueInput({
|
|||||||
{description}
|
{description}
|
||||||
</Text>
|
</Text>
|
||||||
)}
|
)}
|
||||||
<CodeMirror
|
<ConfigurationJsonEditor
|
||||||
value={draft}
|
value={draft}
|
||||||
extensions={[json()]}
|
|
||||||
height="160px"
|
height="160px"
|
||||||
onChange={(next) => {
|
onChange={(next) => {
|
||||||
setDraft(next);
|
setDraft(next);
|
||||||
@@ -484,6 +484,21 @@ function JsonValueInput({
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function ConfigurationJsonEditor({
|
||||||
|
value,
|
||||||
|
height,
|
||||||
|
onChange,
|
||||||
|
}: {
|
||||||
|
value: string;
|
||||||
|
height: string;
|
||||||
|
onChange(value: string): void;
|
||||||
|
}) {
|
||||||
|
const colorScheme = useComputedColorScheme("light");
|
||||||
|
return (
|
||||||
|
<CodeMirror value={value} extensions={jsonExtensions} height={height} theme={colorScheme} onChange={onChange} />
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
function inferControl(schema: Schema) {
|
function inferControl(schema: Schema) {
|
||||||
if (Array.isArray(schema.enum)) return "select";
|
if (Array.isArray(schema.enum)) return "select";
|
||||||
if (schema.type === "boolean") return "switch";
|
if (schema.type === "boolean") return "switch";
|
||||||
|
|||||||
Reference in new issue
Block a user