kcHeaderClass can be updated after initial mount
This commit is contained in:
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "keycloakify",
|
"name": "keycloakify",
|
||||||
"version": "0.3.0",
|
"version": "0.3.1",
|
||||||
"description": "Keycloak theme generator for Reacts app",
|
"description": "Keycloak theme generator for Reacts app",
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
|
@ -86,6 +86,7 @@ export const Template = memo((props: TemplateProps) => {
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|
||||||
let isUnmounted = false;
|
let isUnmounted = false;
|
||||||
|
const cleanups: (() => void)[] = [];
|
||||||
|
|
||||||
const toArr = (x: string | readonly string[] | undefined) =>
|
const toArr = (x: string | readonly string[] | undefined) =>
|
||||||
typeof x === "string" ? x.split(" ") : x ?? [];
|
typeof x === "string" ? x.split(" ") : x ?? [];
|
||||||
@ -116,15 +117,27 @@ export const Template = memo((props: TemplateProps) => {
|
|||||||
|
|
||||||
if (props.kcHtmlClass !== undefined) {
|
if (props.kcHtmlClass !== undefined) {
|
||||||
|
|
||||||
|
const htmlClassList =
|
||||||
document.getElementsByTagName("html")[0]
|
document.getElementsByTagName("html")[0]
|
||||||
.classList
|
.classList;
|
||||||
.add(...cx(props.kcHtmlClass).split(" "));
|
|
||||||
|
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) {
|
if (!isExtraCssLoaded) {
|
||||||
return null;
|
return null;
|
||||||
|
Reference in New Issue
Block a user