aboutsummaryrefslogtreecommitdiff
path: root/apps/web/components/new/document-modal/content/notion-doc.tsx
blob: 379c78af3feca0b02f98a8478df686d34a927858 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import React from "react"
import { Streamdown } from "streamdown"

const components = {
	p: ({ children, ...props }: React.ComponentPropsWithoutRef<"p">) => {
		const hasDiv = React.Children.toArray(children).some(
			(child) =>
				React.isValidElement(child) &&
				typeof child.type === "string" &&
				child.type === "div",
		)

		if (hasDiv) {
			return <div {...props}>{children}</div>
		}

		return <p {...props}>{children}</p>
	},
} as const

export function NotionDoc({ content }: { content: string }) {
	return (
		<div className="p-4 overflow-y-auto flex-1 scrollbar-thin">
			<Streamdown components={components}>{content}</Streamdown>
		</div>
	)
}