kcHeaderClass can be updated after initial mount

This commit is contained in:
Joseph Garrone 2021-03-21 22:10:33 +01:00
parent 12f69b593f
commit 1606c2884d
2 changed files with 29 additions and 16 deletions

View File

@ -1,6 +1,6 @@
{
"name": "keycloakify",
"version": "0.3.0",
"version": "0.3.1",
"description": "Keycloak theme generator for Reacts app",
"repository": {
"type": "git",

View File

@ -86,6 +86,7 @@ export const Template = memo((props: TemplateProps) => {
useEffect(() => {
let isUnmounted = false;
const cleanups: (() => void)[] = [];
const toArr = (x: string | readonly string[] | undefined) =>
typeof x === "string" ? x.split(" ") : x ?? [];
@ -116,15 +117,27 @@ export const Template = memo((props: TemplateProps) => {
if (props.kcHtmlClass !== undefined) {
const htmlClassList =
document.getElementsByTagName("html")[0]
.classList
.add(...cx(props.kcHtmlClass).split(" "));
.classList;
const tokens = cx(props.kcHtmlClass).split(" ")
htmlClassList.add(...tokens);
cleanups.push(() => htmlClassList.remove(...tokens));
}
return () => { isUnmounted = true; };
return () => {
}, []);
isUnmounted = true;
cleanups.forEach(f => f());
};
}, [props.kcHeaderClass]);
if (!isExtraCssLoaded) {
return null;