An opinionated toast component for React.
Remove dom purify to reduce bundle size (#439)
Emil Kowalskibb37103d532d
diff --git a/package.json b/package.jsonindex 63debd7..b1d75a0 100644--- a/package.json+++ b/package.json@@ -41,7 +41,6 @@"@types/dompurify": "^3.0.5","@types/node": "^18.11.13","@types/react": "^18.0.26",- "dompurify": "^3.0.9","prettier": "^2.8.4","react": "^18.2.0","react-dom": "^18.2.0",diff --git a/pnpm-lock.yaml b/pnpm-lock.yamlindex 01ded3f..86dc7c3 100644--- a/pnpm-lock.yaml+++ b/pnpm-lock.yaml@@ -20,9 +20,6 @@ importers:'@types/react':specifier: ^18.0.26version: 18.2.0- dompurify:- specifier: ^3.0.9- version: 3.0.10prettier:specifier: ^2.8.4version: 2.8.8@@ -1929,6 +1926,7 @@ packages:resolution: {integrity: sha512-WZDL8ZHTliEVP3Lk4phtvjg8SNQ3YMc5WVstxE8cszKZrFjzI4PF4ZTIk9VGAc9vZADO7uGO2V/ZiStcRSAT4Q==}+ dev: falseresolution: {integrity: sha512-I88TYZWc9XiYHRQ4/3c5rjjfgkjhLyW2luGIheGERbNQ6OY7yTybanSpDXZa8y7VUP9YmDcYa+eyq4ca7iLqWA==}diff --git a/src/index.tsx b/src/index.tsxindex fa76ce3..a63e10a 100644--- a/src/index.tsx+++ b/src/index.tsx@@ -3,7 +3,6 @@import React from 'react';import ReactDOM from 'react-dom';-import DOMPurify from 'dompurify';import { getAsset, Loader } from './assets';import { useIsDocumentHidden } from './hooks';import { toast, ToastState } from './state';@@ -250,10 +249,6 @@ const Toast = (props: ToastProps) => {return <Loader visible={toastType === 'loading'} />;}- function sanitizeHTML(html: string): { __html: string } {- return { __html: DOMPurify.sanitize(html) };- }-return (<liaria-live={toast.important ? 'assertive' : 'polite'}@@ -391,11 +386,9 @@ const Toast = (props: ToastProps) => {) : null}<div data-content="" className={cn(classNames?.content, toast?.classNames?.content)}>- <div- data-title=""- className={cn(classNames?.title, toast?.classNames?.title)}- dangerouslySetInnerHTML={sanitizeHTML(toast.title as string)}- ></div>+ <div data-title="" className={cn(classNames?.title, toast?.classNames?.title)}>+ {toast.title}+ </div>{toast.description ? (<divdata-description=""@@ -404,12 +397,9 @@ const Toast = (props: ToastProps) => {toastDescriptionClassname,classNames?.description,toast?.classNames?.description,- )}- dangerouslySetInnerHTML={- typeof toast.description === 'string' ? sanitizeHTML(toast.description as string) : undefined- }+ )}>- {typeof toast.description === 'object' ? toast.description : null}+ {toast.description}</div>) : null}</div>@@ -437,7 +427,7 @@ const Toast = (props: ToastProps) => {) : toast.action && isAction(toast.action) ? (<buttondata-button- data-action+ data-actionstyle={toast.actionButtonStyle || actionButtonStyle}onClick={(event) => {// We need to check twice because typescript