Skip to content

Commit

Permalink
fix type collision
Browse files Browse the repository at this point in the history
  • Loading branch information
SupaJoon committed Apr 12, 2024
1 parent 323771c commit f56f734
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion apps/parsley/src/utils/highlightHtml/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export const highlightHtml = (

const highlightedHtml = renderHtml(highlightedText, {
preserveAttributes: ["mark"],
transform: {
transformMap: {
mark: Highlight as unknown as React.ReactNode,
},
});
Expand Down
8 changes: 4 additions & 4 deletions apps/parsley/src/utils/renderHtml/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { escapeTags } from "utils/escapeTags";

interface renderHtmlOptions extends HTMLReactParserOptions {
preserveAttributes?: string[];
transform?: {
transformMap?: {
[key: string]: React.ReactNode;
};
}
Expand All @@ -29,8 +29,8 @@ const renderHtml = (html: string = "", options: renderHtmlOptions = {}) => {
return parse(escapedHtml, {
replace: (domNode) => {
if (domNode instanceof Element) {
if (options.transform && options.transform[domNode.name]) {
const SwapComponent = options.transform[domNode.name];
if (options.transform && options.transformMap?.[domNode.name]) {
const SwapComponent = options.transformMap[domNode.name];
// SwapComponent is just what ever component we want to return from the transform object
const extraProps =
options.preserveAttributes &&
Expand All @@ -41,7 +41,7 @@ const renderHtml = (html: string = "", options: renderHtmlOptions = {}) => {
return (
// @ts-expect-error
<SwapComponent className={extraProps.class} {...extraProps}>
{domToReact(domNode.children)}
{domToReact(domNode.children as Element[])}
</SwapComponent>
);
}
Expand Down
2 changes: 1 addition & 1 deletion apps/parsley/src/utils/renderHtml/renderHtml.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ describe("renderHtml", () => {
<>
{renderHtml("test <span data-cy='element'>string</span>", {
// @ts-expect-error - This is expecting a react component but its an Emotion component which are virtually the same thing
transform: { span: Component },
transformMap: { span: Component },
})}
</>,
);
Expand Down

0 comments on commit f56f734

Please sign in to comment.