Skip to content

Commit

Permalink
feat: Add as option and pass through to ReactRenderer (#2213)
Browse files Browse the repository at this point in the history
* Add `as` option and pass through to ReactRenderer

* Fix type, oops

* type `as` as string
  • Loading branch information
jessicalc authored Dec 2, 2021
1 parent fa18ffe commit dedcf17
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions packages/react/src/ReactNodeViewRenderer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export interface ReactNodeViewRendererOptions extends NodeViewRendererOptions {
newDecorations: Decoration[],
updateProps: () => void,
}) => boolean) | null,
as?: string,
}

class ReactNodeView extends NodeView<React.FunctionComponent, Editor, ReactNodeViewRendererOptions> {
Expand Down Expand Up @@ -81,12 +82,15 @@ class ReactNodeView extends NodeView<React.FunctionComponent, Editor, ReactNodeV
this.contentDOMElement.style.whiteSpace = 'inherit'
}

let as = this.node.isInline ? 'span' : 'div'
if (this.options.as) {
as = this.options.as
}

this.renderer = new ReactRenderer(ReactNodeViewProvider, {
editor: this.editor,
props,
as: this.node.isInline
? 'span'
: 'div',
as,
className: `node-${this.node.type.name}`,
})
}
Expand Down

0 comments on commit dedcf17

Please sign in to comment.