Fix CompareFunctions for mobile
This commit is contained in:
@@ -1,18 +1,11 @@
|
|||||||
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 = ({
|
const highlightSyntax = (str: string) => {
|
||||||
originalFunction,
|
|
||||||
newFunction = "",
|
|
||||||
}: {
|
|
||||||
originalFunction: string;
|
|
||||||
newFunction?: string;
|
|
||||||
}) => {
|
|
||||||
const highlightSyntax = (str: string) => {
|
|
||||||
let highlighted;
|
let highlighted;
|
||||||
try {
|
try {
|
||||||
highlighted = Prism.highlight(str, Prism.languages.javascript as Prism.Grammar, "javascript");
|
highlighted = Prism.highlight(str, Prism.languages.javascript as Prism.Grammar, "javascript");
|
||||||
@@ -21,14 +14,33 @@ const CompareFunctions = ({
|
|||||||
highlighted = str;
|
highlighted = str;
|
||||||
}
|
}
|
||||||
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