Skip to content

Commit

Permalink
(feat) U4X-732: Change login page image and logo to be configurable. (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
jabahum authored Oct 25, 2024
1 parent 2ca3de5 commit 856b690
Show file tree
Hide file tree
Showing 7 changed files with 170 additions and 62 deletions.
29 changes: 29 additions & 0 deletions src/config-schema.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import _default from "@carbon/react/lib/components/Button/Button";
import { validators, Type } from "@openmrs/esm-framework";

export const configSchema = {
Expand Down Expand Up @@ -49,4 +50,32 @@ export const configSchema = {
_description: "Alt text, shown on hover",
},
},
loginBackgroundImage: {
src: {
_type: Type.String,
_default: "/openmrs/spa/background.png",
_description:
"A path or URL to an image. If null, will use the OpenMRS SVG sprite.",
_validators: [validators.isUrl],
},
alt: {
_type: Type.String,
_default: "Background",
_description: "Alt text, shown on hover",
},
},
loginLogoImage: {
src: {
_type: Type.String,
_default: "/openmrs/spa/updf-logo.jpg",
_description:
"A path or URL to an image. If null, will use the OpenMRS SVG sprite.",
_validators: [validators.isUrl],
},
alt: {
_type: Type.String,
_default: "OpenMRS Logo",
_description: "Alt text, shown on hover",
},
},
};
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { getAsyncLifecycle, defineConfigSchema } from "@openmrs/esm-framework";
import { configSchema } from "./config-schema";
import { configSchema } from "./config-schema";

const moduleName = "@ugandaemr/esm-login-app";

Expand Down
32 changes: 32 additions & 0 deletions src/login/background.wrapper.component.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import React from "react";
import styles from "./login.scss";
import { useConfig } from "@openmrs/esm-framework";
const BackgroundWrapper = ({ children }) => {
const config = useConfig();

return config?.loginBackgroundImage ? (
<>
<img
src={config?.loginBackgroundImage?.src}
alt={config?.loginBackgroundImage?.alt || "Background Image"}
className={styles.backgroundImage}
/>
<div className={styles.backgroundContainer}>
<div className={styles.contentOverlay}>{children}</div>
</div>
</>
) : (
<>
<img
src="/openmrs/spa/background.png"
alt="Fallback Background"
className={styles.backgroundImage}
/>
<div className={styles.backgroundContainer}>
<div className={styles.contentOverlay}>{children}</div>
</div>
</>
);
};

export default BackgroundWrapper;
6 changes: 3 additions & 3 deletions src/login/login.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
import { getProvider, performLogin, useFacilityName } from "./login.resource";
import Logo from "./logo.component";
import styles from "./login.scss";
import BackgroundWrapper from "./background.wrapper.component";

export interface LoginReferrer {
referrer?: string;
Expand Down Expand Up @@ -157,7 +158,7 @@ const Login: React.FC<LoginReferrer> = () => {

if (config.provider.type === "basic") {
return (
<div className={`canvas ${styles["container"]}`}>
<BackgroundWrapper>
<div className={styles.section}>
<div className={styles.logoContainer}>
<Logo className={styles.logo} />
Expand Down Expand Up @@ -260,10 +261,9 @@ const Login: React.FC<LoginReferrer> = () => {
</div>
</div>
</div>
</div>
</BackgroundWrapper>
);
}

return null;
};

Expand Down
56 changes: 48 additions & 8 deletions src/login/login.scss
Original file line number Diff line number Diff line change
@@ -1,14 +1,45 @@
@use "@carbon/colors";
@use "@carbon/styles/scss/type";
@import "../root.scss";
.container {

.backgroundContainer {
display: flex;
align-items: center;
background-image: url("../assets/background.png");
background-repeat: no-repeat;
justify-content: center;
height: 100vh;
background-size: cover;
width: 100%;
position: relative;
overflow: hidden;
}

.backgroundImage {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
object-fit: cover;
opacity: 1;
}

.contentOverlay {
position: relative;
z-index: 1;
display: flex;
justify-content: center;
align-items: center;
}

@media screen and (min-width: 1150px) {
.backgroundContainer {
max-width: 80%;
justify-content: right;
}

.backgroundImage {
object-fit: fit;
/* Fit image for larger screens */
}
}

.logoContainer {
Expand All @@ -20,6 +51,7 @@
@include type.type-style('label-02');
text-align: center;
margin-top: 1rem;

>*+* {
margin-left: 0.5rem;
}
Expand All @@ -33,6 +65,7 @@
a {
color: colors.$gray-70;
text-decoration: none;

&:hover {
text-decoration: underline;
}
Expand All @@ -45,6 +78,7 @@
flex-flow: row wrap;
justify-content: center;
align-items: center;

svg {
height: 2rem;
width: 7rem;
Expand All @@ -57,9 +91,11 @@
background-size: contain;
justify-content: right;
}

.login-card {
border: none;
}

.footer {
display: flex;
flex-direction: column;
Expand All @@ -73,8 +109,8 @@

.logo {
margin-bottom: 2rem;
height: 7rem;
width: 18.75rem;
max-height: 10rem;
max-width: 20rem;
}

.logo-img {
Expand Down Expand Up @@ -130,11 +166,13 @@
flex-direction: column;
align-items: center;
width: 18rem;
:global(.cds--text-input) {

:global(.cds--text-input) {
height: 3rem;
@extend .label01;
}
:global(.cds--text-input__field-outer-wrapper) {

:global(.cds--text-input__field-outer-wrapper) {
width: 18rem;
}
}
Expand All @@ -154,10 +192,12 @@
.back-button {
height: 3rem;
padding-left: 0rem;

svg {
margin-right: 0.5rem;
order: 1;
}

span {
order: 2;
}
Expand Down
5 changes: 0 additions & 5 deletions src/login/login.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,6 @@ jest.mock("./login.resource", () => ({
performLogin: jest.fn(),
}));

const loginLocations = [
{ uuid: "111", display: "Earth" },
{ uuid: "222", display: "Mars" },
];

mockedUseSession.mockReturnValue({ authenticated: false });
mockedUseConfig.mockReturnValue(mockConfig);

Expand Down
102 changes: 57 additions & 45 deletions src/login/logo.component.tsx

Large diffs are not rendered by default.

0 comments on commit 856b690

Please sign in to comment.