kcHeaderClass can be updated after initial mount
This commit is contained in:
parent
12f69b593f
commit
1606c2884d
@ -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",
|
||||||
|
@ -25,7 +25,7 @@ export type TemplateProps = {
|
|||||||
showUsernameNode?: ReactNode;
|
showUsernameNode?: ReactNode;
|
||||||
formNode: ReactNode;
|
formNode: ReactNode;
|
||||||
infoNode?: ReactNode;
|
infoNode?: ReactNode;
|
||||||
} & { kcContext: KcContext.Template; } & KcTemplateProps;
|
} & { kcContext: KcContext.Template; } & KcTemplateProps;
|
||||||
|
|
||||||
|
|
||||||
export const Template = memo((props: TemplateProps) => {
|
export const Template = memo((props: TemplateProps) => {
|
||||||
@ -60,34 +60,35 @@ export const Template = memo((props: TemplateProps) => {
|
|||||||
);
|
);
|
||||||
|
|
||||||
const {
|
const {
|
||||||
realm, locale, auth,
|
realm, locale, auth,
|
||||||
url, message, isAppInitiatedAction
|
url, message, isAppInitiatedAction
|
||||||
}= kcContext;
|
} = kcContext;
|
||||||
|
|
||||||
useEffect(()=>{
|
useEffect(() => {
|
||||||
|
|
||||||
if( !realm.internationalizationEnabled ){
|
if (!realm.internationalizationEnabled) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
assert( locale !== undefined );
|
assert(locale !== undefined);
|
||||||
|
|
||||||
if( kcLanguageTag === getBestMatchAmongKcLanguageTag(locale.current) ){
|
if (kcLanguageTag === getBestMatchAmongKcLanguageTag(locale.current)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
window.location.href =
|
window.location.href =
|
||||||
locale.supported.find(({ languageTag }) => languageTag === kcLanguageTag)!.url;
|
locale.supported.find(({ languageTag }) => languageTag === kcLanguageTag)!.url;
|
||||||
|
|
||||||
},[kcLanguageTag]);
|
}, [kcLanguageTag]);
|
||||||
|
|
||||||
const [isExtraCssLoaded, setExtraCssLoaded] = useReducer(() => true, false);
|
const [isExtraCssLoaded, setExtraCssLoaded] = useReducer(() => true, false);
|
||||||
|
|
||||||
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 ?? [];
|
||||||
|
|
||||||
Promise.all(
|
Promise.all(
|
||||||
@ -116,15 +117,27 @@ export const Template = memo((props: TemplateProps) => {
|
|||||||
|
|
||||||
if (props.kcHtmlClass !== undefined) {
|
if (props.kcHtmlClass !== undefined) {
|
||||||
|
|
||||||
document.getElementsByTagName("html")[0]
|
const htmlClassList =
|
||||||
.classList
|
document.getElementsByTagName("html")[0]
|
||||||
.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) {
|
if (!isExtraCssLoaded) {
|
||||||
return null;
|
return null;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user