1
1
import React from "react" ;
2
2
import { Meta } from "@storybook/react" ;
3
- import { toast } from "@nextui-org/theme" ;
3
+ import { cn , toast } from "@nextui-org/theme" ;
4
4
import { Button } from "@nextui-org/button" ;
5
5
6
6
import { Toast , ToastProps , ToastProvider , addToast } from "../src" ;
@@ -43,7 +43,7 @@ const Template = (args: ToastProps) => (
43
43
< Button
44
44
onPress = { ( ) => {
45
45
addToast ( {
46
- title : "Title" ,
46
+ title : "Toast Title" ,
47
47
description : "Toast description" ,
48
48
...args ,
49
49
} ) ;
@@ -54,17 +54,153 @@ const Template = (args: ToastProps) => (
54
54
</ >
55
55
) ;
56
56
57
+ const TimeoutTemplate = ( args : ToastProps ) => {
58
+ return (
59
+ < >
60
+ < ToastProvider />
61
+ < Button
62
+ onPress = { ( ) => {
63
+ addToast ( {
64
+ title : "Toast Title" ,
65
+ description : "Toast Description" ,
66
+ timeout : 3000 ,
67
+ ...args ,
68
+ } ) ;
69
+ } }
70
+ >
71
+ Toast
72
+ </ Button >
73
+ </ >
74
+ ) ;
75
+ } ;
76
+
77
+ const WithEndContentTemplate = ( args ) => {
78
+ return (
79
+ < >
80
+ < ToastProvider />
81
+ < Button
82
+ onPress = { ( ) => {
83
+ addToast ( {
84
+ title : "Toast Title" ,
85
+ description : "Toast Description" ,
86
+ endContent : (
87
+ < Button color = "warning" size = "sm" variant = "flat" >
88
+ Upgrade
89
+ </ Button >
90
+ ) ,
91
+ color : "warning" ,
92
+ variant : "faded" ,
93
+ ...args ,
94
+ } ) ;
95
+ } }
96
+ >
97
+ Toast
98
+ </ Button >
99
+ </ >
100
+ ) ;
101
+ } ;
102
+
103
+ const CustomToastComponent = ( args ) => {
104
+ const color = args . color ;
105
+ const colorMap = {
106
+ primary : "before:bg-primary border-primary-200 dark:border-primary-100" ,
107
+ secondary : "before:bg-secondary border-secondary-200 dark:border-secondary-100" ,
108
+ success : "before:bg-success border-success-200 dark:border-success-100" ,
109
+ warning : "before:bg-warning border-warning-200 dark:border-warning-100" ,
110
+ danger : "before:bg-danger border-danger-200 dark:border-danger-100" ,
111
+ } ;
112
+
113
+ return (
114
+ < >
115
+ < Button
116
+ color = { color }
117
+ variant = "bordered"
118
+ onPress = { ( ) => {
119
+ addToast ( {
120
+ title : "Toast Title" ,
121
+ description : "Toast Description" ,
122
+ classNames : {
123
+ base : cn ( [
124
+ "bg-default-50 dark:bg-background shadow-sm" ,
125
+ "border-1" ,
126
+ "relative before:content-[''] before:absolute before:z-10" ,
127
+ "before:left-0 before:top-[-1px] before:bottom-[-1px] before:w-1" ,
128
+ "rounded-l-none border-l-0" ,
129
+ colorMap [ color ] ,
130
+ ] ) ,
131
+ } ,
132
+ color : color ,
133
+ } ) ;
134
+ } }
135
+ >
136
+ Toast
137
+ </ Button >
138
+ </ >
139
+ ) ;
140
+ } ;
141
+
142
+ const CustomToastTemplate = ( ) => {
143
+ const colors = [ "primary" , "secondary" , "warning" , "danger" , "success" ] ;
144
+
145
+ return (
146
+ < >
147
+ < ToastProvider />
148
+ < div className = "flex gap-2" >
149
+ { colors . map ( ( color , idx ) => (
150
+ < CustomToastComponent key = { idx } color = { color } />
151
+ ) ) }
152
+ </ div >
153
+ </ >
154
+ ) ;
155
+ } ;
156
+
57
157
export const Default = {
58
158
render : Template ,
59
159
args : {
60
160
...defaultProps ,
61
161
} ,
62
162
} ;
63
163
64
- export const WithTimeout = {
164
+ export const WithIcon = {
65
165
render : Template ,
66
166
args : {
67
167
...defaultProps ,
68
- timeout : 3000 ,
168
+ title : "Custom Icon" ,
169
+ icon : (
170
+ < svg height = { 24 } viewBox = "0 0 24 24" width = { 24 } >
171
+ < g
172
+ fill = "none"
173
+ stroke = "currentColor"
174
+ strokeLinecap = "round"
175
+ strokeLinejoin = "round"
176
+ strokeMiterlimit = { 10 }
177
+ strokeWidth = { 1.5 }
178
+ >
179
+ < path
180
+ d = "M11.845 21.662C8.153 21.662 5 21.088 5 18.787s3.133-4.425 6.845-4.425c3.692 0 6.845 2.1 6.845 4.4s-3.134 2.9-6.845 2.9z"
181
+ data-name = "Stroke 1"
182
+ />
183
+ < path d = "M11.837 11.174a4.372 4.372 0 10-.031 0z" data-name = "Stroke 3" />
184
+ </ g >
185
+ </ svg >
186
+ ) ,
187
+ } ,
188
+ } ;
189
+
190
+ export const WithTimeout = {
191
+ render : TimeoutTemplate ,
192
+ args : {
193
+ ...defaultProps ,
194
+ } ,
195
+ } ;
196
+
197
+ export const WithEndContent = {
198
+ render : WithEndContentTemplate ,
199
+ args : {
200
+ ...defaultProps ,
69
201
} ,
70
202
} ;
203
+
204
+ export const CustomTemplate = {
205
+ render : CustomToastTemplate ,
206
+ } ;
0 commit comments