mirror of
https://github.com/ueberdosis/tiptap.git
synced 2025-06-07 17:43:49 +08:00
feat: add className option to ReactRenderer, see #2166
This commit is contained in:
parent
abe932384c
commit
c9dc1e1ec3
@ -87,6 +87,7 @@ class ReactNodeView extends NodeView<React.FunctionComponent, Editor, ReactNodeV
|
||||
as: this.node.isInline
|
||||
? 'span'
|
||||
: 'div',
|
||||
className: `node-${this.node.type.name}`,
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -21,6 +21,7 @@ export interface ReactRendererOptions {
|
||||
editor: Editor,
|
||||
props?: Record<string, any>,
|
||||
as?: string,
|
||||
className?: string,
|
||||
}
|
||||
|
||||
type ComponentType<R> =
|
||||
@ -43,13 +44,23 @@ export class ReactRenderer<R = unknown> {
|
||||
|
||||
ref: R | null = null
|
||||
|
||||
constructor(component: ComponentType<R>, { editor, props = {}, as = 'div' }: ReactRendererOptions) {
|
||||
constructor(component: ComponentType<R>, {
|
||||
editor,
|
||||
props = {},
|
||||
as = 'div',
|
||||
className = '',
|
||||
}: ReactRendererOptions) {
|
||||
this.id = Math.floor(Math.random() * 0xFFFFFFFF).toString()
|
||||
this.component = component
|
||||
this.editor = editor as ExtendedEditor
|
||||
this.props = props
|
||||
this.element = document.createElement(as)
|
||||
this.element.classList.add('react-renderer')
|
||||
|
||||
if (className) {
|
||||
this.element.classList.add(...className.split(' '))
|
||||
}
|
||||
|
||||
this.render()
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user