@@ -3,40 +3,46 @@ import { Body } from '../Body';
3
3
import { HStack } from '../HStack' ;
4
4
import { Paper } from '../Paper' ;
5
5
import { Pressable } from '../Pressable' ;
6
+ import { useToastAction } from '../ToastProvider' ;
6
7
import { VStack } from '../VStack' ;
7
8
import { withToastVariation } from './ToastProps' ;
8
9
9
10
export const Toast = withToastVariation (
10
- ( { innerRef, IconComponent, color, title, buttonText, onButtonClick, testId = 'toast' , ...restProps } ) => (
11
- < HStack ref = { innerRef } { ...restProps } px = { 20 } width = "100%" alignHorizontal = "center" data-testid = { testId } >
12
- < Paper
13
- elevationLevel = { 1 }
14
- rounded = "sm"
15
- backgroundColor = "inverseSurface"
16
- maxWidth = { 816 }
17
- pointerEvents = "auto"
18
- width = { [ '100%' , 'auto' ] }
19
- >
20
- < HStack px = { 16 } py = { 12 } alignVertical = "center" width = { [ '100%' , 'auto' ] } >
21
- { IconComponent && (
22
- < VStack mr = { 8 } flexShrink = { 0 } >
23
- < IconComponent size = { 18 } fill = { color } />
24
- </ VStack >
25
- ) }
26
- < Body level = { 2 } wordBreak = "keep-all" color = "onInverseSurface" >
27
- { title }
28
- </ Body >
29
- { isDefined ( buttonText ) && onButtonClick && (
30
- < VStack flexShrink = { 0 } ml = "auto" >
31
- < Pressable interactions = { [ 'focus' , 'active' ] } ml = { 12 } onClick = { onButtonClick } >
32
- < Body level = { 2 } color = "onViewInformative" weight = "medium" >
33
- { buttonText }
34
- </ Body >
35
- </ Pressable >
36
- </ VStack >
37
- ) }
38
- </ HStack >
39
- </ Paper >
40
- </ HStack >
41
- )
11
+ ( { innerRef, IconComponent, color, title, buttonText, onButtonClick, testId = 'toast' , ...restProps } ) => {
12
+ const { closeToast } = useToastAction ( ) ;
13
+ const onCloseButtonClick = ( ) => onButtonClick ?.( { close : closeToast } ) ;
14
+
15
+ return (
16
+ < HStack ref = { innerRef } { ...restProps } px = { 20 } width = "100%" alignHorizontal = "center" data-testid = { testId } >
17
+ < Paper
18
+ elevationLevel = { 1 }
19
+ rounded = "sm"
20
+ backgroundColor = "inverseSurface"
21
+ maxWidth = { 816 }
22
+ pointerEvents = "auto"
23
+ width = { [ '100%' , 'auto' ] }
24
+ >
25
+ < HStack px = { 16 } py = { 12 } alignVertical = "center" width = { [ '100%' , 'auto' ] } >
26
+ { IconComponent && (
27
+ < VStack mr = { 8 } flexShrink = { 0 } >
28
+ < IconComponent size = { 18 } fill = { color } />
29
+ </ VStack >
30
+ ) }
31
+ < Body level = { 2 } wordBreak = "keep-all" color = "onInverseSurface" >
32
+ { title }
33
+ </ Body >
34
+ { isDefined ( buttonText ) && onButtonClick && (
35
+ < VStack flexShrink = { 0 } ml = "auto" >
36
+ < Pressable interactions = { [ 'focus' , 'active' ] } ml = { 12 } onClick = { onCloseButtonClick } >
37
+ < Body level = { 2 } color = "onViewInformative" weight = "medium" >
38
+ { buttonText }
39
+ </ Body >
40
+ </ Pressable >
41
+ </ VStack >
42
+ ) }
43
+ </ HStack >
44
+ </ Paper >
45
+ </ HStack >
46
+ ) ;
47
+ }
42
48
) ;
1 commit comments
vercel[bot] commentedon Oct 30, 2023
@neroli-101 is attempting to deploy a commit to the Class101 Team on Vercel.
To accomplish this, @neroli-101 needs to request access to the Team.
Afterwards, an owner of the Team is required to accept their membership request.
If you're already a member of the respective Vercel Team, make sure that your Personal Vercel Account is connected to your GitHub account.