Skip to content

Commit

Permalink
Merge pull request #286 from torusresearch/feat/add-whitelabel-palett…
Browse files Browse the repository at this point in the history
…e-generation-algorithm

Create new whitelabel palette generation algorithm
  • Loading branch information
chaitanyapotti authored Jan 26, 2024
2 parents f7f0f6d + ace5fde commit e0dd0e4
Show file tree
Hide file tree
Showing 12 changed files with 5,203 additions and 6,220 deletions.
5,366 changes: 3,025 additions & 2,341 deletions examples/vue-example/package-lock.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions examples/vue-example/src/lib/whitelabel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const whiteLabel: WhiteLabelData = {
mode: "auto",
theme: {
primary: "#FF9900",
onPrimary: "black",
},
};

Expand Down
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"$schema": "node_modules/lerna/schemas/lerna-schema.json",
"version": "6.2.3",
"version": "6.2.5",
"npmClient": "npm"
}
5,959 changes: 2,096 additions & 3,863 deletions package-lock.json

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@
"tslib": "^2.6.2",
"typescript": "^5.3.3"
},
"optionalDependencies": {
"@nx/nx-linux-x64-gnu": "^17.2.8",
"@rollup/rollup-linux-x64-gnu": "^4.9.6"
},
"author": "Torus Labs",
"license": "MIT",
"lint-staged": {
Expand Down
4 changes: 2 additions & 2 deletions packages/openlogin-jrpc/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@toruslabs/openlogin-jrpc",
"version": "6.2.3",
"version": "6.2.5",
"homepage": "https://github.com/torusresearch/OpenLoginSdk#readme",
"license": "ISC",
"main": "dist/openloginJrpc.cjs.js",
Expand All @@ -21,7 +21,7 @@
},
"dependencies": {
"@metamask/rpc-errors": "^6.1.0",
"@toruslabs/openlogin-utils": "^6.2.2",
"@toruslabs/openlogin-utils": "^6.2.5",
"end-of-stream": "^1.4.4",
"events": "^3.3.0",
"fast-safe-stringify": "^2.1.1",
Expand Down
10 changes: 7 additions & 3 deletions packages/openlogin-utils/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@toruslabs/openlogin-utils",
"version": "6.2.2",
"version": "6.2.5",
"homepage": "https://github.com/torusresearch/OpenLoginSdk#readme",
"license": "ISC",
"main": "dist/openloginUtils.cjs.js",
Expand All @@ -21,7 +21,8 @@
},
"dependencies": {
"@toruslabs/constants": "^13.1.0",
"base64url": "^3.0.1"
"base64url": "^3.0.1",
"color": "^4.2.3"
},
"peerDependencies": {
"@babel/runtime": "7.x"
Expand Down Expand Up @@ -51,5 +52,8 @@
"node": ">=18.x",
"npm": ">=9.x"
},
"gitHead": "2d61b7f1967ecd704470c46ff7c30c47d240f4a4"
"gitHead": "2d61b7f1967ecd704470c46ff7c30c47d240f4a4",
"devDependencies": {
"@types/color": "^3.0.6"
}
}
2 changes: 2 additions & 0 deletions packages/openlogin-utils/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@ export * from "./browserStorage";
export * from "./constants";
export * from "./interfaces";
export * from "./utils";
// TODO: code splitting
export * from "./whitelabel";
6 changes: 3 additions & 3 deletions packages/openlogin-utils/src/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ export const LANGUAGES = {
fr: "fr",
pt: "pt",
nl: "nl",
tk: "tk",
tr: "tr",
} as const;

export type LANGUAGE_TYPE = (typeof LANGUAGES)[keyof typeof LANGUAGES];
Expand All @@ -255,7 +255,7 @@ export const THEME_MODES = {
light: "light",
dark: "dark",
auto: "auto",
};
} as const;

export type THEME_MODE_TYPE = (typeof THEME_MODES)[keyof typeof THEME_MODES];

