Skip to content

Commit 0b709b9

Browse files
committed
refactor: components to use TypeScript types and remove React imports
1 parent c2cbc62 commit 0b709b9

File tree

15 files changed

+60
-87
lines changed

15 files changed

+60
-87
lines changed

packages/notion-to-jsx/src/components/Renderer/components/Code/CodeBlock.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useMemo } from 'react';
1+
import { ReactNode, useMemo } from 'react';
22
import { codeBlock } from './styles.css';
33
import Prism, { Grammar, Token } from 'prismjs';
44
import { MemoizedRichText } from '../MemoizedComponents';
@@ -12,13 +12,13 @@ if (typeof window !== 'undefined') {
1212
window.Prism = Prism;
1313
}
1414

15-
const renderToken = (token: string | Token, i: number): React.ReactNode => {
15+
const renderToken = (token: string | Token, i: number): ReactNode => {
1616
if (typeof token === 'string') {
1717
return <span key={i}>{token}</span>;
1818
}
1919

2020
const content = token.content;
21-
let tokenContent: React.ReactNode;
21+
let tokenContent: ReactNode;
2222

2323
if (Array.isArray(content)) {
2424
tokenContent = content.map((subToken, j) => renderToken(subToken, j));

packages/notion-to-jsx/src/components/Renderer/components/Column/Column.tsx

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,18 @@
1-
import React from 'react';
1+
import { ColumnBlock } from '../../../../types';
22
import BlockRenderer from '../Block/BlockRenderer';
33
import { columnContainer } from './styles.css';
44

55
export interface ColumnProps {
6-
block: any;
7-
onFocus?: () => void;
6+
block: ColumnBlock;
87
}
98

10-
const Column: React.FC<ColumnProps> = ({ block, onFocus }) => {
9+
const Column = ({ block }: ColumnProps) => {
1110
if (!block || !block.children) return null;
1211

1312
return (
1413
<div className={columnContainer}>
15-
{block.children.map((childBlock: any, index: number) => (
16-
<BlockRenderer
17-
key={childBlock.id}
18-
block={childBlock}
19-
onFocus={onFocus}
20-
index={index}
21-
isColumn
22-
/>
14+
{block.children.map((childBlock) => (
15+
<BlockRenderer key={childBlock.id} block={childBlock} isColumn />
2316
))}
2417
</div>
2518
);

packages/notion-to-jsx/src/components/Renderer/components/Column/ColumnList.tsx

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,18 @@
1-
import React from 'react';
21
import Column from './Column';
32
import { columnListContainer } from './styles.css';
3+
import { ColumnListBlock } from '../../../../types';
44

55
export interface ColumnListProps {
6-
block: any;
7-
onFocus?: () => void;
6+
block: ColumnListBlock;
87
}
98

10-
const ColumnList: React.FC<ColumnListProps> = ({ block, onFocus }) => {
9+
const ColumnList = ({ block }: ColumnListProps) => {
1110
if (!block || !block.children) return null;
1211

1312
return (
1413
<div className={columnListContainer}>
15-
{block.children.map((column: any) => (
16-
<Column key={column.id} block={column} onFocus={onFocus} />
14+
{block.children.map((column) => (
15+
<Column key={column.id} block={column} />
1716
))}
1817
</div>
1918
);

packages/notion-to-jsx/src/components/Renderer/components/Image/Image.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useState } from 'react';
1+
import { useState } from 'react';
22
import { MemoizedRichText } from '../MemoizedComponents';
33
import {
44
imageContainer,

packages/notion-to-jsx/src/components/Renderer/components/LinkPreview/LinkPreview.tsx

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
1-
import React, { useState, useEffect } from 'react';
1+
import { useState, useEffect } from 'react';
22
import * as styles from './styles.css';
33

4-
export interface LinkPreviewProps {
5-
url: string;
6-
}
7-
84
interface RepoData {
95
name: string;
106
full_name: string;
@@ -172,7 +168,10 @@ const formatUpdatedTime = (dateString: string): string => {
172168
}
173169
};
174170

175-
const LinkPreview: React.FC<LinkPreviewProps> = ({ url }) => {
171+
export interface LinkPreviewProps {
172+
url: string;
173+
}
174+
const LinkPreview = ({ url }: LinkPreviewProps) => {
176175
const [repoData, setRepoData] = useState<RepoData | null>(null);
177176
const [figmaData, setFigmaData] = useState<FigmaData | null>(null);
178177
const [loading, setLoading] = useState(true);

packages/notion-to-jsx/src/components/Renderer/components/List/ListBlocksRenderer.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import React from 'react';
21
import { List, ListItem } from './List';
32
import { MemoizedRichText } from '../MemoizedComponents';
43
import {

packages/notion-to-jsx/src/components/Renderer/components/Quote/Quote.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
1-
import React from 'react';
21
import { MemoizedRichText } from '../MemoizedComponents';
32
import { container } from './styles.css';
43
import { RichTextItem } from '../RichText/RichTexts';
5-
import { richText } from '../RichText/styles.css';
64

75
export interface QuoteProps {
86
richTexts: RichTextItem[];
97
tabIndex?: number;
108
}
119

12-
const Quote: React.FC<QuoteProps> = ({ richTexts, tabIndex }) => {
10+
const Quote = ({ richTexts, tabIndex }: QuoteProps) => {
1311
return (
1412
<blockquote className={container} tabIndex={tabIndex}>
1513
<MemoizedRichText richTexts={richTexts} />

packages/notion-to-jsx/src/components/Renderer/components/RichText/RichTexts.tsx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React from 'react';
1+
import { ReactNode } from 'react';
22
import { richText, link } from './styles.css';
33

44
// 지원하는 Notion 색상 타입 정의
@@ -50,20 +50,20 @@ export interface RichTextItem {
5050
};
5151
}
5252

53-
export interface RichTextProps {
54-
richTexts: RichTextItem[];
55-
}
56-
5753
/**
5854
* 링크 컴포넌트를 생성하는 함수
5955
*/
60-
const renderLink = (href: string, content: React.ReactNode) => (
56+
const renderLink = (href: string, content: ReactNode) => (
6157
<a href={href} target="_blank" rel="noopener noreferrer" className={link}>
6258
{content}
6359
</a>
6460
);
6561

66-
const RichTexts: React.FC<RichTextProps> = ({ richTexts }) => {
62+
export interface RichTextProps {
63+
richTexts: RichTextItem[];
64+
}
65+
66+
const RichTexts = ({ richTexts }: RichTextProps) => {
6767
return (
6868
<>
6969
{richTexts.map((text, index) => {

packages/notion-to-jsx/src/components/Renderer/components/Table/Table.tsx

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,23 @@
1-
import React from 'react';
2-
import { tableContainer, table, headerCell, hasRowHeader } from './styles.css';
1+
import { tableContainer, table, headerCell } from './styles.css';
32
import TableRow from './TableRow';
4-
import { NotionBlock } from '../../../../types';
3+
import { TableBlock } from '../../../../types';
54

65
interface TableProps {
7-
block: NotionBlock;
8-
tabIndex?: number;
6+
block: TableBlock;
97
}
108

11-
const Table: React.FC<TableProps> = ({ block, tabIndex = 0 }) => {
9+
const Table = ({ block }: TableProps) => {
1210
if (!block.table || !block.children) {
1311
return null;
1412
}
1513

1614
const { table_width, has_column_header, has_row_header } = block.table;
1715
const rows =
18-
block.children?.filter(
19-
(child: NotionBlock) => child.type === 'table_row'
20-
) || [];
16+
block.children?.filter((child) => child.type === 'table_row') || [];
2117

2218
return (
2319
<div className={tableContainer}>
24-
<table className={table} tabIndex={tabIndex}>
20+
<table className={table}>
2521
{rows.length > 0 && (
2622
<>
2723
{has_column_header && rows[0] && (
@@ -32,20 +28,13 @@ const Table: React.FC<TableProps> = ({ block, tabIndex = 0 }) => {
3228
<tbody>
3329
{/* 유효한 row만 매핑하도록 필터링 추가 */}
3430
{rows
35-
.filter(
36-
(row): row is NotionBlock =>
37-
row !== undefined && row.type === 'table_row'
38-
)
39-
.map((row: NotionBlock, rowIndex: number) => {
31+
.filter((row) => row !== undefined && row.type === 'table_row')
32+
.map((row, rowIndex: number) => {
4033
// 열 헤더가 있고 첫 번째 행이면 이미 thead에서 렌더링되었으므로 건너뜁니다
4134
if (has_column_header && rowIndex === 0) {
4235
return null;
4336
}
4437

45-
const actualRowIndex = has_column_header
46-
? rowIndex - 1
47-
: rowIndex;
48-
// 타입 체크를 통해 row가 실제 Block 타입임을 확인합니다
4938
return (
5039
<TableRow
5140
key={row.id}

packages/notion-to-jsx/src/components/Renderer/components/Table/TableRow.tsx

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
1-
import React from 'react';
21
import { tableCell, firstCell, lastCell, hasRowHeader } from './styles.css';
32
import { MemoizedRichText } from '../MemoizedComponents';
4-
import { NotionBlock } from '../../../../types';
3+
import { TableRowBlock } from '../../../../types';
54
import { RichTextItem } from '../RichText/RichTexts';
65

76
interface TableRowProps {
8-
rowBlock: NotionBlock;
7+
rowBlock: TableRowBlock;
98
cellClassName?: string;
109
rowHeaderIndex?: number;
1110
}
1211

13-
const TableRow: React.FC<TableRowProps> = ({
12+
const TableRow = ({
1413
rowBlock,
1514
cellClassName = '',
1615
rowHeaderIndex = -1,
17-
}) => {
16+
}: TableRowProps) => {
1817
if (!rowBlock.table_row?.cells) {
1918
return null;
2019
}

0 commit comments

Comments
 (0)