11// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
22// 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' ;
64
75import { Alert as CloudscapeAlert , Button , SpaceBetween } from '~components' ;
86
@@ -68,12 +66,6 @@ interface CustomAlertProps {
6866}
6967
7068function 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- const iconColor = iconColors [ mode ] [ type ] ;
7769 return (
7870 < CloudscapeAlert
7971 dismissible = { dismissible }
@@ -82,26 +74,22 @@ function CustomAlert({ children, type, dismissible, action }: CustomAlertProps)
8274 i18nStrings = { i18nStrings }
8375 style = { {
8476 root : {
85- background,
86- borderColor,
77+ background : getBackground ( type ) ,
78+ borderColor : getBorderColor ( type ) ,
8779 borderRadius : '8px' ,
88- borderWidth,
89- color,
80+ borderWidth : getBorderWidth ( type ) ,
81+ color : getColor ( ) ,
9082 focusRing : {
9183 borderColor : palette . red60 ,
9284 borderRadius : '4px' ,
9385 borderWidth : '2px' ,
9486 } ,
9587 } ,
9688 icon : {
97- color : iconColor ,
89+ color : getIconColor ( type ) ,
9890 } ,
9991 dismissButton : {
100- color : {
101- default : dismissButtonColors [ mode ] [ type ] . default ,
102- hover : dismissButtonColors [ mode ] [ type ] . hover ,
103- active : dismissButtonColors [ mode ] [ type ] . active ,
104- } ,
92+ color : getDismissButtonColor ( type ) ,
10593 focusRing : {
10694 borderColor : palette . red60 ,
10795 borderRadius : '4px' ,
@@ -115,106 +103,72 @@ function CustomAlert({ children, type, dismissible, action }: CustomAlertProps)
115103 ) ;
116104}
117105
118- const backgrounds = {
119- light : {
120- info : palette . blue80 ,
121- success : palette . green80 ,
122- error : palette . red80 ,
123- warning : palette . teal90 ,
124- } ,
125- dark : {
126- info : palette . blue40 ,
127- success : palette . green20 ,
128- error : palette . red30 ,
129- warning : palette . teal20 ,
130- } ,
131- } ;
106+ function getBackground ( type : string ) {
107+ const backgrounds = {
108+ info : `light-dark(${ palette . blue80 } , ${ palette . blue40 } )` ,
109+ success : `light-dark(${ palette . green80 } , ${ palette . green20 } )` ,
110+ error : `light-dark(${ palette . red80 } , ${ palette . red30 } )` ,
111+ warning : `light-dark(${ palette . teal90 } , ${ palette . teal20 } )` ,
112+ } ;
113+ return backgrounds [ type as keyof typeof backgrounds ] ;
114+ }
132115
133- const colors = {
134- light : palette . neutral10 ,
135- dark : palette . neutral100 ,
136- } ;
116+ function getColor ( ) {
117+ return `light-dark(${ palette . neutral10 } , ${ palette . neutral100 } )` ;
118+ }
137119
138- const borderColors = {
139- light : {
140- info : palette . neutral80 ,
141- success : palette . green80 ,
142- error : palette . blue90 ,
143- warning : palette . orange80 ,
144- } ,
145- dark : {
146- info : palette . neutral20 ,
147- success : palette . green30 ,
148- error : palette . red60 ,
149- warning : palette . orange40 ,
150- } ,
151- } ;
120+ function getBorderColor ( type : string ) {
121+ const borderColors = {
122+ info : `light-dark(${ palette . neutral80 } , ${ palette . neutral20 } )` ,
123+ success : `light-dark(${ palette . green80 } , ${ palette . green30 } )` ,
124+ error : `light-dark(${ palette . blue90 } , ${ palette . red60 } )` ,
125+ warning : `light-dark(${ palette . orange80 } , ${ palette . orange40 } )` ,
126+ } ;
127+ return borderColors [ type as keyof typeof borderColors ] ;
128+ }
152129
153- const borderWidths = {
154- info : '4px' ,
155- success : '0px' ,
156- error : '6px' ,
157- warning : '0px' ,
158- } ;
130+ function getBorderWidth ( type : string ) {
131+ const borderWidths = {
132+ info : '4px' ,
133+ success : '0px' ,
134+ error : '6px' ,
135+ warning : '0px' ,
136+ } ;
137+ return borderWidths [ type as keyof typeof borderWidths ] ;
138+ }
159139
160- const iconColors = {
161- light : {
162- info : palette . orange80 ,
163- success : palette . red60 ,
164- error : palette . blue80 ,
165- warning : palette . neutral10 ,
166- } ,
167- dark : {
168- info : palette . red30 ,
169- success : palette . red60 ,
170- error : palette . blue40 ,
171- warning : palette . neutral90 ,
172- } ,
173- } ;
140+ function getIconColor ( type : string ) {
141+ const iconColors = {
142+ info : `light-dark(${ palette . orange80 } , ${ palette . red30 } )` ,
143+ success : `light-dark(${ palette . red60 } , ${ palette . red60 } )` ,
144+ error : `light-dark(${ palette . blue80 } , ${ palette . blue40 } )` ,
145+ warning : `light-dark(${ palette . neutral10 } , ${ palette . neutral90 } )` ,
146+ } ;
147+ return iconColors [ type as keyof typeof iconColors ] ;
148+ }
174149
175- const dismissButtonColors = {
176- light : {
177- info : {
178- default : palette . green60 ,
179- hover : palette . neutral80 ,
180- active : palette . neutral90 ,
181- } ,
182- success : {
183- default : palette . green60 ,
184- hover : palette . green80 ,
185- active : palette . green90 ,
186- } ,
187- error : {
188- default : palette . red60 ,
189- hover : palette . red60 ,
190- active : palette . red80 ,
191- } ,
192- warning : {
193- default : palette . orange60 ,
194- hover : palette . orange80 ,
195- active : palette . orange90 ,
196- } ,
197- } ,
198- dark : {
150+ function getDismissButtonColor ( type : string ) {
151+ const dismissButtonColors = {
199152 info : {
200- default : palette . neutral40 ,
201- hover : palette . neutral20 ,
202- active : palette . neutral10 ,
153+ default : `light-dark( ${ palette . green60 } , ${ palette . neutral40 } )` ,
154+ hover : `light-dark( ${ palette . neutral80 } , ${ palette . neutral20 } )` ,
155+ active : `light-dark( ${ palette . neutral90 } , ${ palette . neutral10 } )` ,
203156 } ,
204157 success : {
205- default : palette . green30 ,
206- hover : palette . green20 ,
207- active : palette . green10 ,
158+ default : `light-dark( ${ palette . green60 } , ${ palette . green30 } )` ,
159+ hover : `light-dark( ${ palette . green80 } , ${ palette . green20 } )` ,
160+ active : `light-dark( ${ palette . green90 } , ${ palette . green10 } )` ,
208161 } ,
209162 error : {
210- default : palette . red60 ,
211- hover : palette . red20 ,
212- active : palette . red10 ,
163+ default : `light-dark( ${ palette . red60 } , ${ palette . red60 } )` ,
164+ hover : `light-dark( ${ palette . red60 } , ${ palette . red20 } )` ,
165+ active : `light-dark( ${ palette . red80 } , ${ palette . red10 } )` ,
213166 } ,
214167 warning : {
215- default : palette . orange40 ,
216- hover : palette . orange20 ,
217- active : palette . orange10 ,
168+ default : `light-dark( ${ palette . orange60 } , ${ palette . orange40 } )` ,
169+ hover : `light-dark( ${ palette . orange80 } , ${ palette . orange20 } )` ,
170+ active : `light-dark( ${ palette . orange90 } , ${ palette . orange10 } )` ,
218171 } ,
219- } ,
220- } ;
172+ } ;
173+ return dismissButtonColors [ type as keyof typeof dismissButtonColors ] ;
174+ }
0 commit comments