Expand Down Expand Up @@ -300,7 +300,7 @@ export type WhiteLabelData = {
* fr: french
* pt: portuguese
* nl: dutch
* tk: turkish
* tr: turkish
*
* @defaultValue en
*/
Expand Down
49 changes: 49 additions & 0 deletions packages/openlogin-utils/src/whitelabel.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import Color from "color";

import { type WHITE_LABEL_THEME } from "./interfaces";

function getColorsList(colorsAmount = 3, colorsShiftAmount = 50, mixColor = "black", rotate = 0, saturation = 20, mainColor = "#0346ff") {
const colorsList = [];

let step;
for (step = 0; step < colorsAmount; step += 1) {
colorsList.push(
Color(mainColor)
.rotate(((step + 1) / colorsAmount) * -rotate)
.saturate(((step + 1) / colorsAmount) * (saturation / 100))
.mix(Color(mixColor), ((colorsShiftAmount / 100) * (step + 1)) / colorsAmount)
.hex()
);
}

return colorsList;
}

function generateWhiteLabelTheme(primary: string) {
const darkSet = getColorsList(3, 50, "black", 0, 20, primary);
const lightSet = getColorsList(6, 85, "white", 0, 20, primary);
return [...darkSet.reverse(), ...[primary], ...lightSet];
}

function applyWhiteLabelTheme(rootElement: HTMLElement, theme: WHITE_LABEL_THEME) {
if (theme.primary) {
const themeSet = generateWhiteLabelTheme(theme.primary);

rootElement.style.setProperty("--app-primary-900", themeSet[0]);
rootElement.style.setProperty("--app-primary-800", themeSet[1]);
rootElement.style.setProperty("--app-primary-700", themeSet[2]);
rootElement.style.setProperty("--app-primary-600", themeSet[3]);
rootElement.style.setProperty("--app-primary-500", themeSet[4]);
rootElement.style.setProperty("--app-primary-400", themeSet[5]);
rootElement.style.setProperty("--app-primary-300", themeSet[6]);
rootElement.style.setProperty("--app-primary-200", themeSet[7]);
rootElement.style.setProperty("--app-primary-100", themeSet[8]);
rootElement.style.setProperty("--app-primary-50", themeSet[9]);
}

if (theme.onPrimary) {
rootElement.style.setProperty("--app-on-primary", theme.onPrimary);
}
}

export { applyWhiteLabelTheme };
12 changes: 9 additions & 3 deletions packages/openlogin/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@toruslabs/openlogin",
"version": "6.2.2",
"version": "6.2.5",
"homepage": "https://github.com/torusresearch/OpenLoginSdk#readme",
"license": "ISC",
"main": "dist/openlogin.cjs.js",
Expand All @@ -23,15 +23,21 @@
"@toruslabs/eccrypto": "^4.0.0",
"@toruslabs/metadata-helpers": "^5.0.0",
"@toruslabs/openlogin-session-manager": "^3.0.0",
"@toruslabs/openlogin-utils": "^6.2.2",
"@toruslabs/openlogin-utils": "file:../openlogin-utils",
"@toruslabs/secure-pub-sub": "^0.0.1",
"bowser": "^2.11.0",
"events": "^3.3.0",
"loglevel": "^1.8.1",
"ts-custom-error": "^3.3.1"
},
"peerDependencies": {
"@babel/runtime": "7.x"
"@babel/runtime": "7.x",
"@toruslabs/openlogin-utils": "file:../openlogin-utils"
},
"peerDependenciesMeta": {
"@toruslabs/openlogin-utils": {
"optional": true
}
},
"files": [
"dist",
Expand Down
8 changes: 4 additions & 4 deletions packages/wrapper/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "openlogin",
"version": "6.2.3",
"version": "6.2.5",
"homepage": "https://github.com/torusresearch/OpenLoginSdk#readme",
"license": "ISC",
"main": "dist/openlogin.cjs.js",
Expand All @@ -20,9 +20,9 @@
"pre-commit": "lint-staged --cwd ."
},
"dependencies": {
"@toruslabs/openlogin": "^6.2.2",
"@toruslabs/openlogin-jrpc": "^6.2.3",
"@toruslabs/openlogin-utils": "^6.2.2"
"@toruslabs/openlogin": "^6.2.5",
"@toruslabs/openlogin-jrpc": "^6.2.5",
"@toruslabs/openlogin-utils": "^6.2.5"
},
"peerDependencies": {
"@babel/runtime": "7.x"
Expand Down

0 comments on commit e0dd0e4

Please sign in to comment.