Skip to content

Commit

Permalink
refactor: AnswerCodeBlock > 공용 컴포넌트로 이동
Browse files Browse the repository at this point in the history
  • Loading branch information
YuHyun-P committed Dec 7, 2023
1 parent 5f7bfa8 commit 0fddb8d
Show file tree
Hide file tree
Showing 9 changed files with 46 additions and 32 deletions.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import { Info, Modal } from "../../../design-system/components/common";
import { AnswerCodeBlock } from "../AnswerCodeBlock";
import {
CodeBlock,
Info,
Modal,
} from "../../../design-system/components/common";
import typography from "../../../design-system/tokens/typography";

import * as styles from "./QuizAnswerModal.css";

Expand All @@ -15,7 +19,7 @@ export default function QuizAnswerModal({
return (
<Modal onClose={closeModal}>
<h3 className={styles.h3}>모범 답안</h3>
<AnswerCodeBlock answer={answer} />
<CodeBlock code={answer} className={typography.$semantic.body2Regular} />
<Info>
본 답안은 모범 답안으로 제공되었으며, 상황에 따라 다양한 해결책이 있을
수 있습니다.
Expand Down
1 change: 0 additions & 1 deletion packages/frontend/src/components/quiz/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,3 @@ export { default as QuizLocation } from "./QuizLocation";
export { default as CommandAccordion } from "./CommandAccordion";
export { SolvedModal, useSolvedModal } from "./SolvedModal";
export { default as QuizAnswerModal } from "./QuizAnswerModal";
export { AnswerCodeBlock } from "./AnswerCodeBlock";
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import { globalStyle, style } from "@vanilla-extract/css";

import color from "../../../design-system/tokens/color";
import typography from "../../../design-system/tokens/typography";
import color from "../../../tokens/color";
import { borderRadius } from "../../../tokens/utils.css";

export const answerContainer = style([
typography.$semantic.body2Regular,
export const container = style([
borderRadius,
{
backgroundColor: color.$semantic.bgAlt,
borderRadius: 8,
width: "100%",
padding: "23px 25px",
marginBottom: 19,
Expand All @@ -16,6 +15,6 @@ export const answerContainer = style([
},
]);

globalStyle(`${answerContainer} code`, {
globalStyle(`${container} code`, {
color: color.$scale.coral500,
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { container } from "./CodeBlock.css";

interface CodeBlockProps {
code: string[];
className?: string;
}

export function CodeBlock({ code, className = "" }: CodeBlockProps) {
return (
<p
className={[className, container].join(" ").trim()}
dangerouslySetInnerHTML={{
__html: toCodeTag(code.join("\n")),
}}
/>
);
}

function toCodeTag(code: string) {
return code.replaceAll(/`(.*?)`/g, "<code>$1</code>");
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { CodeBlock } from "./CodeBlock";
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ export { toast, ToastContainer } from "./Toast";
export { Accordion, useAccordion } from "./Accordion";
export { default as Footer } from "./Footer";
export { default as Info } from "./Info";
export { CodeBlock } from "./CodeBlock";
14 changes: 11 additions & 3 deletions packages/frontend/src/pages/share/[slug].page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,14 @@ import { useRouter } from "next/router";
import { useCallback, useEffect, useState } from "react";

import { GetSharedAnswerResponse, quizAPI } from "../../apis/quiz";
import { AnswerCodeBlock, QuizContent } from "../../components/quiz";
import { QuizContent } from "../../components/quiz";
import { BROWSWER_PATH } from "../../constants/path";
import { Button, toast } from "../../design-system/components/common";
import {
Button,
CodeBlock,
toast,
} from "../../design-system/components/common";
import typography from "../../design-system/tokens/typography";
import { isString } from "../../utils/typeGuard";

import * as styles from "./slug.css";
Expand Down Expand Up @@ -77,7 +82,10 @@ export default function AnswerSharePage() {
<section className={styles.answerContainer}>
<h2 className={styles.h2}>공유된 답안</h2>
<hr className={styles.hr} />
<AnswerCodeBlock answer={answer} />
<CodeBlock
code={answer}
className={typography.$semantic.body2Regular}
/>
</section>
</main>
);
Expand Down

0 comments on commit 0fddb8d

Please sign in to comment.