@rango-dev/widget-embedded 0.28.3-next.6 → 0.29.0
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.
- package/dist/components/BlockchainList/BlockchainList.styles.d.ts +12 -21
- package/dist/components/BlockchainList/BlockchainList.styles.d.ts.map +1 -1
- package/dist/components/BlockchainsSection/BlockchainsSection.styles.d.ts +4 -7
- package/dist/components/BlockchainsSection/BlockchainsSection.styles.d.ts.map +1 -1
- package/dist/components/ConfirmWalletsModal/ConfirmWallets.styles.d.ts +60 -105
- package/dist/components/ConfirmWalletsModal/ConfirmWallets.styles.d.ts.map +1 -1
- package/dist/components/ConfirmWalletsModal/WalletList.styles.d.ts +12 -21
- package/dist/components/ConfirmWalletsModal/WalletList.styles.d.ts.map +1 -1
- package/dist/components/CustomCollapsible/CustomCollapsible.styles.d.ts +16 -28
- package/dist/components/CustomCollapsible/CustomCollapsible.styles.d.ts.map +1 -1
- package/dist/components/HeaderButtons/HeaderButtons.styles.d.ts +32 -56
- package/dist/components/HeaderButtons/HeaderButtons.styles.d.ts.map +1 -1
- package/dist/components/HistoryGroupedList/HistoryGroupedList.styles.d.ts +24 -42
- package/dist/components/HistoryGroupedList/HistoryGroupedList.styles.d.ts.map +1 -1
- package/dist/components/Layout/Layout.styles.d.ts +16 -28
- package/dist/components/Layout/Layout.styles.d.ts.map +1 -1
- package/dist/components/Layout/PageContainer.d.ts +4 -7
- package/dist/components/Layout/PageContainer.d.ts.map +1 -1
- package/dist/components/Layout/ScrollableArea.d.ts +4 -7
- package/dist/components/Layout/ScrollableArea.d.ts.map +1 -1
- package/dist/components/LoadingLiquiditySourceList/LoadingLiquiditySourceList.styles.d.ts +4 -7
- package/dist/components/LoadingLiquiditySourceList/LoadingLiquiditySourceList.styles.d.ts.map +1 -1
- package/dist/components/LoadingSwapDetails/LoadingSwapDetails.styles.d.ts +56 -98
- package/dist/components/LoadingSwapDetails/LoadingSwapDetails.styles.d.ts.map +1 -1
- package/dist/components/NoResult/NoResult.styles.d.ts +16 -28
- package/dist/components/NoResult/NoResult.styles.d.ts.map +1 -1
- package/dist/components/NotificationContent/NotificationContent.styles.d.ts +33 -57
- package/dist/components/NotificationContent/NotificationContent.styles.d.ts.map +1 -1
- package/dist/components/Quote/Quote.styles.d.ts +85 -148
- package/dist/components/Quote/Quote.styles.d.ts.map +1 -1
- package/dist/components/Quote/QuoteCostDetails.styles.d.ts +20 -35
- package/dist/components/Quote/QuoteCostDetails.styles.d.ts.map +1 -1
- package/dist/components/Quote/QuoteSummary.styles.d.ts +8 -14
- package/dist/components/Quote/QuoteSummary.styles.d.ts.map +1 -1
- package/dist/components/QuoteSkeleton/QuoteSkeleton.styles.d.ts +16 -28
- package/dist/components/QuoteSkeleton/QuoteSkeleton.styles.d.ts.map +1 -1
- package/dist/components/QuoteSkeleton/QuoteSummarySkeleton.styles.d.ts +40 -70
- package/dist/components/QuoteSkeleton/QuoteSummarySkeleton.styles.d.ts.map +1 -1
- package/dist/components/QuoteSkeleton/StepSkeleton.styles.d.ts +20 -35
- package/dist/components/QuoteSkeleton/StepSkeleton.styles.d.ts.map +1 -1
- package/dist/components/QuoteWarningsAndErrors/QuoteWarningsAndErrors.styles.d.ts +16 -28
- package/dist/components/QuoteWarningsAndErrors/QuoteWarningsAndErrors.styles.d.ts.map +1 -1
- package/dist/components/Quotes/Quotes.styles.d.ts +12 -21
- package/dist/components/Quotes/Quotes.styles.d.ts.map +1 -1
- package/dist/components/RefreshModal/RefreshModal.styles.d.ts +5 -8
- package/dist/components/RefreshModal/RefreshModal.styles.d.ts.map +1 -1
- package/dist/components/SearchInput/SearchInput.styles.d.ts +4 -7
- package/dist/components/SearchInput/SearchInput.styles.d.ts.map +1 -1
- package/dist/components/SettingsContainer/SettingsContainer.style.d.ts +12 -21
- package/dist/components/SettingsContainer/SettingsContainer.style.d.ts.map +1 -1
- package/dist/components/Slippage/Slippage.styles.d.ts +20 -35
- package/dist/components/Slippage/Slippage.styles.d.ts.map +1 -1
- package/dist/components/SwapDetails/SwapDetails.styles.d.ts +60 -105
- package/dist/components/SwapDetails/SwapDetails.styles.d.ts.map +1 -1
- package/dist/components/SwapDetailsAlerts/SwapDetailsAlerts.styles.d.ts +12 -21
- package/dist/components/SwapDetailsAlerts/SwapDetailsAlerts.styles.d.ts.map +1 -1
- package/dist/components/SwapDetailsModal/SwapDetailsModal.styles.d.ts +8 -14
- package/dist/components/SwapDetailsModal/SwapDetailsModal.styles.d.ts.map +1 -1
- package/dist/components/SwitchFromAndTo/SwitchFromAndTo.styles.d.ts +8 -14
- package/dist/components/SwitchFromAndTo/SwitchFromAndTo.styles.d.ts.map +1 -1
- package/dist/components/TokenList/TokenList.d.ts.map +1 -1
- package/dist/components/TokenList/TokenList.styles.d.ts +72 -126
- package/dist/components/TokenList/TokenList.styles.d.ts.map +1 -1
- package/dist/components/WalletModal/WalletModalContent.styles.d.ts +16 -28
- package/dist/components/WalletModal/WalletModalContent.styles.d.ts.map +1 -1
- package/dist/components/WalletNamespacesModal/WalletNamespacesModal.styles.d.ts +4 -7
- package/dist/components/WalletNamespacesModal/WalletNamespacesModal.styles.d.ts.map +1 -1
- package/dist/containers/App/App.styles.d.ts +4 -7
- package/dist/containers/App/App.styles.d.ts.map +1 -1
- package/dist/containers/ExpandedQuotes/ExpandedQuotes.styles.d.ts +8 -14
- package/dist/containers/ExpandedQuotes/ExpandedQuotes.styles.d.ts.map +1 -1
- package/dist/containers/Inputs/Inputs.styles.d.ts +8 -14
- package/dist/containers/Inputs/Inputs.styles.d.ts.map +1 -1
- package/dist/containers/QuoteInfo/QuoteInfo.styles.d.ts +12 -21
- package/dist/containers/QuoteInfo/QuoteInfo.styles.d.ts.map +1 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +3 -3
- package/dist/types/config.d.ts +5 -3
- package/dist/types/config.d.ts.map +1 -1
- package/dist/utils/colors.d.ts +7 -10
- package/dist/utils/colors.d.ts.map +1 -1
- package/dist/utils/ui.d.ts +2 -1
- package/dist/utils/ui.d.ts.map +1 -1
- package/dist/widget-embedded.build.json +1 -1
- package/package.json +9 -9
- package/src/components/HeaderButtons/HeaderButtons.styles.ts +1 -1
- package/src/components/Quote/Quote.styles.ts +5 -5
- package/src/components/TokenList/TokenList.tsx +8 -13
- package/src/types/config.ts +7 -3
- package/src/utils/colors.ts +160 -117
- package/src/utils/ui.ts +28 -33
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rango-dev/widget-embedded",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.29.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"source": "./src/index.ts",
|
|
@@ -24,15 +24,15 @@
|
|
|
24
24
|
"dependencies": {
|
|
25
25
|
"@lingui/core": "4.2.1",
|
|
26
26
|
"@lingui/react": "4.2.1",
|
|
27
|
-
"@rango-dev/logging-core": "^0.
|
|
28
|
-
"@rango-dev/provider-all": "^0.
|
|
27
|
+
"@rango-dev/logging-core": "^0.4.0",
|
|
28
|
+
"@rango-dev/provider-all": "^0.34.0",
|
|
29
29
|
"@rango-dev/queue-manager-core": "^0.26.0",
|
|
30
|
-
"@rango-dev/queue-manager-rango-preset": "^0.
|
|
30
|
+
"@rango-dev/queue-manager-rango-preset": "^0.34.0",
|
|
31
31
|
"@rango-dev/queue-manager-react": "^0.26.0",
|
|
32
|
-
"@rango-dev/signer-solana": "^0.
|
|
33
|
-
"@rango-dev/ui": "^0.
|
|
34
|
-
"@rango-dev/wallets-react": "^0.
|
|
35
|
-
"@rango-dev/wallets-shared": "^0.
|
|
32
|
+
"@rango-dev/signer-solana": "^0.29.0",
|
|
33
|
+
"@rango-dev/ui": "^0.35.0",
|
|
34
|
+
"@rango-dev/wallets-react": "^0.20.0",
|
|
35
|
+
"@rango-dev/wallets-shared": "^0.34.0",
|
|
36
36
|
"bignumber.js": "^9.1.1",
|
|
37
37
|
"copy-to-clipboard": "^3.3.3",
|
|
38
38
|
"dayjs": "^1.11.7",
|
|
@@ -53,4 +53,4 @@
|
|
|
53
53
|
"publishConfig": {
|
|
54
54
|
"access": "public"
|
|
55
55
|
}
|
|
56
|
-
}
|
|
56
|
+
}
|
|
@@ -48,7 +48,7 @@ export const QuoteContainer = styled(Collapsible.Root, {
|
|
|
48
48
|
listItem: false,
|
|
49
49
|
selected: true,
|
|
50
50
|
css: {
|
|
51
|
-
$$color: '$colors$
|
|
51
|
+
$$color: '$colors$secondary200',
|
|
52
52
|
[`.${darkTheme} &`]: {
|
|
53
53
|
$$color: '$colors$secondary800',
|
|
54
54
|
},
|
|
@@ -63,13 +63,13 @@ export const stepsDetailsStyles = css({
|
|
|
63
63
|
});
|
|
64
64
|
export const AllRoutesButton = styled(Button, {
|
|
65
65
|
backgroundColor: 'transparent',
|
|
66
|
-
border: '1px solid $
|
|
66
|
+
border: '1px solid $secondary550',
|
|
67
67
|
[`.${darkTheme} &`]: {
|
|
68
68
|
border: '1px solid $secondary',
|
|
69
69
|
},
|
|
70
70
|
transition: 'background-color 0.3s ease',
|
|
71
71
|
'&:hover': {
|
|
72
|
-
backgroundColor: '$
|
|
72
|
+
backgroundColor: '$secondary550',
|
|
73
73
|
[`.${darkTheme} &`]: {
|
|
74
74
|
backgroundColor: '$secondary',
|
|
75
75
|
},
|
|
@@ -149,7 +149,7 @@ export const SummaryContainer = styled('div', {
|
|
|
149
149
|
css: {
|
|
150
150
|
$$color: '$colors$secondary100',
|
|
151
151
|
[`.${darkTheme} &`]: {
|
|
152
|
-
$$color: '$colors$
|
|
152
|
+
$$color: '$colors$secondary550',
|
|
153
153
|
},
|
|
154
154
|
backgroundColor: '$$color',
|
|
155
155
|
'&:hover': {
|
|
@@ -262,7 +262,7 @@ export const Trigger = styled(Collapsible.Trigger, {
|
|
|
262
262
|
listItem: false,
|
|
263
263
|
selected: true,
|
|
264
264
|
css: {
|
|
265
|
-
$$color: '$colors$
|
|
265
|
+
$$color: '$colors$secondary200',
|
|
266
266
|
[`.${darkTheme} &`]: {
|
|
267
267
|
$$color: '$colors$secondary800',
|
|
268
268
|
},
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/no-magic-numbers */
|
|
2
2
|
import type { PropTypes, RenderDescProps } from './TokenList.types';
|
|
3
|
-
import type { Token } from 'rango-sdk';
|
|
3
|
+
import type { BlockchainMeta, Token } from 'rango-sdk';
|
|
4
4
|
|
|
5
5
|
import { i18n } from '@lingui/core';
|
|
6
6
|
import {
|
|
@@ -19,7 +19,7 @@ import React, { useEffect, useState } from 'react';
|
|
|
19
19
|
|
|
20
20
|
import { useAppStore } from '../../store/AppStore';
|
|
21
21
|
import { useWalletsStore } from '../../store/wallets';
|
|
22
|
-
import {
|
|
22
|
+
import { createTintsAndShades } from '../../utils/colors';
|
|
23
23
|
import { formatBalance } from '../../utils/wallets';
|
|
24
24
|
|
|
25
25
|
import { LoadingTokenList } from './LoadingTokenList';
|
|
@@ -133,25 +133,20 @@ export function TokenList(props: PropTypes) {
|
|
|
133
133
|
const address = token.address || '';
|
|
134
134
|
const blockchain = blockchains.find(
|
|
135
135
|
(blockchain) => blockchain.name === token.blockchain
|
|
136
|
-
);
|
|
137
|
-
const
|
|
138
|
-
blockchain?.color || '',
|
|
139
|
-
isBright(blockchain?.color || '') ? 5 : 125
|
|
140
|
-
);
|
|
141
|
-
const darkShade = generateShade(blockchain?.color || '', -100);
|
|
142
|
-
|
|
136
|
+
) as BlockchainMeta;
|
|
137
|
+
const colors = createTintsAndShades(blockchain.color, 'main');
|
|
143
138
|
const customCssForTag = {
|
|
144
|
-
$$color:
|
|
139
|
+
$$color: colors.main250,
|
|
145
140
|
[`.${darkTheme} &`]: {
|
|
146
|
-
$$color:
|
|
141
|
+
$$color: colors.main850,
|
|
147
142
|
},
|
|
148
143
|
backgroundColor: '$$color',
|
|
149
144
|
};
|
|
150
145
|
|
|
151
146
|
const customCssForTagTitle = {
|
|
152
|
-
$$color:
|
|
147
|
+
$$color: colors.main600,
|
|
153
148
|
[`.${darkTheme} &`]: {
|
|
154
|
-
$$color:
|
|
149
|
+
$$color: colors.main200,
|
|
155
150
|
},
|
|
156
151
|
color: '$$color',
|
|
157
152
|
};
|
package/src/types/config.ts
CHANGED
|
@@ -14,14 +14,18 @@ export type WidgetVariant = 'default' | 'expanded' | 'full-expanded';
|
|
|
14
14
|
*
|
|
15
15
|
*/
|
|
16
16
|
export type WidgetColorsKeys = keyof WidgetColors;
|
|
17
|
-
|
|
17
|
+
|
|
18
|
+
export type ThemeColors = {
|
|
19
|
+
[key in string]?: string;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export interface WidgetColors extends ThemeColors {
|
|
18
23
|
background?: string;
|
|
19
24
|
foreground?: string;
|
|
20
25
|
neutral?: string;
|
|
21
26
|
primary?: string;
|
|
22
27
|
secondary?: string;
|
|
23
|
-
|
|
24
|
-
};
|
|
28
|
+
}
|
|
25
29
|
|
|
26
30
|
/**
|
|
27
31
|
* The `WidgetTheme` defines the properties of a widget theme, including mode, font family, colors, border
|
package/src/utils/colors.ts
CHANGED
|
@@ -1,141 +1,184 @@
|
|
|
1
|
-
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-magic-numbers */
|
|
2
|
+
// Types
|
|
3
|
+
import type { ThemeColors, WidgetColors, WidgetColorsKeys } from '../types';
|
|
4
|
+
|
|
5
|
+
type RGB = {
|
|
6
|
+
red: number;
|
|
7
|
+
green: number;
|
|
8
|
+
blue: number;
|
|
9
|
+
};
|
|
2
10
|
|
|
3
|
-
|
|
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
|
|
12
|
-
|
|
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;
|
|
26
|
-
}
|
|
27
|
-
}
|
|
11
|
+
type ShadeOrTintFunction = (rgb: RGB, step: number) => RGB;
|
|
28
12
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
: shadeIncrements;
|
|
13
|
+
const HEX_BASE = 16;
|
|
14
|
+
const MAX_COLOR_VALUE = 255;
|
|
15
|
+
const PERCENT = 0.11;
|
|
33
16
|
|
|
34
|
-
|
|
17
|
+
// Utility Functions
|
|
35
18
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
19
|
+
function expandShortHexColor(hexColor: string) {
|
|
20
|
+
// Remove '#' if it exists
|
|
21
|
+
if (hexColor.startsWith('#')) {
|
|
22
|
+
hexColor = hexColor.slice(1);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// Check if the hexColor has a length of 3
|
|
26
|
+
if (hexColor.length === 3) {
|
|
27
|
+
// Convert the string to an array of characters
|
|
28
|
+
const characters = hexColor.split('');
|
|
40
29
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
30
|
+
// Duplicate each character and combine them into a single string
|
|
31
|
+
const expandedHex = characters.reduce(function (acc, char) {
|
|
32
|
+
return acc + char + char;
|
|
33
|
+
}, '');
|
|
34
|
+
|
|
35
|
+
// Return the resulting 6-character hex color
|
|
36
|
+
return `#${expandedHex}`;
|
|
45
37
|
}
|
|
46
38
|
|
|
47
|
-
|
|
39
|
+
// Return the original hexColor if it's not 3 characters
|
|
40
|
+
return `#${hexColor}`;
|
|
48
41
|
}
|
|
49
42
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
)}`;
|
|
43
|
+
/*
|
|
44
|
+
* We letting users to override some specific colors (e.g. `primary550`, `secondary100`).
|
|
45
|
+
* So we are generating a range of colors if `primary` (or other keys) has passed but if user is passing a specific color,
|
|
46
|
+
* we will override the user color to generated range.
|
|
47
|
+
*/
|
|
48
|
+
function isOverridingColor(colorKey: string): boolean {
|
|
49
|
+
return /[0-9]+$/.test(colorKey);
|
|
58
50
|
}
|
|
59
51
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
52
|
+
// pad a hexadecimal string with zeros if it needs it
|
|
53
|
+
function pad(number: string, length: number) {
|
|
54
|
+
return number.padStart(length, '0');
|
|
55
|
+
}
|
|
64
56
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
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
|
|
57
|
+
// Convert an integer to a 2-character hex string
|
|
58
|
+
function intToHex(value: number) {
|
|
59
|
+
const clampedValue = Math.min(
|
|
60
|
+
Math.max(Math.round(value), 0),
|
|
61
|
+
MAX_COLOR_VALUE
|
|
77
62
|
);
|
|
63
|
+
return pad(clampedValue.toString(HEX_BASE), 2);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// convert one of our rgb color objects to a full hex color string
|
|
67
|
+
function rgbToHex(rgb: RGB) {
|
|
68
|
+
return `#${intToHex(rgb.red)}${intToHex(rgb.green)}${intToHex(rgb.blue)}`;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// Convert a hex color string to an RGB object
|
|
72
|
+
function hexToRGB(hex: string): RGB {
|
|
73
|
+
const red = parseInt(hex.slice(1, 3), HEX_BASE);
|
|
74
|
+
const green = parseInt(hex.slice(3, 5), HEX_BASE);
|
|
75
|
+
const blue = parseInt(hex.slice(5, 7), HEX_BASE);
|
|
76
|
+
|
|
77
|
+
return { red, green, blue };
|
|
78
|
+
}
|
|
78
79
|
|
|
79
|
-
|
|
80
|
+
// Generate a shade of a given RGB color
|
|
81
|
+
function generateShade(rgb: RGB, step: number): RGB {
|
|
82
|
+
const factor = 1 - PERCENT * step;
|
|
83
|
+
return {
|
|
84
|
+
red: rgb.red * factor,
|
|
85
|
+
green: rgb.green * factor,
|
|
86
|
+
blue: rgb.blue * factor,
|
|
87
|
+
};
|
|
80
88
|
}
|
|
81
89
|
|
|
82
|
-
//
|
|
83
|
-
function
|
|
84
|
-
const
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
.slice(HEX_LENGTH)
|
|
91
|
-
.toUpperCase();
|
|
90
|
+
// Generate a tint of a given RGB color
|
|
91
|
+
function generateTint(rgb: RGB, step: number): RGB {
|
|
92
|
+
const factor = PERCENT * step;
|
|
93
|
+
return {
|
|
94
|
+
red: rgb.red + (MAX_COLOR_VALUE - rgb.red) * factor,
|
|
95
|
+
green: rgb.green + (MAX_COLOR_VALUE - rgb.green) * factor,
|
|
96
|
+
blue: rgb.blue + (MAX_COLOR_VALUE - rgb.blue) * factor,
|
|
97
|
+
};
|
|
92
98
|
}
|
|
93
99
|
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
100
|
+
// Main Functions
|
|
101
|
+
|
|
102
|
+
// Calculate an array of shades from a hex color string
|
|
103
|
+
export function calculateShades(hex: string): string[] {
|
|
104
|
+
return calculateColors(hex, generateShade);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// Calculate an array of tints from a hex color string
|
|
108
|
+
export function calculateTints(hex: string): string[] {
|
|
109
|
+
return calculateColors(hex, generateTint);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
// General function to calculate shades or tints
|
|
113
|
+
function calculateColors(
|
|
114
|
+
hex: string,
|
|
115
|
+
generateColor: ShadeOrTintFunction
|
|
116
|
+
): string[] {
|
|
117
|
+
const rgb = hexToRGB(hex);
|
|
118
|
+
const colors: string[] = [];
|
|
119
|
+
for (let i = 1; i < 9; i++) {
|
|
120
|
+
colors.push(rgbToHex(generateColor(rgb, i)));
|
|
107
121
|
}
|
|
108
|
-
return
|
|
122
|
+
return colors;
|
|
109
123
|
}
|
|
110
124
|
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
125
|
+
// Create tints and shades for a given color
|
|
126
|
+
export function createTintsAndShades(
|
|
127
|
+
hex: string,
|
|
128
|
+
colorKey: string,
|
|
129
|
+
isReversed?: boolean
|
|
130
|
+
): { [key: string]: string } {
|
|
131
|
+
const BASE_INDEX = 100;
|
|
132
|
+
const STEP = 50;
|
|
133
|
+
|
|
134
|
+
const tints = calculateTints(hex).reverse().concat(hex);
|
|
135
|
+
const shades = calculateShades(hex);
|
|
136
|
+
const combinedColors = tints.concat(shades);
|
|
137
|
+
|
|
138
|
+
const colorMap: { [key: string]: string } = {};
|
|
139
|
+
const length = combinedColors.length;
|
|
140
|
+
|
|
141
|
+
for (let i = 0; i < length; i++) {
|
|
142
|
+
const index = BASE_INDEX + (isReversed ? length - 1 - i : i) * STEP;
|
|
143
|
+
colorMap[`${colorKey}${index}`] = combinedColors[i];
|
|
118
144
|
}
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
145
|
+
|
|
146
|
+
return colorMap;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
// Generate a color palette based on base colors and "Expand Colors"
|
|
150
|
+
export function expandToGenerateThemeColors(
|
|
151
|
+
baseColors: ThemeColors,
|
|
152
|
+
expandColors: WidgetColors,
|
|
153
|
+
options?: { reverseNeutralRange?: boolean }
|
|
154
|
+
): ThemeColors {
|
|
155
|
+
const output = { ...baseColors };
|
|
156
|
+
|
|
157
|
+
for (const colorKey in expandColors) {
|
|
158
|
+
const expandColor = expandColors[colorKey as WidgetColorsKeys] as string;
|
|
159
|
+
const isNeutralReversed =
|
|
160
|
+
colorKey === 'neutral' && !!options?.reverseNeutralRange;
|
|
161
|
+
/*
|
|
162
|
+
*Most of the colors are range but there are some colors that should be a single value e.g.
|
|
163
|
+
*{
|
|
164
|
+
* // single value
|
|
165
|
+
* background: "#fff",
|
|
166
|
+
* // range
|
|
167
|
+
* primary: '#1C3CF1',
|
|
168
|
+
* primary500: '#1C3CF1',
|
|
169
|
+
* primary550: '#0B27C4',
|
|
170
|
+
*}
|
|
171
|
+
*/
|
|
172
|
+
const isSingleColor = ['background', 'foreground'].includes(colorKey);
|
|
173
|
+
|
|
174
|
+
if (!isSingleColor && !isOverridingColor(colorKey)) {
|
|
175
|
+
const expandedHexColor = expandShortHexColor(expandColor);
|
|
176
|
+
Object.assign(
|
|
177
|
+
output,
|
|
178
|
+
createTintsAndShades(expandedHexColor, colorKey, isNeutralReversed)
|
|
179
|
+
);
|
|
138
180
|
}
|
|
139
181
|
}
|
|
140
|
-
|
|
141
|
-
};
|
|
182
|
+
|
|
183
|
+
return { ...output, ...expandColors };
|
|
184
|
+
}
|
package/src/utils/ui.ts
CHANGED
|
@@ -8,14 +8,15 @@ import {
|
|
|
8
8
|
} from '@rango-dev/ui';
|
|
9
9
|
import React from 'react';
|
|
10
10
|
|
|
11
|
-
import {
|
|
11
|
+
import { expandToGenerateThemeColors } from '../utils/colors';
|
|
12
12
|
import { toHash } from '../utils/hash';
|
|
13
13
|
|
|
14
14
|
import { THEME_CLASS_NAME_PREFIX } from './configs';
|
|
15
15
|
|
|
16
|
+
type Tokens = Parameters<typeof createTheme>[0];
|
|
16
17
|
interface CustomizedThemeValues {
|
|
17
18
|
id: string;
|
|
18
|
-
tokens:
|
|
19
|
+
tokens: Tokens;
|
|
19
20
|
}
|
|
20
21
|
|
|
21
22
|
interface CustomizedTheme {
|
|
@@ -27,48 +28,42 @@ export function customizedThemeTokens(
|
|
|
27
28
|
colors: WidgetTheme['colors']
|
|
28
29
|
): CustomizedTheme {
|
|
29
30
|
const baseColors = baseThemeTokens.colors;
|
|
31
|
+
const baseDarkColors = {
|
|
32
|
+
...baseColors,
|
|
33
|
+
...defaultDarkColors,
|
|
34
|
+
};
|
|
35
|
+
let lightTheme: CustomizedTheme['light'] = undefined;
|
|
36
|
+
let darkTheme: CustomizedTheme['dark'] = undefined;
|
|
30
37
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
...defaultDarkColors,
|
|
35
|
-
},
|
|
36
|
-
true,
|
|
37
|
-
colors?.dark
|
|
38
|
-
);
|
|
39
|
-
const lightColorsWithDefaults = generateColors(
|
|
40
|
-
baseColors,
|
|
41
|
-
false,
|
|
42
|
-
colors?.light
|
|
43
|
-
);
|
|
44
|
-
const hasDefaultDarkColors = Object.keys(darkColorsWithDefaults).length > 0;
|
|
45
|
-
const hasDefaultLightColors = Object.keys(lightColorsWithDefaults).length > 0;
|
|
46
|
-
|
|
47
|
-
let light: CustomizedTheme['light'] = undefined;
|
|
48
|
-
let dark: CustomizedTheme['dark'] = undefined;
|
|
49
|
-
|
|
50
|
-
if (hasDefaultLightColors) {
|
|
51
|
-
const tokens = { colors: lightColorsWithDefaults };
|
|
38
|
+
if (colors?.light) {
|
|
39
|
+
const lightColors = expandToGenerateThemeColors(baseColors, colors.light);
|
|
40
|
+
const tokens = { colors: lightColors };
|
|
52
41
|
const id = `${THEME_CLASS_NAME_PREFIX}-light-${toHash(tokens)}`;
|
|
53
|
-
|
|
42
|
+
lightTheme = {
|
|
54
43
|
id,
|
|
55
|
-
tokens,
|
|
44
|
+
tokens: tokens as Tokens,
|
|
56
45
|
};
|
|
57
46
|
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
47
|
+
|
|
48
|
+
if (colors?.dark) {
|
|
49
|
+
const darkColors = expandToGenerateThemeColors(
|
|
50
|
+
baseDarkColors,
|
|
51
|
+
colors.dark,
|
|
52
|
+
{
|
|
53
|
+
reverseNeutralRange: true,
|
|
54
|
+
}
|
|
55
|
+
);
|
|
56
|
+
const tokens = { colors: darkColors };
|
|
62
57
|
const id = `${THEME_CLASS_NAME_PREFIX}-dark-${toHash(tokens)}`;
|
|
63
|
-
|
|
58
|
+
darkTheme = {
|
|
64
59
|
id,
|
|
65
|
-
tokens,
|
|
60
|
+
tokens: tokens as Tokens,
|
|
66
61
|
};
|
|
67
62
|
}
|
|
68
63
|
|
|
69
64
|
return {
|
|
70
|
-
light,
|
|
71
|
-
dark,
|
|
65
|
+
light: lightTheme,
|
|
66
|
+
dark: darkTheme,
|
|
72
67
|
};
|
|
73
68
|
}
|
|
74
69
|
|