UNPKG

@openpass/openpass-js-sdk

Version:
45 lines 2.17 kB
import { getGreenWhiteSvg, getGreenBlueSvg } from "./logos"; const getButtonText = (text) => { switch (text) { case "signin": return "Sign in"; case "continue_with": return "Continue with OpenPass"; default: return "Sign in with OpenPass"; } }; export const createSignInButton = (options) => { var _a, _b, _c, _d, _e; const text = (_a = options.text) !== null && _a !== void 0 ? _a : "signin_with"; const size = (_b = options.size) !== null && _b !== void 0 ? _b : "large"; const theme = (_c = options.theme) !== null && _c !== void 0 ? _c : "openpass"; const shape = (_d = options.shape) !== null && _d !== void 0 ? _d : "standard"; const shapeVariant = (_e = options.shapeVariant) !== null && _e !== void 0 ? _e : "pill"; const button = document.createElement("button"); button.setAttribute("type", "button"); button.setAttribute("aria-label", "Sign in with OpenPass Button"); button.classList.add("op-js-sdk-siwopb__root"); button.classList.add(`op-js-sdk-siwopb__size-shape-${shape}-${size}`); button.classList.add(`op-js-sdk-siwopb__size-shape-${shape}-${shapeVariant}-${size}`); button.classList.add(`op-js-sdk-siwopb__theme-${theme}`); const innerDiv = document.createElement("div"); innerDiv.classList.add("op-js-sdk-siwopb__inner"); button.appendChild(innerDiv); if (options.additionalWidth && options.additionalWidth > 0) { const halfAdditionalWidth = options.additionalWidth / 2; innerDiv.style.marginLeft = `${halfAdditionalWidth}px`; innerDiv.style.marginRight = `${halfAdditionalWidth}px`; } const logoElement = theme === "light" ? getGreenBlueSvg(size) : getGreenWhiteSvg(size); logoElement.classList.add(`op-js-sdk-siwopb__logo-${size}`); logoElement.classList.add(`op-js-sdk-siwopb__logo-shape-${shape}-${size}`); innerDiv.appendChild(logoElement); if (shape === "standard") { const span = document.createElement("span"); span.innerText = getButtonText(text); innerDiv.appendChild(span); } return button; }; //# sourceMappingURL=html.js.map