Skip to content

Commit ecfe1b7

Browse files
fix(alerts): corrección ancho y botón (#554)
1 parent beb3eb0 commit ecfe1b7

File tree

3 files changed

+56
-29
lines changed

3 files changed

+56
-29
lines changed

src/organisms/Alerts/Alert.tsx

Lines changed: 50 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Box, HStack } from '@chakra-ui/react'
1+
import { Box, HStack, useMediaQuery } from '@chakra-ui/react'
22

33
import { BtnLink, BtnPrimary } from '@/molecules'
44
import { 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
}

src/organisms/Alerts/FlashNotification.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export function FlashNotification({
3030
const showToast = useCallback(() => {
3131
toast(
3232
(t) => (
33-
<Alert state={state} canDismiss onClick={() => toast.dismiss(t.id)}>
33+
<Alert isFlash state={state} canDismiss onClick={() => toast.dismiss(t.id)}>
3434
{message}
3535
</Alert>
3636
),

src/organisms/Alerts/types.d.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,14 @@ export interface IAlertProps {
2020
* Boolean que determina si el botón es tipo link
2121
*/
2222
buttonLink?: boolean
23+
/**
24+
* Para notificación flash
25+
*/
26+
isFlash?: boolean
2327
/**
2428
* Función del botón
2529
*/
26-
onClick?: (e: React.MouseEvent<HTMLElement>) => void
30+
onClick?: () => void
2731
/**
2832
* Estado que define color e ícono de la alerta
2933
* @exampe

0 commit comments

Comments
 (0)