If you don't have Storybook in your project you can also test your theme with the dev server.
React – Vite React – Webpack Angular – Webpack Angular – Vite
Copy import { createRoot } from "react-dom/client" ;
import { StrictMode , lazy , Suspense } from "react" ;
import { getKcContextMock } from "./login/KcPageStory" ;
if ( import . meta . env . DEV ) {
window .kcContext = getKcContextMock ({
pageId : "register.ftl" ,
overrides : {}
});
}
const KcLoginThemePage = lazy (() => import ( "./login/KcPage" ));
const KcAccountThemePage = lazy (() => import ( "./account/KcPage" ));
createRoot ( document .getElementById ( "root" ) ! ) .render (
< StrictMode >
< Suspense >
{(() => {
switch ( window . kcContext ?.themeType) {
case "login" :
return < KcLoginThemePage kcContext = { window .kcContext} />;
case "account" :
return < KcAccountThemePage kcContext = { window .kcContext} />;
}
return < h1 >No Keycloak Context</ h1 >;
})()}
</ Suspense >
</ StrictMode >
);
Copy import { createRoot } from "react-dom/client" ;
import { StrictMode , lazy , Suspense } from "react" ;
import { getKcContextMock } from "./login/KcPageStory" ;
if ( process . env . NODE_ENV === "development" ) {
window .kcContext = getKcContextMock ({
pageId : "register.ftl" ,
overrides : {}
});
}
const KcLoginThemePage = lazy (() => import ( "./login/KcPage" ));
const KcAccountThemePage = lazy (() => import ( "./account/KcPage" ));
createRoot ( document .getElementById ( "root" ) ! ) .render (
< StrictMode >
< Suspense >
{(() => {
switch ( window . kcContext ?.themeType) {
case "login" :
return < KcLoginThemePage kcContext = { window .kcContext} />;
case "account" :
return < KcAccountThemePage kcContext = { window .kcContext} />;
}
return < h1 >No Keycloak Context</ h1 >;
})()}
</ Suspense >
</ StrictMode >
);
Copy import '@angular/compiler' ;
import { provideExperimentalZonelessChangeDetection } from '@angular/core' ;
import { bootstrapApplication } from '@angular/platform-browser' ;
import { bootstrapKcApplication } from './kc.gen' ;
import { getKcContextMock } from './login/KcContextMock' ;
import { isDevMode } from '@angular/core' ;
if ( isDevMode ()) {
window .kcContext = getKcContextMock ({
pageId : 'register.ftl' ,
overrides : {} ,
});
}
( async () => {
if ( window .kcContext === undefined ) {
const { NoContextComponent } = await import ( './no-context.component' );
bootstrapApplication (NoContextComponent , appConfig);
return ;
}
bootstrapKcApplication ({
kcContext : window .kcContext ,
bootstrapApplication : ({ KcRootComponent , kcProvider }) =>
bootstrapApplication (KcRootComponent , {
... appConfig ,
providers : [ ... appConfig .providers , kcProvider] ,
}) ,
});
})();
Copy simport '@angular/compiler' ;
import { bootstrapApplication } from '@angular/platform-browser' ;
import { bootstrapKcApplication } from './kc.gen' ;
import { appConfig } from './app.config' ;
import { getKcContextMock } from './login/KcContextMock' ;
if ( import . meta . env . DEV ) {
window .kcContext = getKcContextMock ({
pageId : 'register.ftl' ,
overrides : {} ,
});
}
( async () => {
if ( window .kcContext === undefined ) {
const { NoContextComponent } = await import ( './no-context.component' );
bootstrapApplication (NoContextComponent , appConfig);
return ;
}
bootstrapKcApplication ({
kcContext : window .kcContext ,
bootstrapApplication : ({ KcRootComponent , kcProvider }) =>
bootstrapApplication (KcRootComponent , {
... appConfig ,
providers : [ ... appConfig .providers , kcProvider] ,
}) ,
});
})();
The pageId parameter of the getKcContextMock lets you decide what page you want to test.
The overrides parameter lets you modify the default kcContext mock for the page.
For example you can overwrite the kcContext.locale.currentLanguageTag to preview your page in a different language.
Copy window .kcContext = getKcContextMock ({
pageId : "login.ftl" ,
overrides : {
locale : {
currentLanguageTag : "zh-CN" ,
} ,
} ,
});
For rendering the Login page in Chinese.
Vite Webpack (Create React App) Angular CLI