Skip to content

Commit fc5ab2d

Browse files
committed
refactor: 폴더 구조 개선, Typography, RichText migration
1 parent 8ceec36 commit fc5ab2d

File tree

18 files changed

+285
-247
lines changed

18 files changed

+285
-247
lines changed

packages/notion-to-jsx/src/components/Renderer/components/Block/BlockRenderer.tsx

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {
44
MemoizedRichText,
55
MemoizedImage,
66
MemoizedBookmark,
7-
} from '../../../MemoizedComponents';
7+
} from '../MemoizedComponents';
88
import { CodeBlock } from '../Code';
99
import { Heading1, Heading2, Heading3, Paragraph } from '../Typography';
1010
import { BookmarkCard, BookmarkLink, ImageWrapper } from '../Media';
@@ -67,44 +67,44 @@ const BlockRenderer: React.FC<Props> = ({ block, onFocus, index }) => {
6767
</div>
6868
);
6969

70-
case 'code':
71-
return (
72-
<div {...blockProps}>
73-
<CodeBlock
74-
code={block.code.rich_text[0].text.content}
75-
language={block.code.language}
76-
caption={block.code.caption?.[0]?.plain_text}
77-
/>
78-
</div>
79-
);
70+
// case 'code':
71+
// return (
72+
// <div {...blockProps}>
73+
// <CodeBlock
74+
// code={block.code.rich_text[0].text.content}
75+
// language={block.code.language}
76+
// caption={block.code.caption?.[0]?.plain_text}
77+
// />
78+
// </div>
79+
// );
8080

81-
case 'image':
82-
return (
83-
<ImageWrapper {...blockProps}>
84-
<MemoizedImage
85-
src={block.image.file?.url || block.image.external?.url}
86-
alt={block.image.caption?.[0]?.plain_text || ''}
87-
/>
88-
{block.image.caption && (
89-
<figcaption>
90-
<MemoizedRichText richTexts={block.image.caption} />
91-
</figcaption>
92-
)}
93-
</ImageWrapper>
94-
);
81+
// case 'image':
82+
// return (
83+
// <ImageWrapper {...blockProps}>
84+
// <MemoizedImage
85+
// src={block.image.file?.url || block.image.external?.url}
86+
// alt={block.image.caption?.[0]?.plain_text || ''}
87+
// />
88+
// {block.image.caption && (
89+
// <figcaption>
90+
// <MemoizedRichText richTexts={block.image.caption} />
91+
// </figcaption>
92+
// )}
93+
// </ImageWrapper>
94+
// );
9595

96-
case 'bookmark':
97-
return (
98-
<BookmarkCard {...blockProps}>
99-
<BookmarkLink
100-
href={block.bookmark.url}
101-
target="_blank"
102-
rel="noopener noreferrer"
103-
>
104-
<MemoizedBookmark url={block.bookmark.url} />
105-
</BookmarkLink>
106-
</BookmarkCard>
107-
);
96+
// case 'bookmark':
97+
// return (
98+
// <BookmarkCard {...blockProps}>
99+
// <BookmarkLink
100+
// href={block.bookmark.url}
101+
// target="_blank"
102+
// rel="noopener noreferrer"
103+
// >
104+
// <MemoizedBookmark url={block.bookmark.url} />
105+
// </BookmarkLink>
106+
// </BookmarkCard>
107+
// );
108108

109109
default:
110110
return null;

packages/notion-to-jsx/src/components/Bookmark.tsx renamed to packages/notion-to-jsx/src/components/Renderer/components/Bookmark/Bookmark.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React, { useState, useEffect } from 'react';
22
import styled from 'styled-components';
3-
import { type RichTextItem } from '../types';
4-
import RichTexts from './RichTexts';
3+
import { type RichTextItem } from '../../../../types';
4+
import RichTexts from '../RichText/RichTexts';
55

