@@ -80,47 +80,83 @@ import "github.com/indaco/goaster"
8080
8181### Creating a Toaster
8282
83- Initialize a ` Toaster ` with default settings:
83+ You can create a ` Toaster ` instance using one of the following approaches:
84+
85+ #### 1. Use default settings
8486
8587``` go
86- toaster := goaster.NewToaster ()
88+ func HandleSingle (w http .ResponseWriter , r *http .Request ) {
89+ toaster := goaster.ToasterDefaults ()
90+ templ.Handler (pages.HomePage (toaster)).ServeHTTP (w, r)
91+ }
8792```
8893
89- or customize the toaster with options:
94+ #### 2. Use functional options
95+
96+ Customize the toaster behavior on creation:
9097
9198``` go
92- toaster := goaster.NewToaster (
93- goaster.WithBorder (false ),
94- goaster.WithPosition (goaster.TopRight ),
95- goaster.WithAutoDismiss (false )
96- // ...
97- )
99+ func HandleSingle (w http .ResponseWriter , r *http .Request ) {
100+ toaster := goaster.NewToaster (
101+ goaster.WithBorder (false ),
102+ goaster.WithPosition (goaster.TopRight ),
103+ goaster.WithAutoDismiss (false ),
104+ // ...
105+ )
106+ templ.Handler (pages.HomePage (toaster)).ServeHTTP (w, r)
107+ }
98108```
99109
100- ### Displaying Toast Messages
110+ #### 3. Use the builder pattern
101111
102- Display different levels of toast messages :
112+ More readable when chaining multiple settings :
103113
104114``` go
105- toaster.Default (" Sample message." )
106- toaster.Success (" Operation completed successfully." )
107- toaster.Error (" An error occurred." )
108- toaster.Info (" Here's some information." )
109- toaster.Warning (" This is a warning message." )
115+ func HandleSingle (w http .ResponseWriter , r *http .Request ) {
116+ toaster := goaster.NewToasterBuilder ().WithAutoDismiss (false ).Build ()
117+ templ.Handler (pages.HomePage (toaster)).ServeHTTP (w, r)
118+ }
119+ ```
120+
121+ ### Displaying Toast Messages
122+
123+ In your _ templ_ pages, call the appropriate method on the ` Toaster ` instance:
124+
125+ ``` templ
126+ templ UserPage(toaster *goaster.Toaster) {
127+ @toaster.Success("Operation completed successfully.")
128+ }
129+ ```
130+
131+ Each toast level has a corresponding method:
132+
133+ ``` templ
134+ @toaster.Default("Sample message.")
135+ @toaster.Error("An error occurred.")
136+ @toaster.Info("Here's some information.")
137+ @toaster.Warning("This is a warning message.")
110138```
111139
112- ### Add Toast Messages to the queue and display them
140+ > 💡 Toast messages are displayed when ` @toaster.<Level>() ` is called in your template.
141+
142+ #### Queueing Toast Messages from Go
113143
114- Multiple toast messages in the queue :
144+ You can queue multiple toast messages in your ** handler ** :
115145
116146``` go
117147toaster.PushDefault (" Sample message." )
118148toaster.PushSuccess (" Operation completed successfully." )
119149toaster.PushError (" An error occurred." )
120150toaster.PushInfo (" Here's some information." )
121151toaster.PushWarning (" This is a warning message." )
152+ ```
153+
154+ Then render them all in your _ templ_ page:
122155
123- toaster.RenderAll ()
156+ ``` templ
157+ templ UserPage(toaster *goaster.Toaster) {
158+ @toaster.RenderAll()
159+ }
124160```
125161
126162## Custom Icons
0 commit comments