summaryrefslogtreecommitdiff
path: root/src/components/rich-text/index.tsx
blob: 556942c088dcbdc4908455652deb652f217179d6 (plain)
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import { cn } from '@/lib/utils'
import React from 'react'
import { serializeLexical } from './serialize'

type Props = {
  className?: string
  content: Record<string, unknown>
  enableProse?: boolean
}

export function RichText({
  className,
  content,
  enableProse = true,
}: Props) {
  if (!content) {
    return null
  }

  return (
    <div
      className={cn(
        {
          'prose min-w-0 dark:prose-invert': enableProse,
        },
        className
      )}
    >
      {content &&
        !Array.isArray(content) &&
        typeof content === 'object' &&
        'root' in content &&
        serializeLexical({
          nodes: (content.root as { children: unknown[] })?.children as Parameters<
            typeof serializeLexical
          >[0]['nodes'],
        })}
    </div>
  )
}

export default RichText