feat: add className option to ReactRenderer, see #2166

This commit is contained in:
Philipp Kühn 2021-11-18 09:58:38 +01:00
parent abe932384c
commit c9dc1e1ec3
2 changed files with 13 additions and 1 deletions

View File

@ -87,6 +87,7 @@ class ReactNodeView extends NodeView<React.FunctionComponent, Editor, ReactNodeV
as: this.node.isInline
? 'span'
: 'div',
className: `node-${this.node.type.name}`,
})
}

View File

@ -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()
}