77
88import {
99 accentBaseColor ,
10+ accentFillActive ,
11+ accentFillFocus ,
12+ accentFillHover ,
13+ accentFillRest ,
14+ accentForegroundActive ,
15+ accentForegroundFocus ,
16+ accentForegroundHover ,
17+ accentForegroundRest ,
18+ accentStrokeControlActive ,
19+ accentStrokeControlFocus ,
20+ accentStrokeControlHover ,
21+ accentStrokeControlRest ,
1022 baseLayerLuminance ,
23+ foregroundOnAccentActive ,
24+ foregroundOnAccentFocus ,
25+ foregroundOnAccentHover ,
26+ foregroundOnAccentRecipe ,
27+ foregroundOnAccentRest ,
28+ foregroundOnAccentRestLarge ,
1129 neutralBaseColor ,
1230 StandardLuminance ,
1331 SwatchRGB
@@ -56,7 +74,10 @@ type ColorScheme = {
5674 */
5775 baseLayerLuminance : number ;
5876
59- designTokenOverrides ?: Record < string , string > ;
77+ /**
78+ * Optional function to override design tokens
79+ */
80+ designTokenOverrides ?: ( element : HTMLElement ) => void ;
6081} ;
6182
6283/**
@@ -69,14 +90,7 @@ const applyColorScheme = (settings: ColorScheme, element: HTMLElement = document
6990 accentBaseColor . setValueFor ( element , SwatchRGB . from ( parseColorHexRGB ( settings . accentBaseColor ) ) ) ;
7091 neutralBaseColor . setValueFor ( element , SwatchRGB . from ( parseColorHexRGB ( settings . neutralBaseColor ) ) ) ;
7192 baseLayerLuminance . setValueFor ( element , settings . baseLayerLuminance ) ;
72- // put this work on the macro queue so that it happens after promise based/reactive work of setting the base colors above
73- if ( settings . designTokenOverrides ) {
74- setTimeout ( ( ) => {
75- Object . entries ( settings . designTokenOverrides ) . forEach ( ( [ key , value ] ) => {
76- element . style . setProperty ( key , value ) ;
77- } ) ;
78- } ) ;
79- }
93+ settings . designTokenOverrides ?.( element ) ;
8094} ;
8195
8296/**
@@ -104,28 +118,24 @@ const getThemeSettings = (theme: Theme): ColorScheme => {
104118 accentBaseColor : '#479ef5' ,
105119 neutralBaseColor : '#adadad' ,
106120 baseLayerLuminance : StandardLuminance . DarkMode ,
107- designTokenOverrides : {
108- '--accent-fill-rest' : '#115ea3' ,
109- '--accent-fill-hover' : '#0f6cbd' ,
110- '--accent-fill-active' : '#0c3b5e' ,
111- '--accent-fill-focus' : '#0f548c' ,
112- '--accent-foreground-rest' : '#479EF5' ,
113- '--accent-foreground-hover' : '#62abf5' ,
114- '--accent-foreground-active' : '#2886de' ,
115- '--accent-foreground-focus' : '#479ef5' ,
116- '--accent-stroke-control-rest' : '#115ea3' ,
117- '--accent-stroke-control-hover' : '#0f6cbd' ,
118- '--accent-stroke-control-active' : '#0c3b5e' ,
119- '--accent-stroke-control-focus' : '#0f548c' ,
120- // foreground on accents
121- '--foreground-on-accent-rest' : '#ffffff' ,
122- '--foreground-on-accent-active' : '#ffffff' ,
123- '--foreground-on-accent-rest-large' : '#ffffff' ,
124- '--foreground-on-accent-hover' : '#ffffff' ,
125- '--foreground-on-accent-hover-large' : '#ffffff' ,
126- '--foreground-on-accent-active-large' : '#ffffff' ,
127- '--foreground-on-accent-focus' : '#ffffff' ,
128- '--foreground-on-accent-focus-large' : '#ffffff'
121+ designTokenOverrides : element => {
122+ accentFillRest . setValueFor ( element , SwatchRGB . from ( parseColorHexRGB ( '#115ea3' ) ) ) ;
123+ accentFillHover . setValueFor ( element , SwatchRGB . from ( parseColorHexRGB ( '#0f6cbd' ) ) ) ;
124+ accentFillActive . setValueFor ( element , SwatchRGB . from ( parseColorHexRGB ( '#0c3b5e' ) ) ) ;
125+ accentFillFocus . setValueFor ( element , SwatchRGB . from ( parseColorHexRGB ( '#0f548c' ) ) ) ;
126+ accentForegroundRest . setValueFor ( element , SwatchRGB . from ( parseColorHexRGB ( '#479EF5' ) ) ) ;
127+ accentForegroundHover . setValueFor ( element , SwatchRGB . from ( parseColorHexRGB ( '#62abf5' ) ) ) ;
128+ accentForegroundActive . setValueFor ( element , SwatchRGB . from ( parseColorHexRGB ( '#2886de' ) ) ) ;
129+ accentForegroundFocus . setValueFor ( element , SwatchRGB . from ( parseColorHexRGB ( '#479ef5' ) ) ) ;
130+ accentStrokeControlRest . setValueFor ( element , SwatchRGB . from ( parseColorHexRGB ( '#115ea3' ) ) ) ;
131+ accentStrokeControlHover . setValueFor ( element , SwatchRGB . from ( parseColorHexRGB ( '#0f6cbd' ) ) ) ;
132+ accentStrokeControlActive . setValueFor ( element , SwatchRGB . from ( parseColorHexRGB ( '#0c3b5e' ) ) ) ;
133+ accentStrokeControlFocus . setValueFor ( element , SwatchRGB . from ( parseColorHexRGB ( '#0f548c' ) ) ) ;
134+ foregroundOnAccentActive . setValueFor ( element , SwatchRGB . from ( parseColorHexRGB ( '#ffffff' ) ) ) ;
135+ foregroundOnAccentRest . setValueFor ( element , SwatchRGB . from ( parseColorHexRGB ( '#ffffff' ) ) ) ;
136+ foregroundOnAccentRestLarge . setValueFor ( element , SwatchRGB . from ( parseColorHexRGB ( '#ffffff' ) ) ) ;
137+ foregroundOnAccentHover . setValueFor ( element , SwatchRGB . from ( parseColorHexRGB ( '#ffffff' ) ) ) ;
138+ foregroundOnAccentFocus . setValueFor ( element , SwatchRGB . from ( parseColorHexRGB ( '#ffffff' ) ) ) ;
129139 }
130140 } ;
131141 case 'light' :
0 commit comments