2023-05-18 21:17:17 +00:00
package main
import (
2023-05-19 21:45:39 +00:00
"time"
2023-05-18 21:17:17 +00:00
"git.d3nexus.de/Dadido3/D3vugu-components/components/input"
"git.d3nexus.de/Dadido3/D3vugu-components/components/overlay"
"git.d3nexus.de/Dadido3/D3vugu-components/icons"
"github.com/vugu/vugu"
)
type PageOverlays struct {
overlay . OverlayContainerRef
}
2023-05-19 21:45:39 +00:00
func ( c * PageOverlays ) handleSimpleModalButton ( event vugu . DOMEvent ) {
2023-05-18 21:17:17 +00:00
c . SetModal ( & overlay . ModalRequester {
2023-05-25 13:59:13 +00:00
IconSlot : & icons . LInfoCircle { AttrMap : vugu . AttrMap { "style" : "font-size: 2em;" } } ,
2023-05-19 21:45:39 +00:00
Title : "Simple requester" ,
Message : "This is a simple modal requester, are you happy with it?\nIt also supports multi line text!" ,
2023-05-25 13:59:13 +00:00
SignalColor : "d3c-color-attention" ,
2023-05-19 21:45:39 +00:00
ClickAbort : input . ClickFunc ( func ( event input . ClickEvent ) { } ) ,
ClickYes : input . ClickFunc ( func ( event input . ClickEvent ) { } ) ,
} )
}
func ( c * PageOverlays ) handleSimpleToastButton ( event vugu . DOMEvent ) {
2023-05-29 11:39:39 +00:00
c . AddToast ( event . EventEnv ( ) , & overlay . ToastSimple {
2023-05-25 13:59:13 +00:00
IconSlot : & icons . LInfoCircle { AttrMap : vugu . AttrMap { "style" : "font-size: 2em;" } } ,
2023-05-19 21:45:39 +00:00
Message : "This is a simple toast!\nIt supports multiple lines and has an icon slot.\nThere also can be multiple of it at the same time, this one was opened at " + time . Now ( ) . Format ( time . TimeOnly ) + "." ,
2023-05-25 13:59:13 +00:00
SignalColor : "d3c-color-attention" ,
2023-05-19 21:45:39 +00:00
} )
}
func ( c * PageOverlays ) handleWarningToastButton ( event vugu . DOMEvent ) {
2023-05-29 11:39:39 +00:00
c . AddToast ( event . EventEnv ( ) , & overlay . ToastSimple {
2023-05-25 13:59:13 +00:00
IconSlot : & icons . LWarning { AttrMap : vugu . AttrMap { "style" : "font-size: 2em;" , "class" : "d3c-color-caution d3c-icon-use-color" } } ,
2023-05-19 21:45:39 +00:00
Message : "This is a warning, be careful!" ,
SignalColor : "d3c-color-caution" ,
2023-05-18 21:17:17 +00:00
} )
}
2023-05-28 11:39:43 +00:00
func ( c * PageOverlays ) handleToastMessageButton ( event vugu . DOMEvent ) {
2023-05-29 11:39:39 +00:00
c . AddToast ( event . EventEnv ( ) , & overlay . ToastMessage { MessageType : overlay . ToastMessageTypeCritical , Message : "Uh oh!" } )
2023-05-28 13:04:18 +00:00
}
func ( c * PageOverlays ) handleToastMessageTimeoutButton ( event vugu . DOMEvent ) {
2023-05-29 11:39:39 +00:00
c . AddToast ( event . EventEnv ( ) , & overlay . ToastMessage { MessageType : overlay . ToastMessageTypeSuccess , Message : "That worked!" , Duration : 5 * time . Second } )
2023-05-28 11:39:43 +00:00
}
2023-05-28 14:47:10 +00:00
func ( c * PageOverlays ) handleWaitOverlayButton ( event vugu . DOMEvent ) {
c . WaitOverlayOpen ( )
go func ( ) {
// Simulate some request or some other action.
time . Sleep ( 5 * time . Second )
// We need to lock and unlock the event environment in order for the DOM to re-render and the overlay to disappear correctly.
event . EventEnv ( ) . Lock ( )
defer event . EventEnv ( ) . UnlockRender ( )
defer c . WaitOverlayDone ( ) // WaitOverlayDone has to be called before UnlockRender, so we need to put it afterwards (defer ordering).
// Update other UI stuff here.
} ( )
}