@@ -38,6 +38,39 @@ export const _getValidatedColor = ({
38
38
return newColor ;
39
39
} ;
40
40
41
+ /**
42
+ * Return background color
43
+ * @param {string } string - Color (as hexadecimal)
44
+ * @param {string } colorScheme - Color scheme
45
+ * @returns {string } CSS color value (HSL)
46
+ */
47
+ export const backgroundColor = ( string , colorScheme = "light" ) => {
48
+ const primary = new Color ( string ) . hsl ( ) . round ( ) ;
49
+
50
+ return new Color ( {
51
+ h : primary . hue ( ) ,
52
+ s : 5 ,
53
+ l : colorScheme === "light" ? 99 : 10 ,
54
+ } )
55
+ . hsl ( )
56
+ . toString ( ) ;
57
+ } ;
58
+
59
+ /**
60
+ * Return theme color
61
+ * @param {string } string - Color (as hexadecimal)
62
+ * @param {string } colorScheme - Color scheme
63
+ * @returns {string } CSS color value (HSL)
64
+ */
65
+ export const themeColor = ( string , colorScheme = "light" ) => {
66
+ const primary = new Color ( string ) . hsl ( ) . round ( ) ;
67
+ const h = primary . hue ( ) ;
68
+ const s = 5 ;
69
+ const l = colorScheme === "light" ? 95 : 20 ;
70
+
71
+ return new Color ( { h, s, l } ) . hsl ( ) . toString ( ) ;
72
+ } ;
73
+
41
74
/**
42
75
* Return theme color as CSS custom properties
43
76
* @param {string } string - Color (as hexadecimal)
@@ -49,8 +82,8 @@ export const themeCustomProperties = (string) => {
49
82
const primarySaturation = 5 ;
50
83
51
84
// Calculate neutral lightest and darkest hues used in custom properties
52
- const neutral99 = new Color ( { h : primaryHue , s : primarySaturation , l : 99 } ) ;
53
- const neutral10 = new Color ( { h : primaryHue , s : primarySaturation , l : 10 } ) ;
85
+ const neutral99 = new Color ( backgroundColor ( string ) ) ;
86
+ const neutral10 = new Color ( backgroundColor ( string , "dark" ) ) ;
54
87
55
88
// Generate a darker variant of primary colour
56
89
const primaryVariant = primary . darken ( 0.15 ) . desaturate ( 0.1 ) ;
0 commit comments