Fix CompareFunctions for mobile
This commit is contained in:
@@ -1,17 +1,10 @@
|
|||||||
import { HStack, VStack } from "@chakra-ui/react";
|
import { HStack, VStack, useBreakpointValue } from "@chakra-ui/react";
|
||||||
import React from "react";
|
import React from "react";
|
||||||
import DiffViewer, { DiffMethod } from "react-diff-viewer";
|
import DiffViewer, { DiffMethod } from "react-diff-viewer";
|
||||||
import Prism from "prismjs";
|
import Prism from "prismjs";
|
||||||
import "prismjs/components/prism-javascript";
|
import "prismjs/components/prism-javascript";
|
||||||
import "prismjs/themes/prism.css"; // choose a theme you like
|
import "prismjs/themes/prism.css"; // choose a theme you like
|
||||||
|
|
||||||
const CompareFunctions = ({
|
|
||||||
originalFunction,
|
|
||||||
newFunction = "",
|
|
||||||
}: {
|
|
||||||
originalFunction: string;
|
|
||||||
newFunction?: string;
|
|
||||||
}) => {
|
|
||||||
const highlightSyntax = (str: string) => {
|
const highlightSyntax = (str: string) => {
|
||||||
let highlighted;
|
let highlighted;
|
||||||
try {
|
try {
|
||||||
@@ -22,13 +15,32 @@ const CompareFunctions = ({
|
|||||||
}
|
}
|
||||||
return <pre style={{ display: "inline" }} dangerouslySetInnerHTML={{ __html: highlighted }} />;
|
return <pre style={{ display: "inline" }} dangerouslySetInnerHTML={{ __html: highlighted }} />;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const CompareFunctions = ({
|
||||||
|
originalFunction,
|
||||||
|
newFunction = "",
|
||||||
|
}: {
|
||||||
|
originalFunction: string;
|
||||||
|
newFunction?: string;
|
||||||
|
}) => {
|
||||||
|
const showSplitView = useBreakpointValue(
|
||||||
|
{
|
||||||
|
base: false,
|
||||||
|
md: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
fallback: "base",
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<HStack w="full" spacing={5}>
|
<HStack w="full" spacing={5}>
|
||||||
<VStack w="full" spacing={4} maxH="50vh" fontSize={12} lineHeight={1} overflowY="auto">
|
<VStack w="full" spacing={4} maxH="50vh" fontSize={12} lineHeight={1} overflowY="auto">
|
||||||
<DiffViewer
|
<DiffViewer
|
||||||
oldValue={originalFunction}
|
oldValue={originalFunction}
|
||||||
newValue={newFunction || originalFunction}
|
newValue={newFunction || originalFunction}
|
||||||
splitView={true}
|
splitView={showSplitView}
|
||||||
|
hideLineNumbers={!showSplitView}
|
||||||
leftTitle="Original"
|
leftTitle="Original"
|
||||||
rightTitle={newFunction ? "Modified" : "Unmodified"}
|
rightTitle={newFunction ? "Modified" : "Unmodified"}
|
||||||
disableWordDiff={true}
|
disableWordDiff={true}
|
||||||
|
|||||||
Reference in New Issue
Block a user