Add collapsible code step component

- Create Step component to wrap code snippets in collapsible box
- Render Step instead of default code block for 'step' language
- Pass code snippet as children prop to Step
- Step renders language tag and toggle button
This commit is contained in:
Rankin Zheng 2023-10-11 23:51:57 +08:00 committed by bobo.yang
parent 950a1328a0
commit 3afd42c9d6
2 changed files with 44 additions and 0 deletions

View File

@ -0,0 +1,38 @@
import { Box, Button, Collapse, Group } from "@mantine/core";
import { useDisclosure } from "@mantine/hooks";
import React from "react";
import SyntaxHighlighter from "react-syntax-highlighter";
import LanguageCorner from "./LanguageCorner";
import { okaidia } from "react-syntax-highlighter/dist/esm/styles/prism";
interface StepProps {
language: string;
children: string;
}
const Step: React.FC<StepProps> = (props) => {
const {language,children} = props;
const [opened, { toggle }] = useDisclosure(false);
return (
<Box maw={400} mx="auto">
<Group mb={5}>
<Button onClick={toggle}>Toggle content</Button>
</Group>
<Collapse in={opened}>
<div style={{ position: 'relative' }}>
<LanguageCorner language={language} />
<SyntaxHighlighter {...props}
language={language}
customStyle={{ padding: '3em 1em 1em 2em' }}
style={okaidia}
PreTag="div">
{children}
</SyntaxHighlighter>
</div >
</Collapse>
</Box>
);
};
export default Step;

View File

@ -5,6 +5,7 @@ import rehypeRaw from "rehype-raw";
import { Prism as SyntaxHighlighter } from 'react-syntax-highlighter';
import { okaidia } from "react-syntax-highlighter/dist/esm/styles/prism";
import CodeButtons from "./CodeButtons";
import Step from "./Step";
import LanguageCorner from "./LanguageCorner";
import { observer } from "mobx-react-lite";
import { useMst } from "@/views/stores/RootStore";
@ -133,6 +134,11 @@ Generate a professionally written and formatted release note in markdown with th
if (lanugage === 'markdown' || lanugage === 'text') {
wrapLongLines = true;
}
if (lanugage === 'step') {
return <Step language={lanugage}>{value}</Step>;
}
return !inline && lanugage ? (
<div style={{ position: 'relative' }}>
<LanguageCorner language={lanugage} />