@rango-dev/widget-embedded 0.23.1-next.16 → 0.23.1-next.18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. package/dist/components/ConfirmWalletsModal/ConfirmWallets.styles.d.ts +1 -283
  2. package/dist/components/ConfirmWalletsModal/ConfirmWallets.styles.d.ts.map +1 -1
  3. package/dist/components/ConfirmWalletsModal/ConfirmWalletsModal.d.ts.map +1 -1
  4. package/dist/components/LoadingLiquiditySourceList/LoadingLiquiditySourceList.styles.d.ts +1 -1
  5. package/dist/components/LoadingLiquiditySourceList/LoadingLiquiditySourceList.styles.d.ts.map +1 -1
  6. package/dist/components/Quote/Quote.d.ts.map +1 -1
  7. package/dist/components/Quote/Quote.styles.d.ts.map +1 -1
  8. package/dist/components/Quote/QuoteTrigger.d.ts.map +1 -1
  9. package/dist/components/Quotes/SelectStrategy.d.ts.map +1 -1
  10. package/dist/components/Slippage/Slippage.d.ts.map +1 -1
  11. package/dist/components/TokenList/TokenList.d.ts.map +1 -1
  12. package/dist/hooks/useSwapInput.d.ts.map +1 -1
  13. package/dist/index.js +2 -2
  14. package/dist/index.js.map +3 -3
  15. package/dist/pages/ConfirmSwapPage.d.ts.map +1 -1
  16. package/dist/pages/LiquiditySourcePage.d.ts.map +1 -1
  17. package/dist/pages/SettingsPage.d.ts.map +1 -1
  18. package/dist/types/config.d.ts +3 -3
  19. package/dist/types/config.d.ts.map +1 -1
  20. package/dist/utils/colors.d.ts +5 -3
  21. package/dist/utils/colors.d.ts.map +1 -1
  22. package/dist/utils/ui.d.ts +5 -2
  23. package/dist/utils/ui.d.ts.map +1 -1
  24. package/package.json +3 -3
  25. package/src/components/ConfirmWalletsModal/ConfirmWallets.styles.ts +5 -11
  26. package/src/components/ConfirmWalletsModal/ConfirmWalletsModal.tsx +7 -11
  27. package/src/components/ConfirmWalletsModal/WalletList.tsx +2 -2
  28. package/src/components/LoadingLiquiditySourceList/LoadingLiquiditySourceList.styles.ts +1 -1
  29. package/src/components/LoadingLiquiditySourceList/LoadingLiquiditySourceList.tsx +4 -4
  30. package/src/components/Quote/Quote.styles.ts +13 -14
  31. package/src/components/Quote/Quote.tsx +4 -3
  32. package/src/components/Quote/QuoteTrigger.tsx +4 -5
  33. package/src/components/QuoteSkeleton/QuoteSkeleton.styles.ts +1 -1
  34. package/src/components/Quotes/SelectStrategy.tsx +3 -11
  35. package/src/components/Slippage/Slippage.tsx +11 -13
  36. package/src/components/TokenList/TokenList.tsx +9 -8
  37. package/src/hooks/useSwapInput.ts +3 -2
  38. package/src/pages/ConfirmSwapPage.tsx +7 -3
  39. package/src/pages/LiquiditySourcePage.tsx +3 -1
  40. package/src/pages/SettingsPage.tsx +0 -1
  41. package/src/store/slices/config.ts +2 -2
  42. package/src/store/slices/data.ts +4 -4
  43. package/src/types/config.ts +3 -3
  44. package/src/utils/colors.ts +106 -75
  45. package/src/utils/ui.ts +7 -5
@@ -1,68 +1,113 @@
1
1
  import type { WidgetColors, WidgetColorsKeys } from '../types';
2
2
 
