-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathCodeViewer.tsx
54 lines (50 loc) · 1.63 KB
/
CodeViewer.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import { CodeContent } from '../CodeContent/CodeContent';
import { LineNumbers } from '../LineNumbers/LineNumbers';
import { parseHighlightCss } from '../../utils/parseHighlightCss';
import { parseHighlightHtml } from '../../utils/parseHighlightHtml';
import styles from '../../styles/CodeViewer.module.css';
import { useCoachMarkStore } from '@/shared/store/useCoachMarkStore';
type CodeViewerProps = {
code: string;
type: 'html' | 'css';
theme?: 'light' | 'dark';
selectedBlockStartLine?: number;
selectedBlockLength?: number;
selectedBlockType?: string | null;
};
/**
*
* @description
* 변환된 HTML, CSS 코드를 줄 수와 함께 보여주는 컴포넌트
*/
export const CodeViewer = ({
code,
type,
theme,
selectedBlockStartLine,
selectedBlockLength,
selectedBlockType,
}: CodeViewerProps) => {
const parsedCode =
type === 'html'
? parseHighlightHtml(code, styles, selectedBlockType!)
: parseHighlightCss(code, styles, selectedBlockType!);
const codeLineList = parsedCode.split('\n').filter((line) => line.trim() !== '');
const { currentStep } = useCoachMarkStore();
return (
<div
className={`${styles.viewer} ${theme === 'dark' ? styles.dark : styles.light} ${currentStep === 3 ? 'z-[200] bg-white' : ''}`}
>
<div className={styles.scrollContainer}>
<LineNumbers codeLineList={codeLineList} />
<CodeContent
code={code}
codeLineList={codeLineList}
selectedBlockLength={selectedBlockLength}
selectedBlockStartLine={selectedBlockStartLine}
selectedBlockType={selectedBlockType}
/>
</div>
</div>
);
};