feat: add className option to ReactRenderer, see #2166
This commit is contained in:
@@ -87,6 +87,7 @@ class ReactNodeView extends NodeView<React.FunctionComponent, Editor, ReactNodeV
|
|||||||
as: this.node.isInline
|
as: this.node.isInline
|
||||||
? 'span'
|
? 'span'
|
||||||
: 'div',
|
: 'div',
|
||||||
|
className: `node-${this.node.type.name}`,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ export interface ReactRendererOptions {
|
|||||||
editor: Editor,
|
editor: Editor,
|
||||||
props?: Record<string, any>,
|
props?: Record<string, any>,
|
||||||
as?: string,
|
as?: string,
|
||||||
|
className?: string,
|
||||||
}
|
}
|
||||||
|
|
||||||
type ComponentType<R> =
|
type ComponentType<R> =
|
||||||
@@ -43,13 +44,23 @@ export class ReactRenderer<R = unknown> {
|
|||||||
|
|
||||||
ref: R | null = null
|
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.id = Math.floor(Math.random() * 0xFFFFFFFF).toString()
|
||||||
this.component = component
|
this.component = component
|
||||||
this.editor = editor as ExtendedEditor
|
this.editor = editor as ExtendedEditor
|
||||||
this.props = props
|
this.props = props
|
||||||
this.element = document.createElement(as)
|
this.element = document.createElement(as)
|
||||||
this.element.classList.add('react-renderer')
|
this.element.classList.add('react-renderer')
|
||||||
|
|
||||||
|
if (className) {
|
||||||
|
this.element.classList.add(...className.split(' '))
|
||||||
|
}
|
||||||
|
|
||||||
this.render()
|
this.render()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user