3
- export const colorShade = (col: string, amt: number) => {
4
- const RANGE = 255;
5
- const COL = 3;
6
- const RADIX = 16;
7
-
8
- col = col.replace(/^#/, '');
9
- if (col.length === COL) {
10
- col = col[0] + col[0] + col[1] + col[1] + col[2] + col[2];
11
- }
12
- let [r, g, b]: any = col.match(/.{2}/g);
13
- [r, g, b] = [
14
- parseInt(r, RADIX) + amt,
15
- parseInt(g, RADIX) + amt,
16
- parseInt(b, RADIX) + amt,
17
- ];
18
-
19
- r = Math.max(Math.min(RANGE, r), 0).toString(RADIX);
20
- g = Math.max(Math.min(RANGE, g), 0).toString(RADIX);
21
- b = Math.max(Math.min(RANGE, b), 0).toString(RADIX);
22
-
23
- const rr = (r.length < 2 ? '0' : '') + r;
24
- const gg = (g.length < 2 ? '0' : '') + g;
25
- const bb = (b.length < 2 ? '0' : '') + b;
26
-
27
- return `#${rr}${gg}${bb}`;
28
- };
3
+ export function generateShades(
4
+ baseColor: string,
5
+ prefix: string,
6
+ reverse?: boolean
7
+ ): { [key: string]: string } {
8
+ const BASE_SHADE_INDEX = 100;
9
+ const NUMBER_OF_COLORS = 9;
10
+ const SHADING_INCREMENT_MAX = 10; // For bright colors
11
+ const SHADING_INCREMENT_MIN = 6; // For dark colors
29
12
 
30
- export const generateRangeColors = (name: string, color: string) => {
31
- const NUMBER_OF_COLORS = 10;
32
- const HALF_NUMBER_OF_COLORS = 5;
33
- const COLOR_SUFFIX = 100;
34
- const AMT = 25;
35
-
36
- let colors = { [name]: color };
37
- for (let i = 1; i < NUMBER_OF_COLORS; i++) {
38
- if (i < HALF_NUMBER_OF_COLORS) {
39
- colors = {
40
- ...colors,
41
- [name + i * COLOR_SUFFIX]: colorShade(
42
- color,
43
- (HALF_NUMBER_OF_COLORS - i) * AMT
44
- ),
45
- };
46
- }
47
- if (i === HALF_NUMBER_OF_COLORS) {
48
- colors = {
49
- ...colors,
50
- [name + i * COLOR_SUFFIX]: color,
51
- };
52
- }
53
- if (i > HALF_NUMBER_OF_COLORS) {
54
- colors = {
55
- ...colors,
56
- [name + i * COLOR_SUFFIX]: colorShade(
57
- color,
58
- -((i - HALF_NUMBER_OF_COLORS) * AMT)
59
- ),
60
- };
13
+ const HALF_NUMBER_OF_COLORS = 4;
14
+
15
+ const shadeIncrements: number[] = [];
16
+ let increment = 90;
17
+ for (let i = 0; i < NUMBER_OF_COLORS; i++) {
18
+ shadeIncrements.push(increment);
19
+ if (i + 1 === HALF_NUMBER_OF_COLORS) {
20
+ increment = 0;
21
+ } else {
22
+ increment -=
23
+ i >= HALF_NUMBER_OF_COLORS
24
+ ? SHADING_INCREMENT_MIN
25
+ : SHADING_INCREMENT_MAX;
61
26
  }
62
27
  }
63
28
 
64
- return colors;
65
- };
29
+ // If 'reverse' is true, that means the color should be from dark to light
30
+ const decrementAmounts = reverse
31
+ ? shadeIncrements.slice().reverse()
32
+ : shadeIncrements;
33
+
34
+ const shades: { [key: string]: string } = {};
35
+
36
+ // Generate shades
37
+ for (let i = 0; i < NUMBER_OF_COLORS; i++) {
38
+ const shadeIndex = BASE_SHADE_INDEX + i * BASE_SHADE_INDEX;
39
+ const decrementAmount = decrementAmounts[i];
40
+
41
+ const shade: { [key: string]: string } = {
42
+ [`${prefix}${shadeIndex}`]: generateShade(baseColor, decrementAmount),
43
+ };
44
+ Object.assign(shades, shade);
45
+ }
46
+
47
+ return { ...shades, [prefix]: baseColor };
48
+ }
49
+
50
+ export function generateShade(
51
+ baseColor: string,
52
+ decrementAmount: number
53
+ ): string {
54
+ const [r, g, b] = convertToRGB(baseColor);
55
+ return `#${clamp(r + decrementAmount)}${clamp(g + decrementAmount)}${clamp(
56
+ b + decrementAmount
57
+ )}`;
58
+ }
59
+
60
+ export function convertToRGB(baseColor: string): number[] {
61
+ const COLOR_SLICE_START = 1;
62
+ const COLOR_SLICE_END = 3;
63
+ const BASE_COLOR_LENGTH = 7;
64
+
65
+ // Convert the base color to RGB components
66
+ const r: number = parseInt(
67
+ baseColor.slice(COLOR_SLICE_START, COLOR_SLICE_END),
68
+ 16
69
+ );
70
+ const g: number = parseInt(
71
+ baseColor.slice(COLOR_SLICE_END, COLOR_SLICE_END + 2),
72
+ 16
73
+ );
74
+ const b: number = parseInt(
75
+ baseColor.slice(COLOR_SLICE_END + 2, BASE_COLOR_LENGTH),
76
+ 16
77
+ );
78
+
79
+ return [r, g, b];
80
+ }
81
+
82
+ // Function to clamp color component to valid range [0, 255] and convert to hex
83
+ function clamp(color: number): string {
84
+ const MAX_COLOR_VALUE = 255;
85
+ const HEX_BASE = 16;
86
+ const HEX_LENGTH = -2;
87
+ return (
88
+ '0' + Math.max(0, Math.min(MAX_COLOR_VALUE, color)).toString(HEX_BASE)
89
+ )
90
+ .slice(HEX_LENGTH)
91
+ .toUpperCase();
92
+ }
93
+
94
+ export function isBright(baseColor: string) {
95
+ const BRIGHTNESS_THRESHOLD = 188;
96
+ const RED_COEFFICIENT = 299;
97
+ const GREEN_COEFFICIENT = 587;
98
+ const BLUE_COEFFICIENT = 114;
99
+ const BRIGHTNESS_DIVISOR = 1000;
100
+
101
+ const [r, g, b] = convertToRGB(baseColor);
102
+ const brightness =
103
+ (r * RED_COEFFICIENT + g * GREEN_COEFFICIENT + b * BLUE_COEFFICIENT) /
104
+ BRIGHTNESS_DIVISOR;
105
+ if (brightness > BRIGHTNESS_THRESHOLD) {
106
+ return true;
107
+ }
108
+ return false;
109
+ }
110
+
66
111
  export const generateColors = (
67
112
  mainColors: { [x: string]: string },
68
113
  reverseNeutralRange: boolean,
@@ -83,25 +128,11 @@ export const generateColors = (
83
128
  ...listOfColors,
84
129
  [colorKey]: color,
85
130
  };
86
- } else if (colorKey === 'neutral' && reverseNeutralRange) {
87
- const range = generateRangeColors(colorKey, color);
88
- listOfColors = {
89
- ...listOfColors,
90
- // Reverse the neutral shade
91
- [`${colorKey}100`]: range[`${colorKey}900`],
92
- [`${colorKey}200`]: range[`${colorKey}800`],
93
- [`${colorKey}300`]: range[`${colorKey}700`],
94
- [`${colorKey}400`]: range[`${colorKey}600`],
95
- [`${colorKey}500`]: range[`${colorKey}500`],
96
- [`${colorKey}600`]: range[`${colorKey}400`],
97
- [`${colorKey}700`]: range[`${colorKey}300`],
98
- [`${colorKey}800`]: range[`${colorKey}200`],
99
- [`${colorKey}900`]: range[`${colorKey}100`],
100
- };
101
131
  } else {
132
+ const reverse = colorKey === 'neutral' && reverseNeutralRange;
102
133
  listOfColors = {
103
134
  ...listOfColors,
104
- ...generateRangeColors(colorKey, color),
135
+ ...generateShades(color, colorKey, reverse),
105
136
  };
106
137
  }
107
138
  }
package/src/utils/ui.ts CHANGED
@@ -1,12 +1,12 @@
1
1
  /* eslint-disable @typescript-eslint/no-magic-numbers */
2
2
  import type { WidgetTheme } from '../types';
3
3
  import type { createTheme } from '@rango-dev/ui';
4
- import type React from 'react';
5
4
 
6
5
  import {
7
6
  theme as baseThemeTokens,
8
7
  darkColors as defaultDarkColors,
9
8
  } from '@rango-dev/ui';
9
+ import React from 'react';
10
10
 
11
11
  import { generateColors } from '../utils/colors';
12
12
  import { toHash } from '../utils/hash';
@@ -73,18 +73,20 @@ export function customizedThemeTokens(
73
73
  }
74
74
 
75
75
  export function joinList(
76
- list: React.JSX.Element[],
76
+ list: { element: React.JSX.Element; key: string }[],
77
77
  divider: React.JSX.Element
78
78
  ) {
79
79
  if (list.length <= 1) {
80
- return list;
80
+ return list.map(({ element, key }) => React.cloneElement(element, { key }));
81
81
  }
82
82
 
83
83
  const output: React.JSX.Element[] = [];
84
84
  list.forEach((item, index) => {
85
- output.push(item);
85
+ const { element, key } = item;
86
+ output.push(React.cloneElement(element, { key }));
86
87
  if (index < list.length - 1) {
87
- output.push(divider);
88
+ const key = `divider-${index}`;
89
+ output.push(React.cloneElement(divider, { key }));
88
90
  }
89
91
  });
90
92