1
- import { Box , HStack } from '@chakra-ui/react'
1
+ import { Box , HStack , useMediaQuery } from '@chakra-ui/react'
2
2
3
3
import { BtnLink , BtnPrimary } from '@/molecules'
4
4
import { vars } from '@/theme'
@@ -27,21 +27,44 @@ export function Alert({
27
27
buttonText,
28
28
buttonIcon,
29
29
buttonLink = false ,
30
+ isFlash = false ,
30
31
onClick,
31
32
state,
32
33
m,
33
34
} : IAlertProps ) : JSX . Element {
35
+ const [ isMobile ] = useMediaQuery ( '(max-width: 425px)' )
36
+
37
+ const handleClick = ( ) : any => {
38
+ if ( onClick ) {
39
+ onClick ( )
40
+ }
41
+ }
42
+
43
+ let buttonType : undefined | 'link' | 'normal'
44
+ if ( buttonText ) {
45
+ buttonType = buttonLink ? 'link' : 'normal'
46
+ }
47
+
34
48
return (
35
49
< Box
50
+ className = { isFlash ? 'flashNotification' : 'embeddedAlert' }
51
+ alignItems = { ! isMobile ? 'center' : 'unset' }
36
52
backgroundColor = { alertStates [ state ] . bg }
37
53
borderRadius = "8px"
38
- padding = { canDismiss ? '16px 28px 16px 16px' : '16px' }
39
- width = "max-content"
40
- maxWidth = "796px"
54
+ display = "flex"
55
+ flexFlow = { isMobile ? 'column' : 'row' }
56
+ gap = { ! isFlash ? '16px' : '' }
57
+ justifyContent = { ! isMobile ? 'space-between' : '' }
41
58
margin = { m }
59
+ width = "100%"
60
+ maxWidth = "796px"
61
+ p = "1rem"
62
+ pr = { canDismiss ? '1.75rem' : '1rem' }
42
63
position = "relative"
43
64
>
44
65
< HStack
66
+ gap = "10px"
67
+ className = "alertContent"
45
68
sx = { {
46
69
'.linkButton' : {
47
70
fontSize : '16px' ,
@@ -50,7 +73,6 @@ export function Alert({
50
73
>
51
74
< Box
52
75
className = "iconContainer"
53
- marginRight = "10px"
54
76
sx = { {
55
77
svg : {
56
78
width : 'auto' ,
@@ -67,30 +89,31 @@ export function Alert({
67
89
color = { vars ( 'colors-neutral-darkCharcoal' ) }
68
90
>
69
91
{ children }
70
- { buttonText && onClick && buttonLink && < BtnLink onClick = { onClick } > { buttonText } </ BtnLink > }
92
+ { buttonType === 'link' && < BtnLink onClick = { handleClick } > { buttonText } </ BtnLink > }
71
93
</ Box >
72
- { buttonText && onClick && ! buttonLink && (
73
- < BtnPrimary leftIcon = { buttonIcon } onClick = { onClick } >
74
- { buttonText }
75
- </ BtnPrimary >
76
- ) }
77
- { canDismiss && (
78
- < Box
79
- cursor = "pointer"
80
- marginLeft = "12px"
81
- sx = { {
82
- svg : {
83
- position : 'absolute' ,
84
- top : '16px' ,
85
- right : '12px' ,
86
- } ,
87
- } }
88
- onClick = { onClick }
89
- >
90
- < Close />
91
- </ Box >
92
- ) }
93
94
</ HStack >
95
+
96
+ { buttonType === 'normal' && (
97
+ < BtnPrimary isFullWidth = { ! ! isMobile } leftIcon = { buttonIcon } onClick = { handleClick } >
98
+ { buttonText }
99
+ </ BtnPrimary >
100
+ ) }
101
+ { canDismiss && (
102
+ < Box
103
+ cursor = "pointer"
104
+ marginLeft = "12px"
105
+ sx = { {
106
+ svg : {
107
+ position : 'absolute' ,
108
+ top : '16px' ,
109
+ right : '12px' ,
110
+ } ,
111
+ } }
112
+ onClick = { onClick }
113
+ >
114
+ < Close />
115
+ </ Box >
116
+ ) }
94
117
</ Box >
95
118
)
96
119
}
0 commit comments