1
1
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
2
// SPDX-License-Identifier: Apache-2.0
3
- import React , { useRef } from 'react' ;
4
-
5
- import { useCurrentMode } from '@cloudscape-design/component-toolkit/internal' ;
3
+ import React from 'react' ;
6
4
7
5
import { Alert as CloudscapeAlert , Button , SpaceBetween } from '~components' ;
8
6
@@ -68,11 +66,6 @@ interface CustomAlertProps {
68
66
}
69
67
70
68
function CustomAlert ( { children, type, dismissible, action } : CustomAlertProps ) {
71
- const mode = useCurrentMode ( useRef ( document . body ) ) ;
72
- const background = backgrounds [ mode ] [ type ] ;
73
- const borderColor = borderColors [ mode ] [ type ] ;
74
- const borderWidth = borderWidths [ type ] ;
75
- const color = colors [ mode ] ;
76
69
return (
77
70
< CloudscapeAlert
78
71
dismissible = { dismissible }
@@ -81,23 +74,19 @@ function CustomAlert({ children, type, dismissible, action }: CustomAlertProps)
81
74
i18nStrings = { i18nStrings }
82
75
style = { {
83
76
root : {
84
- background,
85
- borderColor,
77
+ background : getBackground ( type ) ,
78
+ borderColor : getBorderColor ( type ) ,
86
79
borderRadius : '8px' ,
87
- borderWidth,
88
- color,
80
+ borderWidth : getBorderWidth ( type ) ,
81
+ color : getColor ( ) ,
89
82
focusRing : {
90
83
borderColor : palette . red60 ,
91
84
borderRadius : '4px' ,
92
85
borderWidth : '2px' ,
93
86
} ,
94
87
} ,
95
88
dismissButton : {
96
- color : {
97
- default : dismissButtonColors [ mode ] [ type ] . default ,
98
- hover : dismissButtonColors [ mode ] [ type ] . hover ,
99
- active : dismissButtonColors [ mode ] [ type ] . active ,
100
- } ,
89
+ color : getDismissButtonColor ( type ) ,
101
90
focusRing : {
102
91
borderColor : palette . red60 ,
103
92
borderRadius : '4px' ,
@@ -111,91 +100,62 @@ function CustomAlert({ children, type, dismissible, action }: CustomAlertProps)
111
100
) ;
112
101
}
113
102
114
- const backgrounds = {
115
- light : {
116
- info : palette . blue80 ,
117
- success : palette . green80 ,
118
- error : palette . red80 ,
119
- warning : palette . teal90 ,
120
- } ,
121
- dark : {
122
- info : palette . blue40 ,
123
- success : palette . green20 ,
124
- error : palette . red30 ,
125
- warning : palette . teal20 ,
126
- } ,
127
- } ;
103
+ function getBackground ( type : string ) {
104
+ const backgrounds = {
105
+ info : `light-dark(${ palette . blue80 } , ${ palette . blue40 } )` ,
106
+ success : `light-dark(${ palette . green80 } , ${ palette . green20 } )` ,
107
+ error : `light-dark(${ palette . red80 } , ${ palette . red30 } )` ,
108
+ warning : `light-dark(${ palette . teal90 } , ${ palette . teal20 } )` ,
109
+ } ;
110
+ return backgrounds [ type as keyof typeof backgrounds ] ;
111
+ }
128
112
129
- const colors = {
130
- light : palette . neutral10 ,
131
- dark : palette . neutral100 ,
132
- } ;
113
+ function getColor ( ) {
114
+ return `light-dark(${ palette . neutral10 } , ${ palette . neutral100 } )` ;
115
+ }
133
116
134
- const borderColors = {
135
- light : {
136
- info : palette . neutral80 ,
137
- success : palette . green80 ,
138
- error : palette . blue90 ,
139
- warning : palette . orange80 ,
140
- } ,
141
- dark : {
142
- info : palette . neutral20 ,
143
- success : palette . green30 ,
144
- error : palette . red60 ,
145
- warning : palette . orange40 ,
146
- } ,
147
- } ;
117
+ function getBorderColor ( type : string ) {
118
+ const borderColors = {
119
+ info : `light-dark(${ palette . neutral80 } , ${ palette . neutral20 } )` ,
120
+ success : `light-dark(${ palette . green80 } , ${ palette . green30 } )` ,
121
+ error : `light-dark(${ palette . blue90 } , ${ palette . red60 } )` ,
122
+ warning : `light-dark(${ palette . orange80 } , ${ palette . orange40 } )` ,
123
+ } ;
124
+ return borderColors [ type as keyof typeof borderColors ] ;
125
+ }
148
126
149
- const borderWidths = {
150
- info : '4px' ,
151
- success : '0px' ,
152
- error : '6px' ,
153
- warning : '0px' ,
154
- } ;
127
+ function getBorderWidth ( type : string ) {
128
+ const borderWidths = {
129
+ info : '4px' ,
130
+ success : '0px' ,
131
+ error : '6px' ,
132
+ warning : '0px' ,
133
+ } ;
134
+ return borderWidths [ type as keyof typeof borderWidths ] ;
135
+ }
155
136
156
- const dismissButtonColors = {
157
- light : {
137
+ function getDismissButtonColor ( type : string ) {
138
+ const dismissButtonColors = {
158
139
info : {
159
- default : palette . green60 ,
160
- hover : palette . neutral80 ,
161
- active : palette . neutral90 ,
140
+ default : `light-dark( ${ palette . green60 } , ${ palette . neutral40 } )` ,
141
+ hover : `light-dark( ${ palette . neutral80 } , ${ palette . neutral20 } )` ,
142
+ active : `light-dark( ${ palette . neutral90 } , ${ palette . neutral10 } )` ,
162
143
} ,
163
144
success : {
164
- default : palette . green60 ,
165
- hover : palette . green80 ,
166
- active : palette . green90 ,
145
+ default : `light-dark( ${ palette . green60 } , ${ palette . green30 } )` ,
146
+ hover : `light-dark( ${ palette . green80 } , ${ palette . green20 } )` ,
147
+ active : `light-dark( ${ palette . green90 } , ${ palette . green10 } )` ,
167
148
} ,
168
149
error : {
169
- default : palette . red60 ,
170
- hover : palette . red60 ,
171
- active : palette . red80 ,
150
+ default : `light-dark( ${ palette . red60 } , ${ palette . red60 } )` ,
151
+ hover : `light-dark( ${ palette . red60 } , ${ palette . red20 } )` ,
152
+ active : `light-dark( ${ palette . red80 } , ${ palette . red10 } )` ,
172
153
} ,
173
154
warning : {
174
- default : palette . orange60 ,
175
- hover : palette . orange80 ,
176
- active : palette . orange90 ,
177
- } ,
178
- } ,
179
- dark : {
180
- info : {
181
- default : palette . neutral40 ,
182
- hover : palette . neutral20 ,
183
- active : palette . neutral10 ,
155
+ default : `light-dark(${ palette . orange60 } , ${ palette . orange40 } )` ,
156
+ hover : `light-dark(${ palette . orange80 } , ${ palette . orange20 } )` ,
157
+ active : `light-dark(${ palette . orange90 } , ${ palette . orange10 } )` ,
184
158
} ,
185
- success : {
186
- default : palette . green30 ,
187
- hover : palette . green20 ,
188
- active : palette . green10 ,
189
- } ,
190
- error : {
191
- default : palette . red60 ,
192
- hover : palette . red20 ,
193
- active : palette . red10 ,
194
- } ,
195
- warning : {
196
- default : palette . orange40 ,
197
- hover : palette . orange20 ,
198
- active : palette . orange10 ,
199
- } ,
200
- } ,
201
- } ;
159
+ } ;
160
+ return dismissButtonColors [ type as keyof typeof dismissButtonColors ] ;
161
+ }
0 commit comments