66
interface OpenGraphData {
77
title: string;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { default as Bookmark } from './Bookmark';

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import 'prismjs/components/prism-javascript';
66
import 'prismjs/components/prism-jsx';
77
import 'prismjs/components/prism-tsx';
88

9-
import { MemoizedRichText } from '../../../MemoizedComponents';
9+
import { MemoizedRichText } from '../MemoizedComponents';
1010
import { CodeBlockWrapper } from './styles';
1111
import { RichTextItem } from '../../../../types';
1212
import { Caption } from '../Media';

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React, { useState, useEffect } from 'react';
22
import styled from 'styled-components';
3-
import { RichTextItem } from '../types';
4-
import RichTexts from './RichTexts';
3+
import { RichTextItem } from '../../../../types';
4+
import RichTexts from '../RichText/RichTexts';
55

66
export interface ImageProps {
77
src: string;
@@ -46,7 +46,7 @@ const Caption = styled.figcaption`
4646
font-size: ${({ theme }) => theme.typography.fontSize.small};
4747
`;
4848

49-
export const Image: React.FC<ImageProps> = ({
49+
const Image: React.FC<ImageProps> = ({
5050
src,
5151
alt,
5252
caption,
@@ -82,3 +82,5 @@ export const Image: React.FC<ImageProps> = ({
8282
</figure>
8383
);
8484
};
85+
86+
export default Image;
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export { default as Image } from './Image';
2+
export type { ImageProps } from './Image';

packages/notion-to-jsx/src/components/MemoizedComponents.tsx renamed to packages/notion-to-jsx/src/components/Renderer/components/MemoizedComponents.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import React from 'react';
2-
import RichText, { RichTextProps } from './RichTexts';
2+
import RichText, { RichTextProps } from './RichText/RichTexts';
33
import { Image, ImageProps } from './Image';
4-
import Bookmark, { type BookmarkProps } from './Bookmark';
5-
import { RichTextItem } from '../types';
4+
import Bookmark, { type BookmarkProps } from './Bookmark/Bookmark';
5+
import { RichTextItem } from '../../../types';
66

77
export const MemoizedRichText = React.memo<RichTextProps>(
88
RichText,
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import React from 'react';
2+
import { RichTextItem } from '../../../../types';
3+
import { richText, link } from './styles.css';
4+
5+
export interface RichTextProps {
6+
richTexts: RichTextItem[];
7+
}
8+
9+
const RichTexts: React.FC<RichTextProps> = ({ richTexts }) => {
10+
return (
11+
<>
12+
{richTexts.map((text, index) => {
13+
const { bold, italic, strikethrough, underline, code, color } =
14+
text.annotations;
15+
16+
const content = text.text.link ? (
17+
<a
18+
href={text.text.link}
19+
target="_blank"
20+
rel="noopener noreferrer"
21+
className={link}
22+
>
23+
{text.text.content}
24+
</a>
25+
) : (
26+
text.text.content
27+
);
28+
29+
const colorValue =
30+
color === 'default'
31+
? 'inherit'
32+
: color?.includes('_background')
33+
? `var(--notion-${color})`
34+
: `var(--notion-${color})`;
35+
36+
return (
37+
<span
38+
key={index}
39+
className={richText({
40+
bold,
41+
italic,
42+
strikethrough,
43+
underline,
44+
code,
45+
})}
46+
style={{ color: colorValue }}
47+
>
48+
{content}
49+
</span>
50+
);
51+
})}
52+
</>
53+
);
54+
};
55+
56+
export default RichTexts;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { default as RichTexts } from './RichTexts';
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import { style } from '@vanilla-extract/css';
2+
import { recipe } from '@vanilla-extract/recipes';
3+
import { vars } from '../../../../styles/theme.css';
4+
5+
export const richText = recipe({
6+
base: {
7+
fontFamily: 'inherit',
8+
},
9+
10+
variants: {
11+
bold: {
12+
true: {
13+
fontWeight: 'bold',
14+
},
15+
},
16+
italic: {
17+
true: {
18+
fontStyle: 'italic',
19+
},
20+
},
21+
strikethrough: {
22+
true: {
23+
textDecoration: 'line-through',
24+
},
25+
},
26+
underline: {
27+
true: {
28+
textDecoration: 'underline',
29+
},
30+
},
31+
code: {
32+
true: {
33+
background: vars.colors.code.background,
34+
padding: '0.2em 0.4em',
35+
borderRadius: vars.borderRadius.sm,
36+
fontFamily: vars.typography.fontFamily.code,
37+
fontSize: '0.85em',
38+
},
39+
},
40+
},
41+
42+
compoundVariants: [
43+
{
44+
variants: {
45+
strikethrough: true,
46+
underline: true,
47+
},
48+
style: {
49+
textDecoration: 'line-through underline',
50+
},
51+
},
52+
],
53+
});
54+
55+
export const link = style({
56+
color: 'inherit',
57+
textDecoration: 'underline',
58+
});

0 commit comments

Comments
 (0)