fix: add React.ElementType type to SessionHTMLRenderer and rename tag prop to as

pull/3206/head
Ryan Miller 1 year ago
parent 0382d4f0dc
commit c8a19c1664

@ -42,7 +42,7 @@ export const I18n = <T extends LocalizerToken>(props: I18nProps<T>) => {
/** If the string contains a relevant formatting tag, render it as HTML */ /** If the string contains a relevant formatting tag, render it as HTML */
if (i18nString.match(formattingTagRegex)) { if (i18nString.match(formattingTagRegex)) {
return <SessionHtmlRenderer tag={props.as} html={i18nString} />; return <SessionHtmlRenderer as={props.as} html={i18nString} />;
} }
const Comp = props.as ?? React.Fragment; const Comp = props.as ?? React.Fragment;

@ -1,20 +1,20 @@
import React from 'react';
import DOMPurify from 'dompurify'; import DOMPurify from 'dompurify';
import React from 'react';
type ReceivedProps = { type ReceivedProps = {
html: string; html: string;
tag?: string; as?: React.ElementType;
key?: any; key?: any;
className?: string; className?: string;
}; };
export const SessionHtmlRenderer = ({ tag = 'div', key, html, className }: ReceivedProps) => { export const SessionHtmlRenderer = ({ as = 'div', key, html, className }: ReceivedProps) => {
const clean = DOMPurify.sanitize(html, { const clean = DOMPurify.sanitize(html, {
USE_PROFILES: { html: true }, USE_PROFILES: { html: true },
FORBID_ATTR: ['script'], FORBID_ATTR: ['script'],
}); });
return React.createElement(tag, { return React.createElement(as, {
key, key,
className, className,

Loading…
Cancel
Save