File tree 5 files changed +41
-26
lines changed
5 files changed +41
-26
lines changed Original file line number Diff line number Diff line change @@ -102,8 +102,8 @@ const Toast = (props: ToastComponentProps) => {
102
102
</ div >
103
103
< div className = "t_actions" >
104
104
{ props . action && (
105
- < button onClick = { props . action } title = "Action button" >
106
- Action
105
+ < button onClick = { props . action . onClick } title = "Action button" >
106
+ { props . action . text ?? ' Action' }
107
107
</ button >
108
108
) }
109
109
< button onClick = { props . onClose } title = "Close toast" >
Original file line number Diff line number Diff line change 51
51
list-style : none;
52
52
outline : none;
53
53
background-color : var (--background-color );
54
- width : 100 % ;
54
+ width : auto ;
55
55
box-shadow :
56
56
0 1px 3px 0 var (--box-shadow ),
57
57
0 1px 2px -1px var (--box-shadow );
58
58
border : 1px solid var (--border-color );
59
- max-width : 20rem ;
60
59
border-radius : 0.375rem ;
61
60
font-size : 0.875rem ;
62
61
line-height : 1.25rem ;
70
69
.t_container {
71
70
display : flex;
72
71
width : 100% ;
72
+ max-width : 20rem ;
73
73
height : 100wh ;
74
74
gap : 0.5rem ;
75
75
padding : 12px ;
76
+ word-wrap : break-word;
77
+ overflow-wrap : break-word;
76
78
}
77
79
78
80
.t_icon {
82
84
.t_content {
83
85
display : flex;
84
86
flex-direction : column;
87
+ justify-content : center;
88
+ max-width : 100% ;
85
89
}
86
90
87
91
.t_content p {
Original file line number Diff line number Diff line change @@ -10,6 +10,11 @@ export type Position =
10
10
| 'bottom-center' ;
11
11
export type Theme = 'light' | 'dark' | 'system' ;
12
12
13
+ export interface Action {
14
+ text ?: string ;
15
+ onClick : ( ) => void | ( ( ) => Promise < void > ) ;
16
+ }
17
+
13
18
export type ToastProps = {
14
19
id ?: number ;
15
20
text : string ;
@@ -18,7 +23,7 @@ export type ToastProps = {
18
23
iconSize ?: number ;
19
24
delayDuration ?: number ;
20
25
theme ?: Theme ;
21
- action ?: ( ) => void | ( ( ) => Promise < void > ) ;
26
+ action ?: Action ;
22
27
} ;
23
28
24
29
export type ToastProviderProperties = {
Original file line number Diff line number Diff line change @@ -92,23 +92,27 @@ const UseToastActionsExamples = () => {
92
92
93
93
const handleChangeVariant = ( ) => {
94
94
t . default ( {
95
- text : `A toast with 👀 action button` ,
96
- description : 'Click the action button to see the confetti 🥹' ,
97
- action : ( ) => {
98
- if ( typeof window !== 'undefined' ) {
99
- const confetti = new JSConfetti ( ) ;
100
- confetti . addConfetti ( {
101
- confettiRadius : 3 ,
102
- confettiNumber : 100 ,
103
- confettiColors : [
104
- '#14532d' ,
105
- '#ff477e' ,
106
- '#f7f7f7' ,
107
- '#ffcc00' ,
108
- '#ffcc00' ,
109
- ] ,
110
- } ) ;
111
- }
95
+ text : `A toast with confetti 🎉` ,
96
+ description : 'Click the button to see the confetti' ,
97
+ delayDuration : 400000 ,
98
+ icon : < PartyPopperIcon size = { 24 } /> ,
99
+ action : {
100
+ onClick : ( ) => {
101
+ if ( typeof window !== 'undefined' ) {
102
+ const confetti = new JSConfetti ( ) ;
103
+ confetti . addConfetti ( {
104
+ confettiRadius : 3 ,
105
+ confettiNumber : 100 ,
106
+ confettiColors : [
107
+ '#14532d' ,
108
+ '#ff477e' ,
109
+ '#f7f7f7' ,
110
+ '#ffcc00' ,
111
+ '#ffcc00' ,
112
+ ] ,
113
+ } ) ;
114
+ }
115
+ } ,
112
116
} ,
113
117
} ) ;
114
118
} ;
Original file line number Diff line number Diff line change @@ -39,9 +39,11 @@ export default function Index() {
39
39
``` tsx
40
40
t .default ({
41
41
text: ` A toast with 👀 action button ` ,
42
- action : () => {
43
- // Do something
44
- }
42
+ action: {
43
+ label: ' Action' , // Button label
44
+ onClick : () => {
45
+ // Do something
46
+ },
45
47
},
46
48
});
47
49
```
@@ -56,6 +58,6 @@ The `toast.variant` function accepts the following options:
56
58
| ` description ` | Toast's description | ` string ` | - |
57
59
| ` icon ` | Icon to display in the toast | ` ReactNode ` | - |
58
60
| ` iconSize ` | Size of the icon | ` number ` | - |
59
- | ` delayDuration ` | Duration before the toast disappears | ` number ` | - |
61
+ | ` delayDuration ` | Duration before the toast disappears | ` number ` (default: ` 4000 ` ) | - |
60
62
| ` theme ` | Theme of the toast | ` Theme ` (` light ` / ` dark ` / ` system ` ) | - |
61
63
| ` action ` | Show a _ Action_ button and execute a function | ` () => void \| () => Promise<void> ` | - |
You can’t perform that action at this time.
0 commit comments