Skip to content

Commit

Permalink
Fix renderers prop in document renderer (#4816)
Browse files Browse the repository at this point in the history
* Fix renderers prop in document renderer

* Update changeset
  • Loading branch information
emmatown authored Feb 12, 2021
1 parent e29ae27 commit a1266a1
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .changeset/purple-rules-film.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@keystone-next/document-renderer': patch
---

Fixed renderer prop to allow providing some of the renderers and exported `DocumentRendererProps` and `defaultRenderers`
15 changes: 10 additions & 5 deletions packages-next/document-renderer/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ interface Renderers {
};
}

const defaultRenderers: Renderers = {
export const defaultRenderers: Renderers = {
inline: {
bold: 'strong',
code: 'code',
Expand Down Expand Up @@ -221,16 +221,21 @@ function createComponentBlockProps(node: Element, children: ReactElement[]) {
return formProps;
}

type Props<ComponentBlocks> = {
export type DocumentRendererProps<
ComponentBlocks extends Record<string, Component<any>> = Record<string, Component<any>>
> = {
document: Element[];
renderers?: Partial<Renderers>;
renderers?: { inline?: Partial<Renderers['inline']>; block?: Partial<Renderers['block']> };
componentBlocks?: ComponentBlocks;
};

export function DocumentRenderer<ComponentBlocks extends Record<string, Component<any>>>(
props: Props<ComponentBlocks>
props: DocumentRendererProps<ComponentBlocks>
) {
const renderers = { ...defaultRenderers, ...props.renderers };
const renderers = {
inline: { ...props.renderers?.inline, ...defaultRenderers.inline },
block: { ...props.renderers?.block, ...defaultRenderers.block },
};
const componentBlocks = props.componentBlocks || {};
return (
<Fragment>
Expand Down

0 comments on commit a1266a1

Please sign in to comment.