|
1 | | -import Color from "color"; |
| 1 | +import type { ColorConstructor } from "color"; |
2 | 2 |
|
3 | 3 | import { type WHITE_LABEL_THEME } from "./interfaces"; |
4 | 4 |
|
5 | | -export function getColorsList(colorsAmount = 3, colorsShiftAmount = 50, mixColor = "black", rotate = 0, saturation = 20, mainColor = "#0346ff") { |
| 5 | +export function getColorsList( |
| 6 | + colorPackage: ColorConstructor, |
| 7 | + colorsAmount = 3, |
| 8 | + colorsShiftAmount = 50, |
| 9 | + mixColor = "black", |
| 10 | + rotate = 0, |
| 11 | + saturation = 20, |
| 12 | + mainColor = "#0346ff" |
| 13 | +) { |
6 | 14 | const colorsList = []; |
7 | 15 |
|
8 | 16 | let step; |
9 | 17 | for (step = 0; step < colorsAmount; step += 1) { |
10 | 18 | colorsList.push( |
11 | | - Color(mainColor) |
| 19 | + colorPackage(mainColor) |
12 | 20 | .rotate(((step + 1) / colorsAmount) * -rotate) |
13 | 21 | .saturate(((step + 1) / colorsAmount) * (saturation / 100)) |
14 | | - .mix(Color(mixColor), ((colorsShiftAmount / 100) * (step + 1)) / colorsAmount) |
| 22 | + .mix(colorPackage(mixColor), ((colorsShiftAmount / 100) * (step + 1)) / colorsAmount) |
15 | 23 | .hex() |
16 | 24 | ); |
17 | 25 | } |
18 | 26 |
|
19 | 27 | return colorsList; |
20 | 28 | } |
21 | 29 |
|
22 | | -export function generateWhiteLabelTheme(primary: string) { |
23 | | - const darkSet = getColorsList(3, 50, "black", 0, 20, primary); |
24 | | - const lightSet = getColorsList(6, 85, "white", 0, 20, primary); |
| 30 | +export function generateWhiteLabelTheme(colorPackage: ColorConstructor, primary: string) { |
| 31 | + const darkSet = getColorsList(colorPackage, 3, 50, "black", 0, 20, primary); |
| 32 | + const lightSet = getColorsList(colorPackage, 6, 85, "white", 0, 20, primary); |
25 | 33 | return [...darkSet.reverse(), primary, ...lightSet]; |
26 | 34 | } |
27 | 35 |
|
28 | | -export function applyWhiteLabelTheme(rootElement: HTMLElement, theme: WHITE_LABEL_THEME) { |
| 36 | +export function applyWhiteLabelTheme(colorPackage: ColorConstructor, rootElement: HTMLElement, theme: WHITE_LABEL_THEME) { |
29 | 37 | if (theme.primary) { |
30 | | - const themeSet = generateWhiteLabelTheme(theme.primary); |
| 38 | + const themeSet = generateWhiteLabelTheme(colorPackage, theme.primary); |
31 | 39 |
|
32 | 40 | rootElement.style.setProperty("--app-primary-900", themeSet[0]); |
33 | 41 | rootElement.style.setProperty("--app-primary-800", themeSet[1]); |
|
0 commit comments