mirror of
https://github.com/hibiken/asynqmon.git
synced 2025-10-22 06:16:11 +08:00
Create wrapper component for sytanx-highlighter component
This commit is contained in:
26
ui/src/components/SyntaxHighlighter.tsx
Normal file
26
ui/src/components/SyntaxHighlighter.tsx
Normal file
@@ -0,0 +1,26 @@
|
||||
import React from "react";
|
||||
import { useTheme, Theme } from "@material-ui/core/styles";
|
||||
import ReactSyntaxHighlighter from "react-syntax-highlighter";
|
||||
import styleDark from "react-syntax-highlighter/dist/esm/styles/hljs/atom-one-dark";
|
||||
import styleLight from "react-syntax-highlighter/dist/esm/styles/hljs/atom-one-light";
|
||||
|
||||
interface Props {
|
||||
language: string;
|
||||
children: string;
|
||||
customStyle?: object;
|
||||
}
|
||||
|
||||
// Theme aware syntax-highlighter component.
|
||||
export default function SyntaxHighlighter(props: Props) {
|
||||
const theme = useTheme<Theme>();
|
||||
const style = theme.palette.type === "dark" ? styleDark : styleLight;
|
||||
return (
|
||||
<ReactSyntaxHighlighter
|
||||
language={props.language}
|
||||
style={style}
|
||||
customStyle={props.customStyle}
|
||||
>
|
||||
{props.children}
|
||||
</ReactSyntaxHighlighter>
|
||||
);
|
||||
}
|
Reference in New Issue
Block a user