1- import { Text , VStack , HStack , Box , Icon } from '@chakra-ui/react' ;
1+ import { Text , VStack , HStack , Box , Icon , IconButton } from '@chakra-ui/react' ;
22import { BiSolidInfoCircle } from 'react-icons/bi' ;
3- import React from 'react' ;
3+ import { IoClose } from 'react-icons/io5' ;
4+ import React , { useState } from 'react' ;
45
56interface NotifyProps {
67 children ?: React . ReactNode ;
@@ -11,12 +12,21 @@ interface NotifyProps {
1112export const Notify = ( {
1213 children,
1314 title = "Heads Up!" ,
14- notificationType = "info"
15+ notificationType = "info" ,
1516} : NotifyProps ) => {
17+ const [ isVisible , setIsVisible ] = useState ( true ) ;
1618 const bgColor = 'white'
1719 const borderColor = notificationType === 'info' ? 'minusxGreen.800' : notificationType === 'warning' ? 'orange.500' : 'red.600'
1820 const iconColor = notificationType === 'info' ? 'minusxGreen.800' : notificationType === 'warning' ? 'orange.500' : 'red.600' ;
1921
22+ const handleDismiss = ( ) => {
23+ setIsVisible ( false ) ;
24+ } ;
25+
26+ if ( ! isVisible ) {
27+ return null ;
28+ }
29+
2030 return (
2131 < Box
2232 bg = { bgColor }
@@ -28,22 +38,35 @@ export const Notify = ({
2838 w = "full"
2939 >
3040 < VStack align = "flex-start" spacing = { 2 } w = "full" >
31- < HStack spacing = { 2 } align = "center" >
32- {
33- notificationType === 'warning' ?
34- < Icon as = { BiSolidInfoCircle } size = { 16 } color = { "orange.500" } /> :
35- notificationType === 'error' ?
36- < Icon as = { BiSolidInfoCircle } size = { 16 } color = { "red.600" } /> :
37- < Icon as = { BiSolidInfoCircle } size = { 16 } color = { "minusxGreen.800" } />
38- }
39- < Text
40- fontSize = "sm"
41- fontWeight = "semibold"
42- m = { 0 }
43- color = { iconColor }
44- >
45- { title }
46- </ Text >
41+ < HStack spacing = { 2 } align = "center" justify = "space-between" w = "full" >
42+ < HStack spacing = { 2 } align = "center" >
43+ {
44+ notificationType === 'warning' ?
45+ < Icon as = { BiSolidInfoCircle } size = { 16 } color = { "orange.500" } /> :
46+ notificationType === 'error' ?
47+ < Icon as = { BiSolidInfoCircle } size = { 16 } color = { "red.600" } /> :
48+ < Icon as = { BiSolidInfoCircle } size = { 16 } color = { "minusxGreen.800" } />
49+ }
50+ < Text
51+ fontSize = "sm"
52+ fontWeight = "semibold"
53+ m = { 0 }
54+ color = { iconColor }
55+ >
56+ { title }
57+ </ Text >
58+ </ HStack >
59+ { notificationType != 'error' && (
60+ < IconButton
61+ aria-label = "Dismiss notification"
62+ icon = { < IoClose /> }
63+ size = "sm"
64+ variant = "ghost"
65+ color = "gray.500"
66+ onClick = { handleDismiss }
67+ _hover = { { bg : notificationType === 'info' ? 'minusxGreen.800' : notificationType === 'warning' ? 'orange.500' : 'red.600' , color : 'white' } }
68+ />
69+ ) }
4770 </ HStack >
4871 { children && (
4972 < Text
0 commit comments