@0xsquid/ui 0.9.4 → 0.9.5
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/cjs/index.js +73 -75
- package/dist/cjs/types/providers/SquidConfigProvider.d.ts +1 -1
- package/dist/cjs/types/services/internal/colorService.d.ts +16 -1
- package/dist/cjs/types/types/config.d.ts +23 -16
- package/dist/esm/index.js +73 -75
- package/dist/esm/types/providers/SquidConfigProvider.d.ts +1 -1
- package/dist/esm/types/services/internal/colorService.d.ts +16 -1
- package/dist/esm/types/types/config.d.ts +23 -16
- package/dist/index.d.ts +19 -33
- package/package.json +1 -1
package/dist/cjs/index.js
CHANGED
|
@@ -2680,12 +2680,6 @@ const SQUID_THEME_CSS_VARIABLE_PREFIX = '--squid-theme-';
|
|
|
2680
2680
|
* Mapping between readable variables name and css variables used TailwindCSS config
|
|
2681
2681
|
*/
|
|
2682
2682
|
const themeTypesKeys = {
|
|
2683
|
-
'accent-gold': {
|
|
2684
|
-
cssVariable: `${SQUID_THEME_CSS_VARIABLE_PREFIX}accent-gold`,
|
|
2685
|
-
},
|
|
2686
|
-
'accent-salmon': {
|
|
2687
|
-
cssVariable: `${SQUID_THEME_CSS_VARIABLE_PREFIX}accent-salmon`,
|
|
2688
|
-
},
|
|
2689
2683
|
'grey-100': {
|
|
2690
2684
|
cssVariable: `${SQUID_THEME_CSS_VARIABLE_PREFIX}grey-100`,
|
|
2691
2685
|
},
|
|
@@ -2731,54 +2725,18 @@ const themeTypesKeys = {
|
|
|
2731
2725
|
'material-light-thin': {
|
|
2732
2726
|
cssVariable: `${SQUID_THEME_CSS_VARIABLE_PREFIX}material-light-thin`,
|
|
2733
2727
|
},
|
|
2734
|
-
'royal-100': {
|
|
2735
|
-
cssVariable: `${SQUID_THEME_CSS_VARIABLE_PREFIX}royal-100`,
|
|
2736
|
-
},
|
|
2737
|
-
'royal-200': {
|
|
2738
|
-
cssVariable: `${SQUID_THEME_CSS_VARIABLE_PREFIX}royal-200`,
|
|
2739
|
-
},
|
|
2740
|
-
'royal-300': {
|
|
2741
|
-
cssVariable: `${SQUID_THEME_CSS_VARIABLE_PREFIX}royal-300`,
|
|
2742
|
-
},
|
|
2743
2728
|
'royal-400': {
|
|
2744
2729
|
cssVariable: `${SQUID_THEME_CSS_VARIABLE_PREFIX}royal-400`,
|
|
2745
2730
|
},
|
|
2746
2731
|
'royal-500': {
|
|
2747
2732
|
cssVariable: `${SQUID_THEME_CSS_VARIABLE_PREFIX}royal-500`,
|
|
2748
2733
|
},
|
|
2749
|
-
'royal-600': {
|
|
2750
|
-
cssVariable: `${SQUID_THEME_CSS_VARIABLE_PREFIX}royal-600`,
|
|
2751
|
-
},
|
|
2752
|
-
'royal-700': {
|
|
2753
|
-
cssVariable: `${SQUID_THEME_CSS_VARIABLE_PREFIX}royal-700`,
|
|
2754
|
-
},
|
|
2755
|
-
'royal-800': {
|
|
2756
|
-
cssVariable: `${SQUID_THEME_CSS_VARIABLE_PREFIX}royal-800`,
|
|
2757
|
-
},
|
|
2758
2734
|
'status-negative': {
|
|
2759
2735
|
cssVariable: `${SQUID_THEME_CSS_VARIABLE_PREFIX}status-negative`,
|
|
2760
2736
|
},
|
|
2761
2737
|
'status-positive': {
|
|
2762
2738
|
cssVariable: `${SQUID_THEME_CSS_VARIABLE_PREFIX}status-positive`,
|
|
2763
2739
|
},
|
|
2764
|
-
'volt-300': {
|
|
2765
|
-
cssVariable: `${SQUID_THEME_CSS_VARIABLE_PREFIX}volt-300`,
|
|
2766
|
-
},
|
|
2767
|
-
'volt-400': {
|
|
2768
|
-
cssVariable: `${SQUID_THEME_CSS_VARIABLE_PREFIX}volt-400`,
|
|
2769
|
-
},
|
|
2770
|
-
'volt-600': {
|
|
2771
|
-
cssVariable: `${SQUID_THEME_CSS_VARIABLE_PREFIX}volt-600`,
|
|
2772
|
-
},
|
|
2773
|
-
'volt-700': {
|
|
2774
|
-
cssVariable: `${SQUID_THEME_CSS_VARIABLE_PREFIX}volt-700`,
|
|
2775
|
-
},
|
|
2776
|
-
'volt-800': {
|
|
2777
|
-
cssVariable: `${SQUID_THEME_CSS_VARIABLE_PREFIX}volt-800`,
|
|
2778
|
-
},
|
|
2779
|
-
'volt-900': {
|
|
2780
|
-
cssVariable: `${SQUID_THEME_CSS_VARIABLE_PREFIX}volt-900`,
|
|
2781
|
-
},
|
|
2782
2740
|
};
|
|
2783
2741
|
|
|
2784
2742
|
function PlusIcon() {
|
|
@@ -3501,42 +3459,82 @@ function TokenPair({ firstToken, secondToken }) {
|
|
|
3501
3459
|
}, children: [jsxRuntime.jsx("img", { className: "tw-ml-[1px] tw-aspect-square tw-w-10", src: firstToken.imageUrl }), jsxRuntime.jsx("img", { className: "tw-mr-[1px] tw-aspect-square tw-w-10", src: secondToken.imageUrl })] })] }));
|
|
3502
3460
|
}
|
|
3503
3461
|
|
|
3462
|
+
const themeKeysToReplace = [
|
|
3463
|
+
{
|
|
3464
|
+
userKey: 'content',
|
|
3465
|
+
internalKey: 'grey',
|
|
3466
|
+
},
|
|
3467
|
+
{
|
|
3468
|
+
userKey: 'accent',
|
|
3469
|
+
internalKey: 'royal',
|
|
3470
|
+
},
|
|
3471
|
+
{
|
|
3472
|
+
userKey: 'transparent',
|
|
3473
|
+
internalKey: 'material',
|
|
3474
|
+
},
|
|
3475
|
+
];
|
|
3504
3476
|
/**
|
|
3505
3477
|
* Parsing the user readable config to css variables
|
|
3478
|
+
* Also maps the public theme variables to the internal theme variables
|
|
3479
|
+
* example user theme:
|
|
3480
|
+
* {
|
|
3481
|
+
* 'content-100': '#000',
|
|
3482
|
+
* 'content-200': '#000',
|
|
3483
|
+
* 'accent-400': '#000',
|
|
3484
|
+
* 'transparent-light-thin': '#000'
|
|
3485
|
+
* }
|
|
3486
|
+
* Resulting in:
|
|
3487
|
+
* {
|
|
3488
|
+
* 'grey-100': '#000',
|
|
3489
|
+
* 'grey-200': '#000',
|
|
3490
|
+
* 'royal-400': '#000',
|
|
3491
|
+
* 'material-light-thin': '#000'
|
|
3492
|
+
* }
|
|
3506
3493
|
* @param style
|
|
3507
3494
|
*/
|
|
3508
|
-
const
|
|
3509
|
-
if (
|
|
3510
|
-
|
|
3511
|
-
|
|
3512
|
-
|
|
3513
|
-
|
|
3514
|
-
|
|
3515
|
-
|
|
3516
|
-
|
|
3517
|
-
|
|
3518
|
-
|
|
3519
|
-
|
|
3520
|
-
|
|
3521
|
-
|
|
3522
|
-
|
|
3523
|
-
|
|
3524
|
-
|
|
3525
|
-
|
|
3526
|
-
|
|
3527
|
-
|
|
3528
|
-
|
|
3529
|
-
|
|
3530
|
-
|
|
3531
|
-
|
|
3532
|
-
|
|
3533
|
-
|
|
3534
|
-
|
|
3535
|
-
|
|
3536
|
-
|
|
3537
|
-
|
|
3538
|
-
|
|
3539
|
-
}
|
|
3495
|
+
const parseSquidTheme = (userTheme) => {
|
|
3496
|
+
if (!userTheme)
|
|
3497
|
+
return undefined;
|
|
3498
|
+
const squidTheme = Object.entries(userTheme).reduce((internalKeys, [userKey, userValue]) => {
|
|
3499
|
+
// content-* -> grey-*
|
|
3500
|
+
// accent-* -> royal-*
|
|
3501
|
+
// transparent-* -> material-*
|
|
3502
|
+
const keyToReplace = themeKeysToReplace.find((k) => userKey.includes(k.userKey));
|
|
3503
|
+
if (keyToReplace) {
|
|
3504
|
+
const newKey = userKey.replace(keyToReplace.userKey, keyToReplace.internalKey);
|
|
3505
|
+
internalKeys[newKey] = userValue;
|
|
3506
|
+
}
|
|
3507
|
+
return internalKeys;
|
|
3508
|
+
}, {});
|
|
3509
|
+
const styleKeys = Object.keys(themeTypesKeys);
|
|
3510
|
+
const parsed = styleKeys.map((sk) => {
|
|
3511
|
+
const themeItem = themeTypesKeys[sk];
|
|
3512
|
+
let userValue = squidTheme[sk];
|
|
3513
|
+
return {
|
|
3514
|
+
[themeItem.cssVariable]: userValue,
|
|
3515
|
+
};
|
|
3516
|
+
});
|
|
3517
|
+
// adds a variant with 0.05 opacity for each color
|
|
3518
|
+
// will result in variables like this:
|
|
3519
|
+
// var(--squid-theme-grey-100-005) --> grey-100 with 0.05 opacity
|
|
3520
|
+
// styleKeys.forEach((sk) => {
|
|
3521
|
+
// const themeItem = themeTypesKeys[sk]
|
|
3522
|
+
// const valueWith005Opacity = getHexColorFromOpacityPercentage(
|
|
3523
|
+
// style[sk], // i.e "#ffffff"
|
|
3524
|
+
// 0.05,
|
|
3525
|
+
// )
|
|
3526
|
+
// // { "--squid-theme-grey-100-005": "#ffffff80" }
|
|
3527
|
+
// parsed.push({
|
|
3528
|
+
// [`${themeItem.cssVariable}-005`]: valueWith005Opacity,
|
|
3529
|
+
// })
|
|
3530
|
+
// })
|
|
3531
|
+
parsed.push({
|
|
3532
|
+
[`${themeTypesKeys['grey-100'].cssVariable}-005`]: getHexColorFromOpacityPercentage(squidTheme['grey-100'], 0.05),
|
|
3533
|
+
});
|
|
3534
|
+
return parsed.reduce((a, v) => {
|
|
3535
|
+
const key = Object.keys(v)[0];
|
|
3536
|
+
return Object.assign(Object.assign({}, a), { [key]: v[key] });
|
|
3537
|
+
});
|
|
3540
3538
|
};
|
|
3541
3539
|
/**
|
|
3542
3540
|
* Returns a hexadecimal color with opacity based on the given color and opacity percentage.
|
|
@@ -3555,7 +3553,7 @@ function getHexColorFromOpacityPercentage(color, opacity) {
|
|
|
3555
3553
|
}
|
|
3556
3554
|
|
|
3557
3555
|
function SquidConfigProvider({ theme, children, themeType = 'light', }) {
|
|
3558
|
-
const parsedStyle =
|
|
3556
|
+
const parsedStyle = parseSquidTheme(theme);
|
|
3559
3557
|
return (jsxRuntime.jsx("div", { style: parsedStyle, "data-squid-theme-type": themeType, className: "tw-group tw-relative tw-font-geist", children: children }));
|
|
3560
3558
|
}
|
|
3561
3559
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
-
import { SquidTheme } from '../types/config';
|
|
3
2
|
import { ThemeType } from '../types/components';
|
|
3
|
+
import { SquidTheme } from '../types/config';
|
|
4
4
|
export declare function SquidConfigProvider({ theme, children, themeType, }: {
|
|
5
5
|
theme: SquidTheme;
|
|
6
6
|
children?: React.ReactNode;
|
|
@@ -1,9 +1,24 @@
|
|
|
1
1
|
import { SquidTheme } from '../../types/config';
|
|
2
2
|
/**
|
|
3
3
|
* Parsing the user readable config to css variables
|
|
4
|
+
* Also maps the public theme variables to the internal theme variables
|
|
5
|
+
* example user theme:
|
|
6
|
+
* {
|
|
7
|
+
* 'content-100': '#000',
|
|
8
|
+
* 'content-200': '#000',
|
|
9
|
+
* 'accent-400': '#000',
|
|
10
|
+
* 'transparent-light-thin': '#000'
|
|
11
|
+
* }
|
|
12
|
+
* Resulting in:
|
|
13
|
+
* {
|
|
14
|
+
* 'grey-100': '#000',
|
|
15
|
+
* 'grey-200': '#000',
|
|
16
|
+
* 'royal-400': '#000',
|
|
17
|
+
* 'material-light-thin': '#000'
|
|
18
|
+
* }
|
|
4
19
|
* @param style
|
|
5
20
|
*/
|
|
6
|
-
export declare const
|
|
21
|
+
export declare const parseSquidTheme: (userTheme?: SquidTheme) => {
|
|
7
22
|
[key: string]: string | undefined;
|
|
8
23
|
} | undefined;
|
|
9
24
|
export declare function getContrastColor({ r, g, b, }: {
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* The color format must be of type #FFFFFF
|
|
3
3
|
*/
|
|
4
4
|
export type ColorType = `#${string}${string}${string}${string}${string}${string}`;
|
|
5
|
-
export interface
|
|
5
|
+
export interface InternalSquidTheme {
|
|
6
6
|
'grey-100': string;
|
|
7
7
|
'grey-200': string;
|
|
8
8
|
'grey-300': string;
|
|
@@ -12,14 +12,8 @@ export interface SquidTheme {
|
|
|
12
12
|
'grey-700': string;
|
|
13
13
|
'grey-800': string;
|
|
14
14
|
'grey-900': string;
|
|
15
|
-
'royal-100': string;
|
|
16
|
-
'royal-200': string;
|
|
17
|
-
'royal-300': string;
|
|
18
15
|
'royal-400': string;
|
|
19
16
|
'royal-500': string;
|
|
20
|
-
'royal-600': string;
|
|
21
|
-
'royal-700': string;
|
|
22
|
-
'royal-800': string;
|
|
23
17
|
'status-positive': string;
|
|
24
18
|
'status-negative': string;
|
|
25
19
|
'material-light-thin': string;
|
|
@@ -28,19 +22,32 @@ export interface SquidTheme {
|
|
|
28
22
|
'material-dark-thin': string;
|
|
29
23
|
'material-dark-average': string;
|
|
30
24
|
'material-dark-thick': string;
|
|
31
|
-
'volt-300': string;
|
|
32
|
-
'volt-400': string;
|
|
33
|
-
'volt-600': string;
|
|
34
|
-
'volt-700': string;
|
|
35
|
-
'volt-800': string;
|
|
36
|
-
'volt-900': string;
|
|
37
|
-
'accent-salmon': string;
|
|
38
|
-
'accent-gold': string;
|
|
39
25
|
}
|
|
26
|
+
export type SquidTheme = {
|
|
27
|
+
'content-100': string;
|
|
28
|
+
'content-200': string;
|
|
29
|
+
'content-300': string;
|
|
30
|
+
'content-400': string;
|
|
31
|
+
'content-500': string;
|
|
32
|
+
'content-600': string;
|
|
33
|
+
'content-700': string;
|
|
34
|
+
'content-800': string;
|
|
35
|
+
'content-900': string;
|
|
36
|
+
'accent-400': string;
|
|
37
|
+
'accent-500': string;
|
|
38
|
+
'status-positive': string;
|
|
39
|
+
'status-negative': string;
|
|
40
|
+
'transparent-light-thin': string;
|
|
41
|
+
'transparent-light-average': string;
|
|
42
|
+
'transparent-light-thick': string;
|
|
43
|
+
'transparent-dark-thin': string;
|
|
44
|
+
'transparent-dark-average': string;
|
|
45
|
+
'transparent-dark-thick': string;
|
|
46
|
+
};
|
|
40
47
|
export declare const SQUID_THEME_CSS_VARIABLE_PREFIX = "--squid-theme-";
|
|
41
48
|
/**
|
|
42
49
|
* Mapping between readable variables name and css variables used TailwindCSS config
|
|
43
50
|
*/
|
|
44
|
-
export declare const themeTypesKeys: Record<keyof
|
|
51
|
+
export declare const themeTypesKeys: Record<keyof InternalSquidTheme, {
|
|
45
52
|
cssVariable: string;
|
|
46
53
|
}>;
|
package/dist/esm/index.js
CHANGED
|
@@ -2678,12 +2678,6 @@ const SQUID_THEME_CSS_VARIABLE_PREFIX = '--squid-theme-';
|
|
|
2678
2678
|
* Mapping between readable variables name and css variables used TailwindCSS config
|
|
2679
2679
|
*/
|
|
2680
2680
|
const themeTypesKeys = {
|
|
2681
|
-
'accent-gold': {
|
|
2682
|
-
cssVariable: `${SQUID_THEME_CSS_VARIABLE_PREFIX}accent-gold`,
|
|
2683
|
-
},
|
|
2684
|
-
'accent-salmon': {
|
|
2685
|
-
cssVariable: `${SQUID_THEME_CSS_VARIABLE_PREFIX}accent-salmon`,
|
|
2686
|
-
},
|
|
2687
2681
|
'grey-100': {
|
|
2688
2682
|
cssVariable: `${SQUID_THEME_CSS_VARIABLE_PREFIX}grey-100`,
|
|
2689
2683
|
},
|
|
@@ -2729,54 +2723,18 @@ const themeTypesKeys = {
|
|
|
2729
2723
|
'material-light-thin': {
|
|
2730
2724
|
cssVariable: `${SQUID_THEME_CSS_VARIABLE_PREFIX}material-light-thin`,
|
|
2731
2725
|
},
|
|
2732
|
-
'royal-100': {
|
|
2733
|
-
cssVariable: `${SQUID_THEME_CSS_VARIABLE_PREFIX}royal-100`,
|
|
2734
|
-
},
|
|
2735
|
-
'royal-200': {
|
|
2736
|
-
cssVariable: `${SQUID_THEME_CSS_VARIABLE_PREFIX}royal-200`,
|
|
2737
|
-
},
|
|
2738
|
-
'royal-300': {
|
|
2739
|
-
cssVariable: `${SQUID_THEME_CSS_VARIABLE_PREFIX}royal-300`,
|
|
2740
|
-
},
|
|
2741
2726
|
'royal-400': {
|
|
2742
2727
|
cssVariable: `${SQUID_THEME_CSS_VARIABLE_PREFIX}royal-400`,
|
|
2743
2728
|
},
|
|
2744
2729
|
'royal-500': {
|
|
2745
2730
|
cssVariable: `${SQUID_THEME_CSS_VARIABLE_PREFIX}royal-500`,
|
|
2746
2731
|
},
|
|
2747
|
-
'royal-600': {
|
|
2748
|
-
cssVariable: `${SQUID_THEME_CSS_VARIABLE_PREFIX}royal-600`,
|
|
2749
|
-
},
|
|
2750
|
-
'royal-700': {
|
|
2751
|
-
cssVariable: `${SQUID_THEME_CSS_VARIABLE_PREFIX}royal-700`,
|
|
2752
|
-
},
|
|
2753
|
-
'royal-800': {
|
|
2754
|
-
cssVariable: `${SQUID_THEME_CSS_VARIABLE_PREFIX}royal-800`,
|
|
2755
|
-
},
|
|
2756
2732
|
'status-negative': {
|
|
2757
2733
|
cssVariable: `${SQUID_THEME_CSS_VARIABLE_PREFIX}status-negative`,
|
|
2758
2734
|
},
|
|
2759
2735
|
'status-positive': {
|
|
2760
2736
|
cssVariable: `${SQUID_THEME_CSS_VARIABLE_PREFIX}status-positive`,
|
|
2761
2737
|
},
|
|
2762
|
-
'volt-300': {
|
|
2763
|
-
cssVariable: `${SQUID_THEME_CSS_VARIABLE_PREFIX}volt-300`,
|
|
2764
|
-
},
|
|
2765
|
-
'volt-400': {
|
|
2766
|
-
cssVariable: `${SQUID_THEME_CSS_VARIABLE_PREFIX}volt-400`,
|
|
2767
|
-
},
|
|
2768
|
-
'volt-600': {
|
|
2769
|
-
cssVariable: `${SQUID_THEME_CSS_VARIABLE_PREFIX}volt-600`,
|
|
2770
|
-
},
|
|
2771
|
-
'volt-700': {
|
|
2772
|
-
cssVariable: `${SQUID_THEME_CSS_VARIABLE_PREFIX}volt-700`,
|
|
2773
|
-
},
|
|
2774
|
-
'volt-800': {
|
|
2775
|
-
cssVariable: `${SQUID_THEME_CSS_VARIABLE_PREFIX}volt-800`,
|
|
2776
|
-
},
|
|
2777
|
-
'volt-900': {
|
|
2778
|
-
cssVariable: `${SQUID_THEME_CSS_VARIABLE_PREFIX}volt-900`,
|
|
2779
|
-
},
|
|
2780
2738
|
};
|
|
2781
2739
|
|
|
2782
2740
|
function PlusIcon() {
|
|
@@ -3499,42 +3457,82 @@ function TokenPair({ firstToken, secondToken }) {
|
|
|
3499
3457
|
}, children: [jsx("img", { className: "tw-ml-[1px] tw-aspect-square tw-w-10", src: firstToken.imageUrl }), jsx("img", { className: "tw-mr-[1px] tw-aspect-square tw-w-10", src: secondToken.imageUrl })] })] }));
|
|
3500
3458
|
}
|
|
3501
3459
|
|
|
3460
|
+
const themeKeysToReplace = [
|
|
3461
|
+
{
|
|
3462
|
+
userKey: 'content',
|
|
3463
|
+
internalKey: 'grey',
|
|
3464
|
+
},
|
|
3465
|
+
{
|
|
3466
|
+
userKey: 'accent',
|
|
3467
|
+
internalKey: 'royal',
|
|
3468
|
+
},
|
|
3469
|
+
{
|
|
3470
|
+
userKey: 'transparent',
|
|
3471
|
+
internalKey: 'material',
|
|
3472
|
+
},
|
|
3473
|
+
];
|
|
3502
3474
|
/**
|
|
3503
3475
|
* Parsing the user readable config to css variables
|
|
3476
|
+
* Also maps the public theme variables to the internal theme variables
|
|
3477
|
+
* example user theme:
|
|
3478
|
+
* {
|
|
3479
|
+
* 'content-100': '#000',
|
|
3480
|
+
* 'content-200': '#000',
|
|
3481
|
+
* 'accent-400': '#000',
|
|
3482
|
+
* 'transparent-light-thin': '#000'
|
|
3483
|
+
* }
|
|
3484
|
+
* Resulting in:
|
|
3485
|
+
* {
|
|
3486
|
+
* 'grey-100': '#000',
|
|
3487
|
+
* 'grey-200': '#000',
|
|
3488
|
+
* 'royal-400': '#000',
|
|
3489
|
+
* 'material-light-thin': '#000'
|
|
3490
|
+
* }
|
|
3504
3491
|
* @param style
|
|
3505
3492
|
*/
|
|
3506
|
-
const
|
|
3507
|
-
if (
|
|
3508
|
-
|
|
3509
|
-
|
|
3510
|
-
|
|
3511
|
-
|
|
3512
|
-
|
|
3513
|
-
|
|
3514
|
-
|
|
3515
|
-
|
|
3516
|
-
|
|
3517
|
-
|
|
3518
|
-
|
|
3519
|
-
|
|
3520
|
-
|
|
3521
|
-
|
|
3522
|
-
|
|
3523
|
-
|
|
3524
|
-
|
|
3525
|
-
|
|
3526
|
-
|
|
3527
|
-
|
|
3528
|
-
|
|
3529
|
-
|
|
3530
|
-
|
|
3531
|
-
|
|
3532
|
-
|
|
3533
|
-
|
|
3534
|
-
|
|
3535
|
-
|
|
3536
|
-
|
|
3537
|
-
}
|
|
3493
|
+
const parseSquidTheme = (userTheme) => {
|
|
3494
|
+
if (!userTheme)
|
|
3495
|
+
return undefined;
|
|
3496
|
+
const squidTheme = Object.entries(userTheme).reduce((internalKeys, [userKey, userValue]) => {
|
|
3497
|
+
// content-* -> grey-*
|
|
3498
|
+
// accent-* -> royal-*
|
|
3499
|
+
// transparent-* -> material-*
|
|
3500
|
+
const keyToReplace = themeKeysToReplace.find((k) => userKey.includes(k.userKey));
|
|
3501
|
+
if (keyToReplace) {
|
|
3502
|
+
const newKey = userKey.replace(keyToReplace.userKey, keyToReplace.internalKey);
|
|
3503
|
+
internalKeys[newKey] = userValue;
|
|
3504
|
+
}
|
|
3505
|
+
return internalKeys;
|
|
3506
|
+
}, {});
|
|
3507
|
+
const styleKeys = Object.keys(themeTypesKeys);
|
|
3508
|
+
const parsed = styleKeys.map((sk) => {
|
|
3509
|
+
const themeItem = themeTypesKeys[sk];
|
|
3510
|
+
let userValue = squidTheme[sk];
|
|
3511
|
+
return {
|
|
3512
|
+
[themeItem.cssVariable]: userValue,
|
|
3513
|
+
};
|
|
3514
|
+
});
|
|
3515
|
+
// adds a variant with 0.05 opacity for each color
|
|
3516
|
+
// will result in variables like this:
|
|
3517
|
+
// var(--squid-theme-grey-100-005) --> grey-100 with 0.05 opacity
|
|
3518
|
+
// styleKeys.forEach((sk) => {
|
|
3519
|
+
// const themeItem = themeTypesKeys[sk]
|
|
3520
|
+
// const valueWith005Opacity = getHexColorFromOpacityPercentage(
|
|
3521
|
+
// style[sk], // i.e "#ffffff"
|
|
3522
|
+
// 0.05,
|
|
3523
|
+
// )
|
|
3524
|
+
// // { "--squid-theme-grey-100-005": "#ffffff80" }
|
|
3525
|
+
// parsed.push({
|
|
3526
|
+
// [`${themeItem.cssVariable}-005`]: valueWith005Opacity,
|
|
3527
|
+
// })
|
|
3528
|
+
// })
|
|
3529
|
+
parsed.push({
|
|
3530
|
+
[`${themeTypesKeys['grey-100'].cssVariable}-005`]: getHexColorFromOpacityPercentage(squidTheme['grey-100'], 0.05),
|
|
3531
|
+
});
|
|
3532
|
+
return parsed.reduce((a, v) => {
|
|
3533
|
+
const key = Object.keys(v)[0];
|
|
3534
|
+
return Object.assign(Object.assign({}, a), { [key]: v[key] });
|
|
3535
|
+
});
|
|
3538
3536
|
};
|
|
3539
3537
|
/**
|
|
3540
3538
|
* Returns a hexadecimal color with opacity based on the given color and opacity percentage.
|
|
@@ -3553,7 +3551,7 @@ function getHexColorFromOpacityPercentage(color, opacity) {
|
|
|
3553
3551
|
}
|
|
3554
3552
|
|
|
3555
3553
|
function SquidConfigProvider({ theme, children, themeType = 'light', }) {
|
|
3556
|
-
const parsedStyle =
|
|
3554
|
+
const parsedStyle = parseSquidTheme(theme);
|
|
3557
3555
|
return (jsx("div", { style: parsedStyle, "data-squid-theme-type": themeType, className: "tw-group tw-relative tw-font-geist", children: children }));
|
|
3558
3556
|
}
|
|
3559
3557
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
-
import { SquidTheme } from '../types/config';
|
|
3
2
|
import { ThemeType } from '../types/components';
|
|
3
|
+
import { SquidTheme } from '../types/config';
|
|
4
4
|
export declare function SquidConfigProvider({ theme, children, themeType, }: {
|
|
5
5
|
theme: SquidTheme;
|
|
6
6
|
children?: React.ReactNode;
|
|
@@ -1,9 +1,24 @@
|
|
|
1
1
|
import { SquidTheme } from '../../types/config';
|
|
2
2
|
/**
|
|
3
3
|
* Parsing the user readable config to css variables
|
|
4
|
+
* Also maps the public theme variables to the internal theme variables
|
|
5
|
+
* example user theme:
|
|
6
|
+
* {
|
|
7
|
+
* 'content-100': '#000',
|
|
8
|
+
* 'content-200': '#000',
|
|
9
|
+
* 'accent-400': '#000',
|
|
10
|
+
* 'transparent-light-thin': '#000'
|
|
11
|
+
* }
|
|
12
|
+
* Resulting in:
|
|
13
|
+
* {
|
|
14
|
+
* 'grey-100': '#000',
|
|
15
|
+
* 'grey-200': '#000',
|
|
16
|
+
* 'royal-400': '#000',
|
|
17
|
+
* 'material-light-thin': '#000'
|
|
18
|
+
* }
|
|
4
19
|
* @param style
|
|
5
20
|
*/
|
|
6
|
-
export declare const
|
|
21
|
+
export declare const parseSquidTheme: (userTheme?: SquidTheme) => {
|
|
7
22
|
[key: string]: string | undefined;
|
|
8
23
|
} | undefined;
|
|
9
24
|
export declare function getContrastColor({ r, g, b, }: {
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* The color format must be of type #FFFFFF
|
|
3
3
|
*/
|
|
4
4
|
export type ColorType = `#${string}${string}${string}${string}${string}${string}`;
|
|
5
|
-
export interface
|
|
5
|
+
export interface InternalSquidTheme {
|
|
6
6
|
'grey-100': string;
|
|
7
7
|
'grey-200': string;
|
|
8
8
|
'grey-300': string;
|
|
@@ -12,14 +12,8 @@ export interface SquidTheme {
|
|
|
12
12
|
'grey-700': string;
|
|
13
13
|
'grey-800': string;
|
|
14
14
|
'grey-900': string;
|
|
15
|
-
'royal-100': string;
|
|
16
|
-
'royal-200': string;
|
|
17
|
-
'royal-300': string;
|
|
18
15
|
'royal-400': string;
|
|
19
16
|
'royal-500': string;
|
|
20
|
-
'royal-600': string;
|
|
21
|
-
'royal-700': string;
|
|
22
|
-
'royal-800': string;
|
|
23
17
|
'status-positive': string;
|
|
24
18
|
'status-negative': string;
|
|
25
19
|
'material-light-thin': string;
|
|
@@ -28,19 +22,32 @@ export interface SquidTheme {
|
|
|
28
22
|
'material-dark-thin': string;
|
|
29
23
|
'material-dark-average': string;
|
|
30
24
|
'material-dark-thick': string;
|
|
31
|
-
'volt-300': string;
|
|
32
|
-
'volt-400': string;
|
|
33
|
-
'volt-600': string;
|
|
34
|
-
'volt-700': string;
|
|
35
|
-
'volt-800': string;
|
|
36
|
-
'volt-900': string;
|
|
37
|
-
'accent-salmon': string;
|
|
38
|
-
'accent-gold': string;
|
|
39
25
|
}
|
|
26
|
+
export type SquidTheme = {
|
|
27
|
+
'content-100': string;
|
|
28
|
+
'content-200': string;
|
|
29
|
+
'content-300': string;
|
|
30
|
+
'content-400': string;
|
|
31
|
+
'content-500': string;
|
|
32
|
+
'content-600': string;
|
|
33
|
+
'content-700': string;
|
|
34
|
+
'content-800': string;
|
|
35
|
+
'content-900': string;
|
|
36
|
+
'accent-400': string;
|
|
37
|
+
'accent-500': string;
|
|
38
|
+
'status-positive': string;
|
|
39
|
+
'status-negative': string;
|
|
40
|
+
'transparent-light-thin': string;
|
|
41
|
+
'transparent-light-average': string;
|
|
42
|
+
'transparent-light-thick': string;
|
|
43
|
+
'transparent-dark-thin': string;
|
|
44
|
+
'transparent-dark-average': string;
|
|
45
|
+
'transparent-dark-thick': string;
|
|
46
|
+
};
|
|
40
47
|
export declare const SQUID_THEME_CSS_VARIABLE_PREFIX = "--squid-theme-";
|
|
41
48
|
/**
|
|
42
49
|
* Mapping between readable variables name and css variables used TailwindCSS config
|
|
43
50
|
*/
|
|
44
|
-
export declare const themeTypesKeys: Record<keyof
|
|
51
|
+
export declare const themeTypesKeys: Record<keyof InternalSquidTheme, {
|
|
45
52
|
cssVariable: string;
|
|
46
53
|
}>;
|
package/dist/index.d.ts
CHANGED
|
@@ -443,41 +443,27 @@ interface HeadingTextProps {
|
|
|
443
443
|
}
|
|
444
444
|
declare function HeadingText({ children, bold, size }: HeadingTextProps): react_jsx_runtime.JSX.Element;
|
|
445
445
|
|
|
446
|
-
|
|
447
|
-
'
|
|
448
|
-
'
|
|
449
|
-
'
|
|
450
|
-
'
|
|
451
|
-
'
|
|
452
|
-
'
|
|
453
|
-
'
|
|
454
|
-
'
|
|
455
|
-
'
|
|
456
|
-
'
|
|
457
|
-
'
|
|
458
|
-
'royal-300': string;
|
|
459
|
-
'royal-400': string;
|
|
460
|
-
'royal-500': string;
|
|
461
|
-
'royal-600': string;
|
|
462
|
-
'royal-700': string;
|
|
463
|
-
'royal-800': string;
|
|
446
|
+
type SquidTheme = {
|
|
447
|
+
'content-100': string;
|
|
448
|
+
'content-200': string;
|
|
449
|
+
'content-300': string;
|
|
450
|
+
'content-400': string;
|
|
451
|
+
'content-500': string;
|
|
452
|
+
'content-600': string;
|
|
453
|
+
'content-700': string;
|
|
454
|
+
'content-800': string;
|
|
455
|
+
'content-900': string;
|
|
456
|
+
'accent-400': string;
|
|
457
|
+
'accent-500': string;
|
|
464
458
|
'status-positive': string;
|
|
465
459
|
'status-negative': string;
|
|
466
|
-
'
|
|
467
|
-
'
|
|
468
|
-
'
|
|
469
|
-
'
|
|
470
|
-
'
|
|
471
|
-
'
|
|
472
|
-
|
|
473
|
-
'volt-400': string;
|
|
474
|
-
'volt-600': string;
|
|
475
|
-
'volt-700': string;
|
|
476
|
-
'volt-800': string;
|
|
477
|
-
'volt-900': string;
|
|
478
|
-
'accent-salmon': string;
|
|
479
|
-
'accent-gold': string;
|
|
480
|
-
}
|
|
460
|
+
'transparent-light-thin': string;
|
|
461
|
+
'transparent-light-average': string;
|
|
462
|
+
'transparent-light-thick': string;
|
|
463
|
+
'transparent-dark-thin': string;
|
|
464
|
+
'transparent-dark-average': string;
|
|
465
|
+
'transparent-dark-thick': string;
|
|
466
|
+
};
|
|
481
467
|
|
|
482
468
|
declare function SquidConfigProvider({ theme, children, themeType, }: {
|
|
483
469
|
theme: SquidTheme;
|