Skip to content

Commit

Permalink
feat: add useInnerHtml checkbox option and dynamically show HTML content
Browse files Browse the repository at this point in the history
  • Loading branch information
Rob Dekker committed Dec 17, 2024
1 parent d5d1b3e commit 4328bba
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/components/alert.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
bodyText,
allowTextServerResponse,
allowTitleServerResponse,
useInnerHtml,
dataComponentAttribute,
} = options;
const title = useText(titleText);
Expand All @@ -23,6 +24,7 @@
const [open, setOpen] = useState(visible);
const [titleFromServer, setTitleFromServer] = useState('');
const [textFromServer, setTextFromServer] = useState('');
const alertBody = (allowTextServerResponse && textFromServer) || body;

useEffect(() => {
setOpen(visible);
Expand Down Expand Up @@ -125,7 +127,15 @@
: title}
</AlertTitle>
)}
{textFromServer && allowTextServerResponse ? textFromServer : body}
{useInnerHtml ? (
<div
className={classes.htmlContent}
// eslint-disable-next-line react/no-danger
dangerouslySetInnerHTML={{ __html: alertBody }}
/>
) : (
alertBody
)}
</Alert>
);
return isDev ? (
Expand Down Expand Up @@ -209,6 +219,11 @@
},
},
},
htmlContent: {
'& *': {
color: ({ options: { textColor } }) => style.getColor(textColor),
},
},
hide: {
display: 'none !important',
},
Expand Down
4 changes: 4 additions & 0 deletions src/prefabs/structures/Alert/options/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export const categories = [
'iconColor',
'background',
'borderColor',
'useInnerHtml',
],
},
{
Expand Down Expand Up @@ -77,6 +78,9 @@ export const alertOptions = {
borderColor: color('Border color', {
value: ThemeColor.TRANSPARENT,
}),
useInnerHtml: toggle('Display Rich Text', {
value: false,
}),
icon: icon('Icon', {
value: 'None',
}),
Expand Down

0 comments on commit 4328bba

Please sign in to comment.