Files
ipal-kit/src/modules/branding/signIn/css.ts
T
Radosław SmolińskiandClaude Fable 5.2 b6c91a3a11 Sign-in look: the client's logo or the site's name on a dark panel beside the form (whiteLabel.signIn)
On by default with whiteLabel. The login screen and the 2FA screens get the look through AdminLogo and
SafeTotpView, which every site already has in its import map: an upgrade needs no edit. allScreens adds one
provider (SignInLook) for forgot / reset password, first user and logout; a production start leaves it out
when the import map on disk lacks it. Logo and name come from Site settings: no new field, no migration.
Language links through GET /api/ipal/admin-language (Payload's own cookie, back to an admin path only).
Options: accent, logoMadeFor, languages, svgLogo; whiteLabel.brandAccess 'admin'. The 2FA code boxes get
names for screen readers. Reference site and starter: allScreens on. Docs, agent guide, skills, tests.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
2026-11-26 20:35:33 +01:00

170 lines
11 KiB
TypeScript

/**
* The stylesheet of the panel's sign-in screens (`whiteLabel.signIn`): a dark panel with the client's logo or
* name beside the form, the look IAPL shares with its WordPress sibling. It styles Payload's minimal template
* (`.template-minimal`: login, forgot and reset password, create first user, logout, the 2FA screens) and the one
* element IAPL prints (`.iapl-signin`). CSS only: no script, no font file, no request to another host.
*
* It is put into the page as a `<style>` by the component that prints the panel, so it exists only where the
* panel does; every rule needs `.iapl-signin` on the page. Payload's own rules sit in `@layer payload-default`,
* so these win without `!important`; the few `!important`s answer inline styles and the 2FA package's own.
*
* Projects: set the custom properties on `:root` in the admin's `custom.scss` (the defaults below have no
* specificity), or pass `whiteLabel.signIn.accent`.
*/
/** A colour a project may pass as the accent: a hex value only, so nothing else can reach the stylesheet. */
export const isHexColour = (value: unknown): value is string => typeof value === 'string' && /^#(?:[0-9a-f]{3}|[0-9a-f]{6})$/i.test(value)
/** Id of the `<style>`: React keeps one copy however many components print it. */
export const SIGN_IN_STYLE_ID = 'iapl-sign-in'
const TOKENS = (accent: string | undefined) => `
:where(:root){
--iapl-signin-split:45.4545%;
--iapl-signin-bg:#ffffff;
--iapl-signin-text:#060606;
--iapl-signin-muted:#5f6368;
--iapl-signin-border:#e5e7eb;
--iapl-signin-field-border:#80868f;
--iapl-signin-primary:${accent ?? '#0070c0'};
--iapl-signin-primary-hover:${accent ? 'color-mix(in srgb,var(--iapl-signin-primary) 82%,#000)' : '#005a9e'};
--iapl-signin-primary-text:#ffffff;
--iapl-signin-link:${accent ? 'var(--iapl-signin-primary)' : '#006bb8'};
--iapl-signin-focus:${accent ? 'var(--iapl-signin-primary)' : '#017bd0'};
--iapl-signin-panel:#060606;
--iapl-signin-panel-text:#fbfbfb;
--iapl-signin-panel-label:#b2b2b2;
--iapl-signin-panel-glow:0 158 246;
--iapl-signin-panel-inset:0.625rem;
--iapl-signin-panel-radius:1.25rem;
--iapl-signin-radius:0.375rem;
}
:where(html[data-theme=dark]){
--iapl-signin-bg:var(--theme-bg,#141414);
--iapl-signin-text:#f3f3f3;
--iapl-signin-muted:#a8adb4;
--iapl-signin-border:#2f3338;
--iapl-signin-field-border:#6b7178;
--iapl-signin-link:${accent ? 'color-mix(in srgb,var(--iapl-signin-primary) 55%,#fff)' : '#74bdf2'};
--iapl-signin-focus:${accent ? 'color-mix(in srgb,var(--iapl-signin-primary) 55%,#fff)' : '#4aa8f0'};
}`
const RULES = `
.iapl-signin{display:none}
body:has(.template-minimal) .iapl-signin{
box-sizing:border-box;position:fixed;z-index:1;inset-block:var(--iapl-signin-panel-inset);inset-inline-start:var(--iapl-signin-panel-inset);
width:calc(var(--iapl-signin-split) - var(--iapl-signin-panel-inset));margin:0;padding:clamp(2rem,4vw,4rem);overflow:hidden;
display:flex;flex-direction:column;justify-content:flex-end;align-items:flex-start;gap:1.25rem;
background:var(--iapl-signin-panel);border-radius:var(--iapl-signin-panel-radius);color:var(--iapl-signin-panel-text);text-align:start;
}
.iapl-signin *{box-sizing:border-box}
.iapl-signin::before{
content:"";position:absolute;inset:0;pointer-events:none;
background:
linear-gradient(rgb(255 255 255 / .04) 1px,transparent 1px) 0 0 / 3.5rem 2.5rem,
linear-gradient(90deg,rgb(255 255 255 / .04) 1px,transparent 1px) 0 0 / 3.5rem 2.5rem;
}
.iapl-signin::after{
content:"";position:absolute;inset:0;pointer-events:none;
background:
radial-gradient(circle 24rem at 0% 62%,rgb(var(--iapl-signin-panel-glow) / .24),transparent),
radial-gradient(circle 22rem at 100% 8%,rgb(var(--iapl-signin-panel-glow) / .22),transparent);
}
.iapl-signin>*{position:relative;z-index:1}
.iapl-signin__label{
display:flex;align-items:center;gap:.625rem;margin:0;padding:0;
font:600 .875rem/1.25rem ui-monospace,"SFMono-Regular",Menlo,Consolas,"Liberation Mono",monospace;
letter-spacing:.05em;text-transform:uppercase;color:var(--iapl-signin-panel-label);
}
.iapl-signin__label::before{content:"";flex:none;width:.3125rem;height:.3125rem;background:rgb(var(--iapl-signin-panel-glow))}
.iapl-signin__brand{display:block;max-width:100%;color:inherit;text-decoration:none}
.iapl-signin__brand--plate{padding:1rem 1.25rem;background:#fff;border-radius:.75rem}
.iapl-signin__brand img{display:block;width:auto;height:auto;max-width:min(15rem,100%);max-height:4.5rem}
.iapl-signin__brand--name{
margin:0;font-family:inherit;font-weight:500;font-size:clamp(2.25rem,1.4rem + 2.4vw,3.75rem);line-height:1.12;letter-spacing:-.03em;
text-wrap:balance;overflow-wrap:anywhere;
}
.iapl-signin a:hover{color:inherit}
.iapl-signin a:focus-visible{outline:2px solid #fff;outline-offset:3px;border-radius:.25rem}
.iapl-signin__languages{position:absolute;inset-block-start:clamp(1.25rem,2.5vw,2rem);inset-inline-end:clamp(1.25rem,2.5vw,2rem);max-width:calc(100% - 2.5rem);font-size:.8125rem;line-height:1.25rem;color:var(--iapl-signin-panel-label)}
.iapl-signin__languages ul{display:flex;flex-wrap:wrap;justify-content:flex-end;gap:0 .125rem;margin:0;padding:0;list-style:none}
.iapl-signin__languages li{display:flex;align-items:center;margin:0;padding:0}
.iapl-signin__languages li+li::before{content:"";width:1px;height:.875rem;margin-inline-end:.125rem;background:rgb(255 255 255 / .22)}
.iapl-signin__languages :is(a,span){display:block;padding:.375rem .5rem;color:inherit;text-decoration:none;border-radius:.25rem}
.iapl-signin__languages a:hover{color:#fff;text-decoration:underline}
.iapl-signin__languages [aria-current]{color:#fff;font-weight:600}
/* The form column: Payload's minimal template. */
html:has(.iapl-signin) body .template-minimal{
box-sizing:border-box;width:calc(100% - var(--iapl-signin-split));min-height:100vh;min-height:100svh;height:auto;
margin-inline:var(--iapl-signin-split) 0;padding:clamp(1.5rem,4vw,3.5rem) clamp(1.25rem,4vw,2rem);
background:var(--iapl-signin-bg);color:var(--iapl-signin-text);
}
html:has(.iapl-signin) body:has(.template-minimal){background:var(--iapl-signin-bg)}
html:has(.iapl-signin) .template-minimal--width-normal .template-minimal__wrap{max-width:28rem}
/* The logo's own place on the login screen: the panel carries the brand. */
html:has(.iapl-signin) .login__brand{display:block;margin:0}
html:has(.iapl-signin) .login__brand:not(:has(.iapl-signin)){display:none}
html:has(.iapl-signin) .template-minimal h1{font-size:1.75rem;line-height:1.2;letter-spacing:-.02em;font-weight:500}
html:has(.iapl-signin) .template-minimal a:not(.btn):not(.iapl-signin *){color:var(--iapl-signin-link);text-underline-offset:.25em}
html:has(.iapl-signin) .template-minimal :is(a,button,input,select,textarea):not(.iapl-signin *):focus-visible{outline:2px solid var(--iapl-signin-focus);outline-offset:2px}
html:has(.iapl-signin) .template-minimal .field-type :is(input[type=text],input[type=email],input[type=password]){
min-height:3rem;border-color:var(--iapl-signin-field-border);border-radius:var(--iapl-signin-radius);
}
/* The 2FA code boxes are white with a soft shadow: on a white page they need an edge. */
html:has(.iapl-signin) .template-minimal form input[type=text]:not(.field-type *){box-shadow:inset 0 0 0 1px var(--iapl-signin-field-border)}
html:has(.iapl-signin) .template-minimal .form-submit{display:block;width:100%;margin:1.375rem 0 0}
html:has(.iapl-signin) .template-minimal :is(.form-submit .btn,.btn--style-primary):not(.btn--disabled){
--bg-color:var(--iapl-signin-primary);--hover-bg:var(--iapl-signin-primary-hover);--color:var(--iapl-signin-primary-text);--hover-color:var(--iapl-signin-primary-text);
}
html:has(.iapl-signin) .template-minimal .form-submit .btn{display:block;width:100%;min-height:3.125rem;margin-block:0;border-radius:var(--iapl-signin-radius)}
html:has(.iapl-signin) .template-minimal .forgot-password__form__actions{gap:1rem}
html:has(.iapl-signin) .template-minimal .forgot-password__form__actions .form-submit{margin-top:.375rem}
html:has(.iapl-signin) .template-minimal .reset-password__wrap>a{display:inline-block;margin-top:1rem}
/* The credit line under the login form (its own inline styles are answered here). */
html:has(.iapl-signin) .template-minimal .iapl-credit--login{
margin-top:1.5rem!important;padding:1rem 0 0!important;border-top:1px solid var(--iapl-signin-border);
color:var(--iapl-signin-muted)!important;opacity:1!important;font-size:.8125rem!important;
}
/* The 2FA setup notice is a bar over the page: it stays over the form column. */
html:has(.iapl-signin) body:has(.template-minimal) #ipal-two-factor-notice{margin-inline-start:var(--iapl-signin-split)}
/* A phone: the panel is a band above the form. */
@media (max-width:52rem){
body:has(.template-minimal) .iapl-signin{
position:relative;inset:auto;width:100vw;max-width:none;margin-inline-start:calc(50% - 50vw);
justify-content:flex-start;gap:.625rem;padding:1.75rem 1.25rem 2rem;
border-radius:0 0 var(--iapl-signin-panel-radius) var(--iapl-signin-panel-radius);
}
.iapl-signin::after{
background:
radial-gradient(circle 12rem at 0% 100%,rgb(var(--iapl-signin-panel-glow) / .2),transparent),
radial-gradient(circle 12rem at 100% 0%,rgb(var(--iapl-signin-panel-glow) / .22),transparent);
}
.iapl-signin__brand img{max-width:min(12rem,100%);max-height:3.5rem}
.iapl-signin__brand--plate{padding:.75rem 1rem}
.iapl-signin__brand--name{font-size:1.875rem}
.iapl-signin__languages{position:static;order:3;max-width:100%;margin:.375rem 0 -.5rem -.5rem}
.iapl-signin__languages ul{justify-content:flex-start}
html:has(.iapl-signin) body .template-minimal{
width:100%;min-height:0;margin-inline:0;align-items:flex-start;padding:1.75rem 1.25rem 2rem;
}
html:has(.iapl-signin) body .template-minimal:has(.iapl-signin){padding-top:0}
html:has(.iapl-signin) .login__brand:has(.iapl-signin){margin-bottom:1.75rem}
html:has(.iapl-signin) .template-minimal--width-normal .template-minimal__wrap{max-width:30rem}
html:has(.iapl-signin) body:has(.template-minimal) #ipal-two-factor-notice{margin-inline-start:0}
}
@media (prefers-reduced-motion:no-preference){
html:has(.iapl-signin) .template-minimal .form-submit .btn{transition:background-color 120ms ease}
}
@media (forced-colors:active){
body:has(.template-minimal) .iapl-signin{border:1px solid CanvasText}
.iapl-signin__brand--plate{border:1px solid CanvasText}
}`
/** The whole stylesheet. `accent`: a hex colour for the button, the links and the focus ring. */
export function signInCss(options: { accent?: string } = {}): string {
const accent = isHexColour(options.accent) ? options.accent : undefined
return `${TOKENS(accent)}${RULES}`.replace(/\n\s*/g, '')
}