Skip to content

Commit 1ed56ba

Browse files
committed
refactor: List migrate
1 parent b6aea68 commit 1ed56ba

File tree

6 files changed

+96
-45
lines changed

6 files changed

+96
-45
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import React from 'react';
2+
import { list, listItem } from './styles.css';
3+
4+
interface ListProps
5+
extends React.HTMLAttributes<HTMLUListElement | HTMLOListElement> {
6+
as?: 'ul' | 'ol';
7+
type: 'bulleted' | 'numbered';
8+
children: React.ReactNode;
9+
}
10+
11+
export const List: React.FC<ListProps> = ({
12+
as: Component = 'ul',
13+
type,
14+
className,
15+
children,
16+
...props
17+
}) => {
18+
return (
19+
<Component className={list({ type })} {...props}>
20+
{children}
21+
</Component>
22+
);
23+
};
24+
25+
interface ListItemProps extends React.HTMLAttributes<HTMLLIElement> {
26+
children: React.ReactNode;
27+
}
28+
29+
export const ListItem: React.FC<ListItemProps> = ({
30+
className,
31+
children,
32+
...props
33+
}) => {
34+
return (
35+
<li className={listItem} {...props}>
36+
{children}
37+
</li>
38+
);
39+
};

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { BlockRenderer } from '../Block';
2-
import { List } from './styles';
2+
import { List } from './List';
33

44
export interface Props {
55
blocks: any[];
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1+
export { List, ListItem } from './List';
12
export { default as ListBlocksRenderer } from './ListBlocksRenderer';
2-
export * from './styles';
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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 list = recipe({
6+
base: {
7+
margin: `${vars.spacing.sm} 0`,
8+
paddingLeft: vars.spacing.xl,
9+
},
10+
variants: {
11+
type: {
12+
bulleted: {
13+
listStyleType: 'disc',
14+
},
15+
numbered: {
16+
listStyleType: 'decimal',
17+
},
18+
},
19+
},
20+
});
21+
22+
export const listItem = style({
23+
margin: `${vars.spacing.xs} 0`,
24+
});

packages/notion-to-jsx/src/components/Renderer/components/List/styles.ts

Lines changed: 0 additions & 11 deletions
This file was deleted.

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

Lines changed: 31 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { NotionBlock } from '../../types';
66
import testData from '../../constants/test.json';
77
import { useKeyboardNavigation } from '../../hooks/useKeyboardNavigation';
88
import { darkTheme, lightTheme } from '../../styles/theme.css';
9+
import { List } from './components/List';
910
// import { BlockRenderer } from './components/Block';
1011
// import { List, ListBlocksRenderer } from './components/List';
1112

@@ -65,22 +66,21 @@ export const Renderer: React.FC<Props> = React.memo(
6566
block.type === 'bulleted_list_item' &&
6667
(i === 0 || blocks[i - 1]?.type !== 'bulleted_list_item')
6768
) {
68-
result
69-
.push
70-
// <List
71-
// as="ul"
72-
// type="bulleted"
73-
// role="list"
74-
// aria-label="Bulleted list"
75-
// key={block.id}
76-
// >
77-
// <ListBlocksRenderer
78-
// blocks={blocks}
79-
// startIndex={i}
80-
// type="bulleted"
81-
// />
82-
// </List>
83-
();
69+
result.push(
70+
<List
71+
as="ul"
72+
type="bulleted"
73+
role="list"
74+
aria-label="Bulleted list"
75+
key={block.id}
76+
>
77+
{/* <ListBlocksRenderer
78+
blocks={blocks}
79+
startIndex={i}
80+
type="bulleted"
81+
/> */}
82+
</List>
83+
);
8484
while (
8585
i + 1 < blocks.length &&
8686
blocks[i + 1] &&
@@ -92,22 +92,21 @@ export const Renderer: React.FC<Props> = React.memo(
9292
block.type === 'numbered_list_item' &&
9393
(i === 0 || blocks[i - 1]?.type !== 'numbered_list_item')
9494
) {
95-
result
96-
.push
97-
// <List
98-
// as="ol"
99-
// type="1"
100-
// role="list"
101-
// aria-label="Numbered list"
102-
// key={block.id}
103-
// >
104-
// <ListBlocksRenderer
105-
// blocks={blocks}
106-
// startIndex={i}
107-
// type="numbered"
108-
// />
109-
// </List>
110-
();
95+
result.push(
96+
<List
97+
as="ol"
98+
type="1"
99+
role="list"
100+
aria-label="Numbered list"
101+
key={block.id}
102+
>
103+
{/* <ListBlocksRenderer
104+
blocks={blocks}
105+
startIndex={i}
106+
type="numbered"
107+
/> */}
108+
</List>
109+
);
111110
while (
112111
i + 1 < blocks.length &&
113112
blocks[i + 1] &&

0 commit comments

Comments
 (0)