1- import { Box , HStack } from '@chakra-ui/react'
1+ import { Box , HStack , useMediaQuery } from '@chakra-ui/react'
22
33import { BtnLink , BtnPrimary } from '@/molecules'
44import { vars } from '@/theme'
@@ -27,21 +27,44 @@ export function Alert({
2727 buttonText,
2828 buttonIcon,
2929 buttonLink = false ,
30+ isFlash = false ,
3031 onClick,
3132 state,
3233 m,
3334} : 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+
3448 return (
3549 < Box
50+ className = { isFlash ? 'flashNotification' : 'embeddedAlert' }
51+ alignItems = { ! isMobile ? 'center' : 'unset' }
3652 backgroundColor = { alertStates [ state ] . bg }
3753 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' : '' }
4158 margin = { m }
59+ width = "100%"
60+ maxWidth = "796px"
61+ p = "1rem"
62+ pr = { canDismiss ? '1.75rem' : '1rem' }
4263 position = "relative"
4364 >
4465 < HStack
66+ gap = "10px"
67+ className = "alertContent"
4568 sx = { {
4669 '.linkButton' : {
4770 fontSize : '16px' ,
@@ -50,7 +73,6 @@ export function Alert({
5073 >
5174 < Box
5275 className = "iconContainer"
53- marginRight = "10px"
5476 sx = { {
5577 svg : {
5678 width : 'auto' ,
@@ -67,30 +89,31 @@ export function Alert({
6789 color = { vars ( 'colors-neutral-darkCharcoal' ) }
6890 >
6991 { children }
70- { buttonText && onClick && buttonLink && < BtnLink onClick = { onClick } > { buttonText } </ BtnLink > }
92+ { buttonType === 'link' && < BtnLink onClick = { handleClick } > { buttonText } </ BtnLink > }
7193 </ 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- ) }
9394 </ 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+ ) }
94117 </ Box >
95118 )
96119}
0 commit comments