77
88import styled , { css , ThemeProps , DefaultTheme } from 'styled-components' ;
99import {
10- getColorV8 ,
1110 DEFAULT_THEME ,
1211 retrieveComponentStyles ,
1312 getLineHeight ,
14- focusStyles
13+ focusStyles ,
14+ getColor
1515} from '@zendeskgarden/react-theming' ;
1616
1717import { IGlobalAlertProps } from '../../types' ;
1818
19- const COMPONENT_ID = 'notifications.global-alert ' ;
19+ const COMPONENT_ID = 'notifications.global_alert ' ;
2020
2121interface IStyledGlobalAlertProps {
22- alertType : IGlobalAlertProps [ 'type' ] ;
22+ $ alertType : IGlobalAlertProps [ 'type' ] ;
2323}
2424
25+ const lightDarkOptions = ( lightOffset : number , darkOffset : number ) => ( {
26+ light : { offset : lightOffset } ,
27+ dark : { offset : darkOffset }
28+ } ) ;
29+
2530/**
2631 * 1. Shifting :focus-visible from LVHFA order to preserve `color` on hover
2732 */
28- const colorStyles = ( props : ThemeProps < DefaultTheme > & IStyledGlobalAlertProps ) => {
33+ const colorStyles = ( { theme , $alertType } : ThemeProps < DefaultTheme > & IStyledGlobalAlertProps ) => {
2934 let borderColor ;
3035 let backgroundColor ;
3136 let foregroundColor ;
3237 let anchorHoverColor ;
3338 let anchorActiveColor ;
34- let focusColor ;
35-
36- switch ( props . alertType ) {
37- case 'success' :
38- borderColor = getColorV8 ( 'successHue' , 700 , props . theme ) ;
39- backgroundColor = getColorV8 ( 'successHue' , 600 , props . theme ) ;
40- foregroundColor = getColorV8 ( 'successHue' , 100 , props . theme ) ;
41- anchorHoverColor = props . theme . palette . white ;
42- anchorActiveColor = props . theme . palette . white ;
43- focusColor = 'successHue' ;
39+ let focusVariable ;
40+
41+ switch ( $alertType ) {
42+ case 'success' : {
43+ borderColor = getColor ( {
44+ variable : 'border.successEmphasis' ,
45+ ...lightDarkOptions ( 100 , 200 ) ,
46+ theme
47+ } ) ;
48+ backgroundColor = getColor ( {
49+ variable : 'background.successEmphasis' ,
50+ dark : { offset : 100 } ,
51+ theme
52+ } ) ;
53+ foregroundColor = getColor ( {
54+ variable : 'foreground.success' ,
55+ ...lightDarkOptions ( - 600 , - 300 ) ,
56+ theme
57+ } ) ;
58+ focusVariable = 'foreground.successEmphasis' ;
4459 break ;
45-
46- case 'error' :
47- borderColor = getColorV8 ( 'dangerHue' , 700 , props . theme ) ;
48- backgroundColor = getColorV8 ( 'dangerHue' , 600 , props . theme ) ;
49- foregroundColor = getColorV8 ( 'dangerHue' , 100 , props . theme ) ;
50- anchorHoverColor = props . theme . palette . white ;
51- anchorActiveColor = props . theme . palette . white ;
52- focusColor = 'dangerHue' ;
60+ }
61+ case 'error' : {
62+ borderColor = getColor ( {
63+ variable : 'border.dangerEmphasis' ,
64+ ...lightDarkOptions ( 100 , 200 ) ,
65+ theme
66+ } ) ;
67+ backgroundColor = getColor ( {
68+ variable : 'background.dangerEmphasis' ,
69+ dark : { offset : 100 } ,
70+ theme
71+ } ) ;
72+ foregroundColor = getColor ( {
73+ variable : 'foreground.danger' ,
74+ ...lightDarkOptions ( - 600 , - 300 ) ,
75+ theme
76+ } ) ;
77+ focusVariable = 'foreground.dangerEmphasis' ;
5378 break ;
54-
55- case 'warning' :
56- borderColor = getColorV8 ( 'warningHue' , 400 , props . theme ) ;
57- backgroundColor = getColorV8 ( 'warningHue' , 300 , props . theme ) ;
58- foregroundColor = getColorV8 ( 'warningHue' , 800 , props . theme ) ;
59- anchorHoverColor = getColorV8 ( 'warningHue' , 900 , props . theme ) ;
60- anchorActiveColor = getColorV8 ( 'warningHue' , 1000 , props . theme ) ;
61- focusColor = 'warningHue' ;
79+ }
80+ case 'warning' : {
81+ borderColor = getColor ( {
82+ variable : 'border.warningEmphasis' ,
83+ ...lightDarkOptions ( - 300 , - 200 ) ,
84+ theme
85+ } ) ;
86+ backgroundColor = getColor ( {
87+ variable : 'background.warningEmphasis' ,
88+ ...lightDarkOptions ( - 400 , - 300 ) ,
89+ theme
90+ } ) ;
91+ const fgVariable = 'foreground.warning' ;
92+ foregroundColor = getColor ( {
93+ variable : fgVariable ,
94+ ...lightDarkOptions ( 100 , 400 ) ,
95+ theme
96+ } ) ;
97+ anchorHoverColor = getColor ( {
98+ variable : fgVariable ,
99+ ...lightDarkOptions ( 200 , 500 ) ,
100+ theme
101+ } ) ;
102+ anchorActiveColor = getColor ( {
103+ variable : fgVariable ,
104+ ...lightDarkOptions ( 300 , 600 ) ,
105+ theme
106+ } ) ;
107+ focusVariable = fgVariable ;
62108 break ;
63-
64- case 'info' :
65- borderColor = getColorV8 ( 'primaryHue' , 300 , props . theme ) ;
66- backgroundColor = getColorV8 ( 'primaryHue' , 200 , props . theme ) ;
67- foregroundColor = getColorV8 ( 'primaryHue' , 700 , props . theme ) ;
68- anchorHoverColor = getColorV8 ( 'primaryHue' , 800 , props . theme ) ;
69- anchorActiveColor = getColorV8 ( 'primaryHue' , 900 , props . theme ) ;
70- focusColor = 'primaryHue' ;
109+ }
110+ case 'info' : {
111+ borderColor = getColor ( {
112+ variable : 'border.primaryEmphasis' ,
113+ ...lightDarkOptions ( - 300 , - 200 ) ,
114+ theme
115+ } ) ;
116+ backgroundColor = getColor ( {
117+ variable : 'background.primaryEmphasis' ,
118+ ...lightDarkOptions ( - 400 , - 300 ) ,
119+ theme
120+ } ) ;
121+ const fgVariable = 'foreground.primary' ;
122+ foregroundColor = getColor ( {
123+ variable : fgVariable ,
124+ ...lightDarkOptions ( 100 , 200 ) ,
125+ theme
126+ } ) ;
127+ anchorHoverColor = getColor ( {
128+ variable : fgVariable ,
129+ ...lightDarkOptions ( 200 , 300 ) ,
130+ theme
131+ } ) ;
132+ anchorActiveColor = getColor ( {
133+ variable : fgVariable ,
134+ ...lightDarkOptions ( 300 , 400 ) ,
135+ theme
136+ } ) ;
137+ focusVariable = fgVariable ;
71138 break ;
139+ }
140+ }
141+
142+ if ( [ 'success' , 'error' ] . includes ( $alertType ) ) {
143+ anchorHoverColor = theme . palette . white ;
144+ anchorActiveColor = theme . palette . white ;
72145 }
73146
74147 // Apply a border without affecting the element's size
75- const boxShadow = `0 ${ props . theme . borderWidths . sm } ${ props . theme . borderWidths . sm } ${ borderColor } ` ;
148+ const boxShadow = `0 ${ theme . borderWidths . sm } ${ theme . borderWidths . sm } ${ borderColor } ` ;
76149
77150 /* stylelint-disable selector-no-qualifying-type */
78151 return css `
@@ -85,8 +158,8 @@ const colorStyles = (props: ThemeProps<DefaultTheme> & IStyledGlobalAlertProps)
85158
86159 /* [1] */
87160 ${ focusStyles ( {
88- theme : props . theme ,
89- color : { hue : focusColor , shade : props . alertType === 'info' ? 600 : 800 } ,
161+ theme,
162+ color : { variable : focusVariable } ,
90163 styles : { color : 'inherit' }
91164 } ) }
92165
@@ -119,7 +192,7 @@ const sizeStyles = (props: ThemeProps<DefaultTheme>) => {
119192export const StyledGlobalAlert = styled . div . attrs ( {
120193 'data-garden-id' : COMPONENT_ID ,
121194 'data-garden-version' : PACKAGE_VERSION
122- } ) `
195+ } ) < IStyledGlobalAlertProps > `
123196 display: flex;
124197 flex-wrap: nowrap;
125198 overflow: auto;
0 commit comments