-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathrich-text-provider.tsx
More file actions
66 lines (61 loc) · 1.77 KB
/
rich-text-provider.tsx
File metadata and controls
66 lines (61 loc) · 1.77 KB
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import type { Editor } from '@tiptap/react'
import {
EditorConsumer,
EditorContent,
EditorContext,
type EditorProviderProps,
useEditor,
} from '@tiptap/react'
import { cn } from '../../../../../src/react/utils/cn'
import { InputGroup, InputGroupControl } from '../../../primitives'
interface EditorProviderPropsWithEditor extends EditorProviderProps {
editor?: Editor | null
inputGroupProps?: {
isInvalid?: boolean
isDisabled?: boolean
isPending?: boolean
}
}
export function EditorProvider({
children,
slotAfter,
slotBefore,
editorContainerProps = {},
editor,
inputGroupProps,
...editorOptions
}: EditorProviderPropsWithEditor) {
const editorInstance = editor ?? useEditor(editorOptions)
if (!editorInstance) {
return null
}
return (
<EditorContext.Provider value={{ editor: editorInstance }}>
{slotBefore}
<EditorConsumer>
{() => (
<InputGroup
className="h-auto focus-within:border-ring focus-within:ring-ring/20 focus-within:ring-4"
aria-invalid={inputGroupProps?.isInvalid}
aria-disabled={inputGroupProps?.isDisabled}
isPending={inputGroupProps?.isPending}
>
<InputGroupControl>
<EditorContent
editor={editorInstance}
className={cn(
'!rounded-md min-h-[240px] max-h-[240px] bg-white w-full outline-none overflow-y-auto tiptap-content-editor',
editorContainerProps.className
)}
data-slot="input-group-control"
{...editorContainerProps}
/>
</InputGroupControl>
</InputGroup>
)}
</EditorConsumer>
{children}
{slotAfter}
</EditorContext.Provider>
)
}