Skip to content

Commit 5d9e97d

Browse files
authored
refactor: JDS Code 컴포넌트 vanilla-extract 마이그레이션 (#438)
* rename: Code.types.ts → code.types.ts 파일명 변경 * refactor: Code 컴포넌트 VE 마이그레이션 * docs: Code 스토리 description 문구 수정 * refactor: code.css.ts의 vars import를 상대 경로로 변경 * refactor: code recipe의 defaultVariants 제거 * style: code.css.ts import 순서 정리 * refactor: Code 컴포넌트에 ref 전달 지원 * refactor: Code import 정리
1 parent 607210f commit 5d9e97d

7 files changed

Lines changed: 51 additions & 67 deletions

File tree

packages/jds/src/components/Code/Code.stories.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ const meta: Meta<typeof Code> = {
1313
docs: {
1414
description: {
1515
component:
16-
"인라인 코드는 문장 흐름 안에서 특정 키워드, 값, 명령어, 짧은 코드 조각을 시각적으로 구분하기 위한 텍스트 컴포넌트입니다. 주요 내용의 이해를 보조하는 용도로, 문장을 끊지 않고 맥락 속에서 코드를 인지할 수 있도록 합니다.",
16+
"코드는 문장 흐름 안에서 키워드, 값, 명령어, 짧은 코드 조각을 시각적으로 구분하는 텍스트 컴포넌트입니다. 본문을 끊지 않고도 코드 요소를 맥락 속에서 인지하게 합니다. 설명 문맥을 유지하면서 특정 표현을 정확히 지목할 때 사용합니다.",
1717
},
1818
},
1919
},

packages/jds/src/components/Code/Code.styles.ts

Lines changed: 0 additions & 44 deletions
This file was deleted.
Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
1-
import { StyledCode } from "./Code.styles";
2-
import type { CodeProps } from "./Code.types";
1+
import { clsx } from "clsx";
2+
import { forwardRef } from "react";
33

4-
export const Code = ({ children, size = "md", className, ...restProps }: CodeProps) => {
5-
return (
6-
<StyledCode $size={size} className={className} {...restProps}>
7-
{children}
8-
</StyledCode>
9-
);
10-
};
4+
import * as styles from "./code.css";
5+
import type { CodeProps } from "./code.types";
6+
7+
export const Code = forwardRef<HTMLElement, CodeProps>(
8+
({ children, size = "md", className, ...restProps }, ref) => {
9+
return (
10+
<code ref={ref} className={clsx(styles.code({ size }), className)} {...restProps}>
11+
{children}
12+
</code>
13+
);
14+
},
15+
);
1116

1217
Code.displayName = "Code";

packages/jds/src/components/Code/Code.types.ts

Lines changed: 0 additions & 12 deletions
This file was deleted.
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { recipe } from "@vanilla-extract/recipes";
2+
3+
import type { CodeSize } from "./code.types";
4+
import { vars } from "tokens";
5+
6+
export const codeTypographyClassName: Record<CodeSize, string> = {
7+
lg: "semantic-textStyle-syntax-lg",
8+
md: "semantic-textStyle-syntax-md",
9+
sm: "semantic-textStyle-syntax-sm",
10+
xs: "semantic-textStyle-syntax-xs",
11+
};
12+
13+
export const code = recipe({
14+
base: {
15+
display: "inline-flex",
16+
alignItems: "center",
17+
padding: `${vars.scheme.semantic.spacing["0"]} ${vars.scheme.semantic.spacing["6"]}`,
18+
borderRadius: vars.scheme.semantic.radius["4"],
19+
background: vars.color.semantic.fill.subtlest,
20+
border: `1px solid ${vars.color.semantic.stroke.alpha.assistive}`,
21+
color: vars.color.semantic.object.bold,
22+
cursor: "text",
23+
},
24+
variants: {
25+
size: codeTypographyClassName,
26+
},
27+
});
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import type { ComponentPropsWithoutRef, ReactNode } from "react";
2+
3+
export type CodeSize = "lg" | "md" | "sm" | "xs";
4+
5+
export interface CodeProps extends ComponentPropsWithoutRef<"code"> {
6+
children: ReactNode;
7+
size?: CodeSize;
8+
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
export * from "./Code";
2-
export * from "./Code.types";
2+
export * from "./code.types";

0 commit comments

Comments
 (0)