Skip to content
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

Feature/loading screen #43

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion packages/core/src/elements/iframe.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { iframeStyles } from "../styles/styles";

import { ORBA_ONE_MESSAGE_CHANNEL, ORBA_ONE_SUCCESS, ORBA_ONE_CANCEL } from "./constants";
import { removeLoadingScreen } from "../helpers/utils";

import {ORBA_ONE_MESSAGE_CHANNEL,ORBA_ONE_SUCCESS,ORBA_ONE_CANCEL} from "./constants";

type State = "loading" | "success" | "error" | "idle";

Expand Down Expand Up @@ -57,7 +59,9 @@ export function iframeManager(
// The html tag has to have a overflowY value of visible instead of auto to
// prevent unnecessary margins to the scrollbar
document.documentElement.style.overflowY = "visible";
removeLoadingScreen();
document.body.removeChild(iframe);

}

function addIFrame() {
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/helpers/elements.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const loadingDiv = document.createElement('div');
10 changes: 10 additions & 0 deletions packages/core/src/helpers/utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { OrbaOneConfig } from "./types";
import { iframeLoader } from "../styles/templates";
import { loadingDiv } from "../helpers/elements";

export function isDomElement(obj: any): obj is HTMLElement | Element {
//! check if obj is not null explicitly because null is a type of object
Expand Down Expand Up @@ -57,3 +59,11 @@ export function getSessionUrl(verificationUrl: string, apiKey: string, applicant
return `${verificationUrl}?publicKey=${apiKey}&applicantId=${applicantId}&steps=${steps.join("&steps=")}`;
}

export function showLoadingScreen() {
loadingDiv.innerHTML = iframeLoader;
document.body.appendChild(loadingDiv);
}

export function removeLoadingScreen() {
document.body.removeChild(loadingDiv);
}
5 changes: 3 additions & 2 deletions packages/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@ import { createButton } from "./elements/button";
import { createIframe } from "./elements/iframe";
import { verificationUrl } from "./helpers/defaultConfig";
import { OrbaOneConfig } from "./helpers/types";

import { getSessionUrl, isValidConfig } from "./helpers/utils";
import { showLoadingScreen } from "./helpers/utils";

function initializeVerification(config: OrbaOneConfig, button: ReturnType<typeof createButton>): void {
const { apiKey, applicantId, onSuccess, onCancelled, onError, steps } = config;

//Set Loading state
button.setState("loading");

showLoadingScreen();

const url = getSessionUrl(verificationUrl, apiKey, applicantId, steps);
const iframe = createIframe(url, applicantId, onSuccess, onCancelled, onError, (state) => {
button.setState(state);
Expand Down
17 changes: 17 additions & 0 deletions packages/core/src/styles/templates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,3 +119,20 @@ export const loader = `
</rect>
</svg>
`;

export const iframeLoader = `
<div
style="
position:absolute;
top:0;
bottom:0;
left:0;
right:0;
display:flex;
align-items:center;
justify-content:center;
background-color: rgba(255, 255, 255, 0.8);
">
${loader}
</div>
`;