Repository navigation
Upgrade login UI to PatternFly 6 #52371
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
78173aa
00abbcf
18d8c62
282c62a
9f6df0a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,84 +3,161 @@ import { useEnvironment } from "@keycloak/keycloak-ui-shared"; | |
| import { Environment } from "../../environment-types"; | ||
| import { joinPath } from "../../utils/joinPath"; | ||
| import { usePreviewBackground } from "./BackgroundContext"; | ||
| import { LoginForm, LoginPage } from "@patternfly/react-core"; | ||
| import { pf5VarsToPf6Css } from "./pf5ToPf6Tokens"; | ||
|
|
||
| type LoginPreviewWindowProps = { | ||
| cssVars: Record<string, string>; | ||
| }; | ||
|
|
||
| /** | ||
| * Renders a static PatternFly 6 login preview that mirrors the keycloak.v3 | ||
| * FreeMarker markup. Admin UI itself remains on PatternFly React 5, so this | ||
| * loads the theme CSS instead of using @patternfly/react-core LoginPage. | ||
| */ | ||
| export const LoginPreviewWindow = ({ cssVars }: LoginPreviewWindowProps) => { | ||
| const { environment } = useEnvironment<Environment>(); | ||
| const contextLogo = usePreviewLogo(); | ||
| const contextBackground = usePreviewBackground(); | ||
|
|
||
| // Resources | ||
| const resourceUrlRoot = joinPath( | ||
| environment.adminBaseUrl, | ||
| "resources", | ||
| environment.resourceVersion, | ||
| ); | ||
| const loginResourceUrl = `${resourceUrlRoot}/login/keycloak.v2`; | ||
| const loginResourceUrl = `${resourceUrlRoot}/login/keycloak.v3`; | ||
|
mabartos marked this conversation as resolved.
Resolved
|
||
| const commonResourceUrl = `${resourceUrlRoot}/common/keycloak`; | ||
|
|
||
| // Default login theme resources from local files | ||
| const defaultBgImage = `${loginResourceUrl}/img/keycloak-bg-darken.svg`; | ||
| const defaultLogo = `${loginResourceUrl}/img/keycloak-logo-text.svg`; | ||
|
|
||
| // Use uploaded images or fall back to local defaults | ||
| // Both logo and background come from context for immediate reactivity | ||
| const logoUrl = contextLogo?.logo || defaultLogo; | ||
| const bgUrl = contextBackground?.background || defaultBgImage; | ||
|
|
||
| // Logo dimensions are theme CSS custom properties, not PatternFly tokens. | ||
| const logoWidth = cssVars["logoWidth"]; | ||
| const logoHeight = cssVars["logoHeight"]; | ||
|
|
||
| const stylesThemeCssUrl = `${loginResourceUrl}/css/styles.css`; | ||
| const themeCssVars = Object.fromEntries( | ||
| Object.entries(cssVars).filter( | ||
| ([key]) => key !== "logoWidth" && key !== "logoHeight", | ||
|
mabartos marked this conversation as resolved.
Resolved
|
||
| ), | ||
| ); | ||
|
|
||
| return ( | ||
| <> | ||
| <link rel="stylesheet" href={stylesThemeCssUrl} /> | ||
| <link | ||
| rel="stylesheet" | ||
| href={`${commonResourceUrl}/vendor/patternfly-v6/patternfly.min.css`} | ||
| /> | ||
| <link | ||
| rel="stylesheet" | ||
| href={`${commonResourceUrl}/vendor/patternfly-v6/patternfly-addons.css`} | ||
| /> | ||
| <link rel="stylesheet" href={`${loginResourceUrl}/css/styles.css`} /> | ||
| <style>{` | ||
| .login-preview { | ||
| ${Object.entries(cssVars) | ||
| .map(([key, value]) => `--pf-v5-global--${key}: ${value};`) | ||
| .join("\n")} | ||
| ${pf5VarsToPf6Css(themeCssVars)} | ||
| /* Keycloak login theme variables - override with local/uploaded images */ | ||
| --keycloak-logo-url: url('${logoUrl}'); | ||
| --keycloak-bg-logo-url: url('${bgUrl}'); | ||
| ${logoHeight ? `--keycloak-logo-height: ${logoHeight};` : ""} | ||
| ${logoWidth ? `--keycloak-logo-width: ${logoWidth};` : ""} | ||
| } | ||
| /* Apply background to #keycloak-bg */ | ||
| .login-preview { | ||
| background: var(--keycloak-bg-logo-url); | ||
| /* Theme CSS targets "login-pf body"; preview is not a document body. */ | ||
| background: var(--keycloak-bg-logo-url) no-repeat center center; | ||
| background-size: cover; | ||
| } | ||
| .login-preview .kc-logo-text { | ||
| position: absolute; | ||
| position-anchor: --logo; | ||
| position-area: start center; | ||
| margin-bottom: 3rem; | ||
| } | ||
| .login-preview .pf-v5-c-login__main { | ||
| anchor-name: --logo; | ||
| } | ||
| .login-preview .pf-v5-c-login__footer { | ||
| display: none; | ||
| min-height: 40rem; | ||
| padding: 2rem 1rem; | ||
| } | ||
| `}</style> | ||
| <div className="login-preview login-pf"> | ||
| <div className="kc-logo-text"> | ||
| <span>Keycloak</span> | ||
| <div className="login-preview login-pf" data-testid="login-page-preview"> | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can be done in a follow-up.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also the toggle is global and because the admin console itself is not yet using pf6 we'll always have this problem that either one doesn't work |
||
| <div className="pf-v6-c-login"> | ||
| <div className="pf-v6-c-login__container"> | ||
| <header id="kc-header" className="pf-v6-c-login__header"> | ||
| <div id="kc-header-wrapper" className="pf-v6-c-brand"> | ||
| <div className="kc-logo-text"> | ||
| <span>Keycloak</span> | ||
| </div> | ||
| </div> | ||
| </header> | ||
| <main className="pf-v6-c-login__main"> | ||
| <div className="pf-v6-c-login__main-header"> | ||
| <h1 className="pf-v6-c-title pf-m-3xl" id="kc-page-title"> | ||
| Sign in to your account | ||
| </h1> | ||
| </div> | ||
| <div className="pf-v6-c-login__main-body"> | ||
| <div id="kc-form"> | ||
| <div id="kc-form-wrapper"> | ||
| <form | ||
| id="kc-form-login" | ||
| className="pf-v6-c-form pf-v6-u-w-100" | ||
| onSubmit={(event) => event.preventDefault()} | ||
| > | ||
| <div className="pf-v6-c-form__group"> | ||
| <div className="pf-v6-c-form__group-label pf-v6-u-pb-xs"> | ||
| <label | ||
| htmlFor="username" | ||
| className="pf-v6-c-form__label" | ||
| > | ||
| <span className="pf-v6-c-form__label-text"> | ||
| Username or email | ||
| </span> | ||
| </label> | ||
| </div> | ||
| <span className="pf-v6-c-form-control"> | ||
| <input | ||
| id="username" | ||
| name="username" | ||
| type="text" | ||
| autoComplete="username" | ||
| readOnly | ||
| /> | ||
| </span> | ||
| </div> | ||
| <div className="pf-v6-c-form__group"> | ||
| <div className="pf-v6-c-form__group-label pf-v6-u-pb-xs"> | ||
| <label | ||
| htmlFor="password" | ||
| className="pf-v6-c-form__label" | ||
| > | ||
| <span className="pf-v6-c-form__label-text"> | ||
| Password | ||
| </span> | ||
| </label> | ||
| </div> | ||
| <div className="pf-v6-c-input-group"> | ||
| <div className="pf-v6-c-input-group__item pf-m-fill"> | ||
| <span className="pf-v6-c-form-control"> | ||
| <input | ||
| id="password" | ||
| name="password" | ||
| type="password" | ||
| autoComplete="current-password" | ||
| readOnly | ||
| /> | ||
| </span> | ||
| </div> | ||
| </div> | ||
| </div> | ||
| <div className="pf-v6-c-form__group"> | ||
| <div className="pf-v6-c-form__actions pf-v6-u-pt-xs pf-v6-u-flex-wrap"> | ||
| <button | ||
| className="pf-v6-c-button pf-m-primary pf-m-block" | ||
| id="kc-login" | ||
| name="login" | ||
| type="submit" | ||
| > | ||
| Sign In | ||
| </button> | ||
| </div> | ||
| </div> | ||
| </form> | ||
| </div> | ||
| </div> | ||
| </div> | ||
| </main> | ||
| </div> | ||
| </div> | ||
| <LoginPage loginTitle="Sign in to your account"> | ||
| <LoginForm | ||
| usernameLabel="Username or email" | ||
| loginButtonLabel="Sign In" | ||
| /> | ||
| </LoginPage> | ||
| </div> | ||
| </> | ||
| ); | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.