Skip to content

Commit

Permalink
fix: change element to data, and output the RenderNodeProps type
Browse files Browse the repository at this point in the history
  • Loading branch information
thebuilder committed May 5, 2024
1 parent 6a2939a commit 6946b1e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
11 changes: 8 additions & 3 deletions src/UmbracoRichText.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,11 @@ interface NodeMeta {
next?: string;
}

type RenderNodeProps = {
/**
* Props for rendering a single node in the rich text.
* A node is any HTML element that is part of the rich text.
*/
export type RenderNodeProps = {
children?: React.ReactNode;
meta: NodeMeta;
} & (
Expand All @@ -74,10 +78,11 @@ type RenderNodeProps = {
);

interface RichTextProps {
element:
data:
| {
/** List as `string` so it matches generated type from Umbraco. In reality, the value of the root `tag` must be `#root` */
tag: string;
attributes?: Record<string, unknown>;
elements?: RichTextElementModel[];
blocks?: Array<BlockItemModel>;
}
Expand Down Expand Up @@ -214,7 +219,7 @@ function RichTextElement({
* Component for rendering a rich text component
*/
export function UmbracoRichText(props: RichTextProps) {
const rootElement = props.element;
const rootElement = props.data;
if (rootElement?.tag === "#root" && rootElement.elements) {
return (
<>
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export { UmbracoRichText } from "./UmbracoRichText";
export type { UmbracoBlockItemModel } from "./UmbracoRichText";
export type { UmbracoBlockItemModel, RenderNodeProps } from "./UmbracoRichText";

0 comments on commit 6946b1e

Please sign in to comment.